Skip to content

Commit

Permalink
Merge pull request #6045 from ericmehl/numericWidgetMouseWheel
Browse files Browse the repository at this point in the history
NumericWidget : Mouse wheel adjust value
  • Loading branch information
murraystevenson authored Sep 23, 2024
2 parents 17e0b00 + a6e6cbf commit 4d698f1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
1.4.x.x (relative to 1.4.13.0)
=======

Improvements
------------

- NumericWidget : Added the ability to use <kbd>Ctrl</kbd> + scroll wheel to adjust values in the same manner as <kbd>Up</kbd> and <kbd>Down</kbd> (#6009).

1.4.13.0 (relative to 1.4.12.0)
========
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/NumericPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def getToolTip( self ) :
if result :
result += "\n"
result += "## Actions\n"
result += " - Cursor up/down to increment/decrement\n"
result += " - Cursor up/down or <kbd>Ctrl</kbd> + scroll wheel to increment/decrement\n"
result += " - Use `+`, `-`, `*`, `/` and `%` to perform simple maths\n"

return result
Expand Down
19 changes: 19 additions & 0 deletions python/GafferUI/NumericWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__( self, value, **kw ) :
self.__dragStart = None

self.keyPressSignal().connect( Gaffer.WeakMethod( self.__keyPress ), scoped = False )
self.wheelSignal().connect( Gaffer.WeakMethod( self.__wheel ), scoped = False )
self.buttonPressSignal().connect( Gaffer.WeakMethod( self.__buttonPress ), scoped = False )
self.dragBeginSignal().connect( Gaffer.WeakMethod( self.__dragBegin ), scoped = False )
self.dragEnterSignal().connect( Gaffer.WeakMethod( self.__dragEnter ), scoped = False )
Expand All @@ -72,6 +73,8 @@ def __init__( self, value, **kw ) :
self.__numericType = None
self.setValue( value )

self.__scrollWheelRotation = 0

def setValue( self, value ) :

self.__setValueInternal( value, self.ValueChangedReason.SetValue )
Expand Down Expand Up @@ -141,6 +144,20 @@ def __keyPress( self, widget, event ) :

return False

def __wheel( self, widget, event ) :

assert( widget is self )

if not self.getEditable() or not self._qtWidget().hasFocus() or event.modifiers != GafferUI.ModifiableEvent.Modifiers.Control :
return False

self.__scrollWheelRotation += event.wheelRotation
if abs( self.__scrollWheelRotation ) >= 15.0 :
self.__incrementIndex( self.getCursorPosition(), int( math.copysign( 1, self.__scrollWheelRotation ) ) )
self.__scrollWheelRotation %= 15.0

return True

def __incrementIndex( self, index, increment ) :

text = self.getText()
Expand Down Expand Up @@ -276,6 +293,8 @@ def __editingFinished( self, widget ) :

self.__emitValueChanged( reason )

self.__scrollWheelRotation = 0.0

def __setValueInternal( self, value, reason ) :

# update our validator based on the type of the value
Expand Down
6 changes: 5 additions & 1 deletion python/GafferUI/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,11 @@ def __wheel( self, qObject, qEvent ) :
Widget._modifiers( qEvent.modifiers() ),
)

return widget._wheelSignal( widget, event )
result = widget._wheelSignal( widget, event )
if result :
qEvent.accept()

return result

return False

Expand Down

0 comments on commit 4d698f1

Please sign in to comment.