diff options
author | Treeki <treeki@gmail.com> | 2012-07-25 19:00:10 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-07-25 19:00:10 +0200 |
commit | dcd8c9c20aa883d056862d0ba7c53fd7b06edc49 (patch) | |
tree | 03685c3a72348f68e5e43129caf03b9b3a9b9caf /src/editorui/paths.py | |
parent | 0e63ef0b2e2f062e5214f841239c3a483d45562a (diff) | |
parent | e0aebec63011cbcb676caa92948e25c62fd6c17b (diff) | |
download | koopatlas-dcd8c9c20aa883d056862d0ba7c53fd7b06edc49.tar.gz koopatlas-dcd8c9c20aa883d056862d0ba7c53fd7b06edc49.zip |
merging the new unlock system into master
Diffstat (limited to '')
-rw-r--r-- | src/editorui/paths.py | 117 |
1 files changed, 20 insertions, 97 deletions
diff --git a/src/editorui/paths.py b/src/editorui/paths.py index 4110188..43a1465 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -538,93 +538,6 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.setPalette(palette) - class UnlockButton(QtGui.QPushButton): - def __init__(self, pathRef): - QtGui.QPushButton.__init__(self) - - self.setFixedSize(48,48) - - self.iconList = [QtGui.QIcon("Resources/Key.png"), - QtGui.QIcon("Resources/SecretKey.png")] - - self.unlockIcon = QtGui.QIcon("Resources/Unlock.png") - self.arrowIcon = [QtGui.QIcon("Resources/KeyArrow.png"), - QtGui.QIcon("Resources/SecretKeyArrow.png")] - - - self._pathRef = pathRef - - self.secret = 0 - self.path = 0 - - if not hasattr(KPEditorPath.UnlockButton, 'PALETTE'): - KPEditorPath.UnlockButton.PALETTE = QtGui.QPalette(Qt.transparent) - - self.setPalette(self.PALETTE) - - self.released.connect(self.toggle) - - - def toggle(self): - - path = self._pathRef() - - if KP.app.keyboardModifiers() == Qt.ShiftModifier: - if self.secret == 1: - self.secret = 0 - else: - self.secret = 1 - - path.secret = self.secret - - else: - self.path += 1 - - if self.path > 2: - self.path = 0 - - path.unlocks = self.path - - - def paintEvent(self, event): - painter = QtGui.QPainter(self) - contentsRect = self.contentsRect() - smallRect = QtCore.QRect(12, 12, 24, 24) - painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform) - - if self.path > 0: - painter.save() - - displaceX, displaceY = contentsRect.width() / 2, contentsRect.height() / 2 - - pathItem = self._pathRef().qtItem.line() - - if self.path == 1: - angle = 90 - pathItem.angle() - else: - angle = 270 - pathItem.angle() - - painter.translate(displaceX, displaceY) - painter.rotate(angle) - painter.translate(-displaceX, -displaceY) - self.arrowIcon[self.secret].paint(painter, contentsRect, Qt.AlignCenter) - - painter.restore() - - if self.isDown(): - self.iconList[self.secret].paint(painter, smallRect, Qt.AlignCenter, QtGui.QIcon.Disabled) - else: - self.iconList[self.secret].paint(painter, smallRect, Qt.AlignCenter) - - else: - if self.isDown(): - self.unlockIcon.paint(painter, smallRect, Qt.AlignCenter, QtGui.QIcon.Disabled) - else: - self.unlockIcon.paint(painter, smallRect, Qt.AlignCenter) - - painter.end() - - class HiddenProxy(QtGui.QGraphicsProxyWidget): def __init__(self, button, parent, x, y): QtGui.QGraphicsProxyWidget.__init__(self, parent) @@ -663,12 +576,6 @@ class KPEditorPath(QtGui.QGraphicsLineItem): if not hasattr(KPEditorPath, 'SELECTION_PEN'): KPEditorPath.SELECTION_PEN = QtGui.QPen(Qt.blue, 1, Qt.DotLine) - self.unlock = self.UnlockButton(self._pathRef) - self.unlockProxy = self.HiddenProxy(self.unlock, self, -24, -24) - - self.unlock.secret = path.secret - self.unlock.path = path.unlocks - self.options = self.PathOptionsMenuButton(self._pathRef) self.optionsProxy = self.HiddenProxy(self.options, self, -54, +24) @@ -677,6 +584,25 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.updatePosition() + def mousePressEvent(self, event): + if event.button() != Qt.LeftButton: + return + if QtGui.QApplication.keyboardModifiers() != QtCore.Qt.ControlModifier: + return + + # modify the unlock settings + from unlock import KPUnlockSpecDialog + + dlg = KPUnlockSpecDialog('path', 'unlocked') + + if hasattr(self._pathRef(), 'unlockSpec'): + dlg.setSpec(self._pathRef().unlockSpec) + + result = dlg.exec_() + if result == QtGui.QDialog.Accepted: + print "New spec:", dlg.spec + self._pathRef().unlockSpec = dlg.spec + def updatePosition(self): path = self._pathRef() @@ -720,12 +646,9 @@ class KPEditorPath(QtGui.QGraphicsLineItem): painter.setPen(self.SELECTION_PEN) painter.setBrush(QtGui.QColor(0,0,0,0)) painter.drawPath(self.shape()) - - self.unlockProxy.show() self.optionsProxy.show() else: - self.unlockProxy.hide() self.optionsProxy.hide() @@ -753,4 +676,4 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.scene().removeItem(self) -
\ No newline at end of file + |