Skip to content

Commit

Permalink
MultiLineTextWidget : Add "activation hint" overlay
Browse files Browse the repository at this point in the history
This hopefully makes the <kbd>Ctrl</kbd>+<kbd>Return</kbd> much more discoverable. I've deliberately not added methods to enable/disable this functionality as I think it is best applied consistently throughout the entire UI. As soon as you show it in one place and not another, it implies that the shortcut doesn't exist in both.
  • Loading branch information
johnhaddon committed May 23, 2024
1 parent 2fc46bd commit 3989262
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 183 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Improvements
------------

- SetFilter, StandardAttributes, StandardOptions : Added syntax highlighting and auto-complete for set expressions.
- NodeEditor, UIEditor, PythonEditor : Added popup hint for the <kbd>Ctrl</kbd>+<kbd>Return</kbd> shortcut.
- CodeWidget : Added highlighting of braces and operators.

Fixes
Expand Down
23 changes: 22 additions & 1 deletion python/GafferUI/MultiLineTextWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def dropTextSignal( self ) :
def _emitEditingFinished( self ) :

self.editingFinishedSignal()( self )
# Hide our activation hint
self._qtWidget().document().setModified( False )

def __textChanged( self ) :

Expand Down Expand Up @@ -407,9 +409,12 @@ def __drop( self, widget, event ) :
class _PlainTextEdit( QtWidgets.QPlainTextEdit ) :

def __init__( self, parent = None ) :

QtWidgets.QPlainTextEdit.__init__( self, parent )
self.__fixedLineHeight = None

self.document().modificationChanged.connect( self.update )

def setFixedLineHeight( self, fixedLineHeight ) :

self.__fixedLineHeight = fixedLineHeight
Expand Down Expand Up @@ -480,15 +485,31 @@ def paintEvent( self, event ) :

QtWidgets.QPlainTextEdit.paintEvent( self, event )

painter = QtGui.QPainter( self.viewport() )

if self.isEnabled() :
self.__paintActivationHint( painter )
return

# Disabled. We want the text to use faded colours but we can't
# do that with a stylesheet because we may have embedded HTML
# colours and/or a highlighter. So instead we draw a semi-transparent
# overlay the same colour as our background.

painter = QtGui.QPainter( self.viewport() )
color = self.palette().base().color()
color.setAlpha( 128 )
painter.fillRect( 0, 0, self.width(), self.height(), color )

def __paintActivationHint( self, painter ) :

if self.isReadOnly() or not self.document().isModified() :
return

widget = GafferUI.Widget._owner( self )
if widget is None or ( widget.activatedSignal().numSlots() + widget.editingFinishedSignal().numSlots() ) == 0 :
return

viewport = self.viewport()
pixmap = GafferUI.Image._qtPixmapFromFile( "ctrlEnter.png" )
painter.setOpacity( 0.75 )
painter.drawPixmap( viewport.width() - ( pixmap.width() + 4 ), viewport.height() - ( pixmap.height() + 4 ), pixmap )
1 change: 1 addition & 0 deletions resources/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"ids" : [
"colorPlugValueWidgetSlidersOff",
"colorPlugValueWidgetSlidersOn",
"ctrlEnter",
]

},
Expand Down
Loading

0 comments on commit 3989262

Please sign in to comment.