NEW show/hide gradient ticks
NEW link gradientEditorItem to other gradients
This commit is contained in:
parent
4cdc3ac7e5
commit
2d754672a0
@ -450,7 +450,20 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
self.addTick(1, QtGui.QColor(255,0,0), True)
|
self.addTick(1, QtGui.QColor(255,0,0), True)
|
||||||
self.setColorMode('rgb')
|
self.setColorMode('rgb')
|
||||||
self.updateGradient()
|
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):
|
def setOrientation(self, orientation):
|
||||||
## public
|
## public
|
||||||
"""
|
"""
|
||||||
@ -753,7 +766,9 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
for t in self.ticks:
|
for t in self.ticks:
|
||||||
c = t.color
|
c = t.color
|
||||||
ticks.append((self.ticks[t], (c.red(), c.green(), c.blue(), c.alpha())))
|
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
|
return state
|
||||||
|
|
||||||
def restoreState(self, state):
|
def restoreState(self, state):
|
||||||
@ -778,6 +793,8 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
for t in state['ticks']:
|
for t in state['ticks']:
|
||||||
c = QtGui.QColor(*t[1])
|
c = QtGui.QColor(*t[1])
|
||||||
self.addTick(t[0], c, finish=False)
|
self.addTick(t[0], c, finish=False)
|
||||||
|
self.showTicks( state.get('ticksVisible',
|
||||||
|
next(iter(self.ticks)).isVisible()) )
|
||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
self.sigGradientChangeFinished.emit(self)
|
self.sigGradientChangeFinished.emit(self)
|
||||||
|
|
||||||
@ -793,6 +810,18 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
self.sigGradientChangeFinished.emit(self)
|
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
|
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
|
## activating this bug: https://bugreports.qt-project.org/browse/PYSIDE-86
|
||||||
|
Loading…
x
Reference in New Issue
Block a user