Merge pull request #393 from radjkarl/gradient

NEW show/hide gradient ticks NEW link gradientEditor to others
This commit is contained in:
Ogi Moore 2020-05-31 21:03:27 -07:00 committed by GitHub
commit a27506209b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -461,7 +461,20 @@ class GradientEditorItem(TickSliderItem):
self.addTick(1, QtGui.QColor(255,0,0), True)
self.setColorMode('rgb')
self.updateGradient()
self.linkedGradients = {}
def showTicks(self, show=True):
for tick in self.ticks.keys():
if show:
tick.show()
orig = getattr(self, '_allowAdd_backup', None)
if orig:
self.allowAdd = orig
else:
self._allowAdd_backup = self.allowAdd
self.allowAdd = False #block tick creation
tick.hide()
def setOrientation(self, orientation):
## public
"""
@ -764,7 +777,9 @@ class GradientEditorItem(TickSliderItem):
for t in self.ticks:
c = t.color
ticks.append((self.ticks[t], (c.red(), c.green(), c.blue(), c.alpha())))
state = {'mode': self.colorMode, 'ticks': ticks}
state = {'mode': self.colorMode,
'ticks': ticks,
'ticksVisible': next(iter(self.ticks)).isVisible()}
return state
def restoreState(self, state):
@ -789,6 +804,8 @@ class GradientEditorItem(TickSliderItem):
for t in state['ticks']:
c = QtGui.QColor(*t[1])
self.addTick(t[0], c, finish=False)
self.showTicks( state.get('ticksVisible',
next(iter(self.ticks)).isVisible()) )
self.updateGradient()
self.sigGradientChangeFinished.emit(self)
@ -804,6 +821,18 @@ class GradientEditorItem(TickSliderItem):
self.updateGradient()
self.sigGradientChangeFinished.emit(self)
def linkGradient(self, slaveGradient, connect=True):
if connect:
fn = lambda g, slave=slaveGradient:slave.restoreState(
g.saveState())
self.linkedGradients[id(slaveGradient)] = fn
self.sigGradientChanged.connect(fn)
self.sigGradientChanged.emit(self)
else:
fn = self.linkedGradients.get(id(slaveGradient), None)
if fn:
self.sigGradientChanged.disconnect(fn)
class Tick(QtGui.QGraphicsWidget): ## NOTE: Making this a subclass of GraphicsObject instead results in
## activating this bug: https://bugreports.qt-project.org/browse/PYSIDE-86