Skip to content

Commit

Permalink
Merge pull request #4669 from nyalldawson/spinbox_ctrl
Browse files Browse the repository at this point in the history
When holding ctrl while mouse wheeling on spin box, increase in smaller amounts
  • Loading branch information
m-kuhn authored Jul 8, 2017
2 parents 8f8cb67 + df9344e commit e2c84f1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/gui/editorwidgets/qgsdoublespinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.

protected:
virtual void changeEvent( QEvent *event );
virtual void wheelEvent( QWheelEvent *event );


};

Expand Down
2 changes: 2 additions & 0 deletions python/gui/editorwidgets/qgsspinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Set the current value to the value defined by the clear value.

virtual void changeEvent( QEvent *event );
virtual void paintEvent( QPaintEvent *event );
virtual void wheelEvent( QWheelEvent *event );


};

Expand Down
22 changes: 22 additions & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ void QgsDoubleSpinBox::changeEvent( QEvent *event )
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
}

void QgsDoubleSpinBox::wheelEvent( QWheelEvent *event )
{
double step = singleStep();
if ( event->modifiers() & Qt::ControlModifier )
{
// ctrl modifier results in finer increments - 10% of usual step
double newStep = step / 10;
// but don't ever use an increment smaller than would be visible in the widget
// i.e. if showing 2 decimals, smallest increment will be 0.01
newStep = qMax( newStep, pow( 10.0, 0.0 - decimals() ) );

setSingleStep( newStep );

// clear control modifier before handing off event - Qt uses it for unwanted purposes
// (*increasing* step size, whereas QGIS UX convention is that control modifier
// results in finer changes!)
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
}
QDoubleSpinBox::wheelEvent( event );
setSingleStep( step );
}

void QgsDoubleSpinBox::paintEvent( QPaintEvent *event )
{
mLineEdit->setShowClearButton( shouldShowClearForValue( value() ) );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox

protected:
virtual void changeEvent( QEvent *event ) override;
void wheelEvent( QWheelEvent *event ) override;

private slots:
void changed( double value );
Expand Down
21 changes: 21 additions & 0 deletions src/gui/editorwidgets/qgsspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ void QgsSpinBox::paintEvent( QPaintEvent *event )
QSpinBox::paintEvent( event );
}

void QgsSpinBox::wheelEvent( QWheelEvent *event )
{
int step = singleStep();
if ( event->modifiers() & Qt::ControlModifier )
{
// ctrl modifier results in finer increments - 10% of usual step
int newStep = step / 10;
// step should be at least 1
newStep = qMax( newStep, 1 );

setSingleStep( newStep );

// clear control modifier before handing off event - Qt uses it for unwanted purposes
// (*increasing* step size, whereas QGIS UX convention is that control modifier
// results in finer changes!)
event->setModifiers( event->modifiers() & ~Qt::ControlModifier );
}
QSpinBox::wheelEvent( event );
setSingleStep( step );
}

void QgsSpinBox::changed( int value )
{
mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox

virtual void changeEvent( QEvent *event ) override;
virtual void paintEvent( QPaintEvent *event ) override;
void wheelEvent( QWheelEvent *event ) override;

private slots:
void changed( int value );
Expand Down

0 comments on commit e2c84f1

Please sign in to comment.