Skip to content

Commit

Permalink
Improvements to QDoubleSpinBox value editors
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Dec 12, 2024
1 parent 7e29081 commit 6529dd4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/ui/widgets/nifeditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ NifFloatEdit::NifFloatEdit( NifModel * n, const QModelIndex & index, float min,
getLayout()->addWidget( spinbox = new QDoubleSpinBox() );
spinbox->setRange( min, max );
spinbox->setDecimals( 4 );
spinbox->setStepType( QAbstractSpinBox::AdaptiveDecimalStepType );
spinbox->setAccelerated( true );
spinbox->setKeyboardTracking( false );
// Cast QDoubleSpinBox slot
auto dsbValueChanged = static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);

Expand Down Expand Up @@ -306,8 +309,9 @@ NifVectorEdit::NifVectorEdit( NifModel * n, const QModelIndex & index )
: NifEditBox( n, index )
{
getLayout()->addWidget( vector = new VectorEdit() );
if ( n && n->getBSVersion() >= 170 )
vector->setStepSize( 0.02 );
vector->setStepSize( n && n->getBSVersion() >= 170 ? 0.005 : 0.25 );
vector->setAccelerated( true );
vector->setKeyboardTracking( false );
connect( vector, &VectorEdit::sigEdited, this, &NifVectorEdit::sltApplyData );
}

Expand Down
33 changes: 30 additions & 3 deletions src/ui/widgets/valueedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,37 @@ Vector2 VectorEdit::getVector2() const

void VectorEdit::setStepSize( double n )
{
bool isAdaptive = !( n > 0.0 );
QAbstractSpinBox::StepType stepType = ( isAdaptive ? QAbstractSpinBox::AdaptiveDecimalStepType
: QAbstractSpinBox::DefaultStepType );
x->setStepType( stepType );
y->setStepType( stepType );
z->setStepType( stepType );
w->setStepType( stepType );
if ( isAdaptive )
return;
x->setSingleStep( n );
y->setSingleStep( n );
z->setSingleStep( n );
w->setSingleStep( n );
}

void VectorEdit::setAccelerated( bool n )
{
x->setAccelerated( n );
y->setAccelerated( n );
z->setAccelerated( n );
w->setAccelerated( n );
}

void VectorEdit::setKeyboardTracking( bool n )
{
x->setKeyboardTracking( n );
y->setKeyboardTracking( n );
z->setKeyboardTracking( n );
w->setKeyboardTracking( n );
}


RotationEdit::RotationEdit( QWidget * parent ) : ValueEdit( parent ), mode( mAuto ), setting( false )
{
Expand All @@ -777,6 +802,8 @@ RotationEdit::RotationEdit( QWidget * parent ) : ValueEdit( parent ), mode( mAut
for ( int x = 0; x < 4; x++ ) {
lay->addWidget( l[x] = new CenterLabel, 1 );
lay->addWidget( v[x] = new QDoubleSpinBox, 5 );
v[x]->setAccelerated( true );
v[x]->setKeyboardTracking( false );
connect( v[x], dsbValueChanged, this, &RotationEdit::sltChanged );
}

Expand Down Expand Up @@ -812,7 +839,7 @@ void RotationEdit::setupMode()
l[x]->setText( labs.value( x ) );
v[x]->setDecimals( ROTATION_COARSE );
v[x]->setRange( -360, +360 );
v[x]->setSingleStep( 1 );
v[x]->setSingleStep( 0.2 );
l[x]->setHidden( x == 3 );
v[x]->setHidden( x == 3 );
}
Expand All @@ -829,11 +856,11 @@ void RotationEdit::setupMode()
if ( x == 0 ) {
v[x]->setDecimals( ROTATION_COARSE );
v[x]->setRange( -360, +360 );
v[x]->setSingleStep( 1 );
v[x]->setSingleStep( 0.2 );
} else {
v[x]->setDecimals( ROTATION_FINE );
v[x]->setRange( -1.0, +1.0 );
v[x]->setSingleStep( 0.1 );
v[x]->setSingleStep( 0.02 );
}

l[x]->setHidden( false );
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/valueedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ class VectorEdit final : public ValueEdit
//! Accessor for the Vector2
Vector2 getVector2() const;

//! Set single step to n
//! Set single step to n (n <= 0.0 enables adaptive step mode)
void setStepSize( double n );
void setAccelerated( bool n );
void setKeyboardTracking( bool n );

signals:
//! Signal emitted when the vector is edited
Expand Down

0 comments on commit 6529dd4

Please sign in to comment.