summaryrefslogtreecommitdiff
path: root/src/editorui
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-11-22 11:28:42 -0600
committerColin Noga <Tempus@Spectrum-Song.local>2011-11-22 11:28:42 -0600
commit5a70b9a8d357a44fc245a95b76f8ab17aa03bc6e (patch)
tree063209ed989df8bb009388475595c1a91e2e2430 /src/editorui
parent4ddf1fc43e1c25e7b033cdebd0630e26f71ba81a (diff)
downloadkoopatlas-5a70b9a8d357a44fc245a95b76f8ab17aa03bc6e.tar.gz
koopatlas-5a70b9a8d357a44fc245a95b76f8ab17aa03bc6e.zip
path widget button thingy
Diffstat (limited to '')
-rw-r--r--src/editorui/editormain.py4
-rw-r--r--src/editorui/paths.py135
2 files changed, 129 insertions, 10 deletions
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py
index 297ac34..8ffd034 100644
--- a/src/editorui/editormain.py
+++ b/src/editorui/editormain.py
@@ -307,8 +307,8 @@ class KPEditorWidget(QtGui.QGraphicsView):
KP.map.pathLayer.paths.append(path)
- pathitem = KPEditorPath(path)
- self.scene().addItem(pathitem)
+ pathItem = KPEditorPath(path)
+ self.scene().addItem(pathItem)
# Switch the selection to the recently drawn node, so you can keep on rolling.
diff --git a/src/editorui/paths.py b/src/editorui/paths.py
index c5a51b6..ad81fa0 100644
--- a/src/editorui/paths.py
+++ b/src/editorui/paths.py
@@ -73,7 +73,6 @@ class KPEditorNode(KPEditorItem):
self.setPalette(self.PALETTE)
-
def __init__(self, node):
KPEditorItem.__init__(self)
@@ -108,7 +107,6 @@ class KPEditorNode(KPEditorItem):
self._updatePosition()
-
@QtCore.pyqtSlot(int)
def stateChange(self, state):
@@ -145,7 +143,6 @@ class KPEditorNode(KPEditorItem):
node.level[1] = stage
-
def _updatePosition(self):
node = self._nodeRef()
x, y = node.position
@@ -162,6 +159,7 @@ class KPEditorNode(KPEditorItem):
def paint(self, painter, option, widget):
+ painter.setRenderHint(QtGui.QPainter.Antialiasing)
node = self._nodeRef()
selectionRect = None
@@ -208,8 +206,6 @@ class KPEditorNode(KPEditorItem):
self.stageProxy.hide()
-
-
def remove(self, withItem=False):
node = self._nodeRef()
layer = KP.map.pathLayer
@@ -261,6 +257,98 @@ class KPEditorNode(KPEditorItem):
class KPEditorPath(QtGui.QGraphicsLineItem):
+
+
+ class UnlockButton(QtGui.QPushButton):
+ def __init__(self, pathRef):
+ QtGui.QPushButton.__init__(self)
+
+ self.setIconSize(QtCore.QSize(32,32))
+ self.setFixedSize(64,64)
+
+ 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")
+
+ 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)
+
+ if self.path > 0:
+ painter.save()
+
+ pathItem = self._pathRef().qtItem.line()
+
+ if self.path == 1:
+ angle = pathItem.angle()
+ else:
+ angle = 180 + pathItem.angle()
+
+ painter.rotate(angle)
+ self.arrowIcon.paint(painter, self.contentsRect(), Qt.AlignCenter)
+
+ painter.restore()
+
+ if self.isDown():
+ self.iconList[self.secret].paint(painter, self.contentsRect(), Qt.AlignCenter, QtGui.QIcon.Disabled)
+ else:
+ self.iconList[self.secret].paint(painter, self.contentsRect(), Qt.AlignCenter)
+
+ else:
+ if self.isDown():
+ self.unlockIcon.paint(painter, self.contentsRect(), Qt.AlignCenter, QtGui.QIcon.Disabled)
+ else:
+ self.unlockIcon.paint(painter, self.contentsRect(), Qt.AlignCenter)
+
+ painter.end()
+
+
+ class HiddenProxy(QtGui.QGraphicsProxyWidget):
+ def __init__(self, button, parent, x, y):
+ QtGui.QGraphicsProxyWidget.__init__(self, parent)
+
+ self.setWidget(button)
+ self.setPos(x, y)
+ self.setZValue(parent.zValue()+1000)
+ self.hide()
+
+
def __init__(self, path):
QtGui.QGraphicsLineItem.__init__(self)
@@ -277,13 +365,19 @@ class KPEditorPath(QtGui.QGraphicsLineItem):
path.qtItem = self
- self.updatePosition()
-
if not hasattr(KPEditorPath, 'PEN'):
KPEditorPath.BRUSH = QtGui.QBrush(QtGui.QColor(255, 255, 255, 140))
KPEditorPath.PEN = QtGui.QPen(KPEditorPath.BRUSH, 8, Qt.SolidLine, Qt.RoundCap)
self.setPen(KPEditorPath.PEN)
+ 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, -32, -32)
+
+ self.updatePosition()
+
def updatePosition(self):
path = self._pathRef()
@@ -291,9 +385,34 @@ class KPEditorPath(QtGui.QGraphicsLineItem):
x1, y1 = path._startNodeRef().position
x2, y2 = path._endNodeRef().position
- self.setLine(QtCore.QLineF(x1+12, y1+12, x2+12, y2+12))
+ originLine = QtCore.QLineF(x1+12, y1+12, x2+12, y2+12)
+ self.setPos(originLine.pointAt(0.5))
+ dy = originLine.dy()/2
+ dx = originLine.dx()/2
+
+ self.setLine(QtCore.QLineF(-dx, -dy, dx, dy))
+ def paint(self, painter, option, widget):
+
+ painter.setRenderHint(QtGui.QPainter.Antialiasing)
+
+ painter.setPen(KPEditorPath.PEN)
+ painter.drawLine(self.line())
+
+ if self.isSelected():
+ painter.setPen(self.SELECTION_PEN)
+ painter.setBrush(QtGui.QColor(0,0,0,0))
+ painter.drawPath(self.shape())
+
+ self.unlockProxy.show()
+
+ else:
+ self.unlockProxy.hide()
+
+
+
+
def remove(self, withItem=False):
path = self._pathRef()
layer = KP.map.pathLayer