diff --git a/Changes.md b/Changes.md index 42412e2342..be7c324798 100644 --- a/Changes.md +++ b/Changes.md @@ -1,7 +1,10 @@ 1.4.x.x (relative to 1.4.13.0) ======= +Improvements +------------ +- NumericWidget : Added the ability to use Ctrl + scroll wheel to adjust values in the same manner as Up and Down (#6009). 1.4.13.0 (relative to 1.4.12.0) ======== diff --git a/python/GafferUI/NumericPlugValueWidget.py b/python/GafferUI/NumericPlugValueWidget.py index 6226437b8b..7c6a4be4c7 100644 --- a/python/GafferUI/NumericPlugValueWidget.py +++ b/python/GafferUI/NumericPlugValueWidget.py @@ -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 Ctrl + scroll wheel to increment/decrement\n" result += " - Use `+`, `-`, `*`, `/` and `%` to perform simple maths\n" return result diff --git a/python/GafferUI/NumericWidget.py b/python/GafferUI/NumericWidget.py index 2ed1f2811f..5581f2681d 100644 --- a/python/GafferUI/NumericWidget.py +++ b/python/GafferUI/NumericWidget.py @@ -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 ) @@ -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 ) @@ -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() @@ -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 diff --git a/python/GafferUI/Widget.py b/python/GafferUI/Widget.py index 15b3b77e7f..25cf66e2ba 100644 --- a/python/GafferUI/Widget.py +++ b/python/GafferUI/Widget.py @@ -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