From 43dc2792df7c98d985209c95654cd55faa67ea75 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 21 Nov 2011 16:12:40 +0100 Subject: some stylistic fixes, changed how the proxies work --- src/editorui/editormain.py | 6 ------ src/editorui/paths.py | 52 ++++++++++++++++++---------------------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index d11642a..297ac34 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -264,9 +264,6 @@ class KPEditorWidget(QtGui.QGraphicsView): nodeItem = KPEditorNode(node) self.scene().addItem(nodeItem) - self.scene().addItem(nodeItem.buttonProxy) - self.scene().addItem(nodeItem.stageProxy) - self.scene().addItem(nodeItem.worldProxy) self.painting = node self.paintingItem = item @@ -287,9 +284,6 @@ class KPEditorWidget(QtGui.QGraphicsView): item = KPEditorNode(node) self.scene().addItem(item) - self.scene().addItem(item.buttonProxy) - self.scene().addItem(item.stageProxy) - self.scene().addItem(item.worldProxy) # Paint a path to this node (if one is selected) sourceItem, sourceNode = None, None diff --git a/src/editorui/paths.py b/src/editorui/paths.py index 4dca31e..f6ea252 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -6,8 +6,7 @@ class KPEditorNode(KPEditorItem): SNAP_TO = (12,12) - class toggleButton(QtGui.QPushButton): - + class ToggleButton(QtGui.QPushButton): stateToggled = QtCore.pyqtSignal(int) @@ -29,7 +28,6 @@ class KPEditorNode(KPEditorItem): def toggle(self): - self.state += 1 if self.state == 3: self.state = 0 @@ -38,7 +36,6 @@ class KPEditorNode(KPEditorItem): def paintEvent(self, event): - painter = QtGui.QPainter(self) painter.setBackgroundMode(Qt.TransparentMode) @@ -52,22 +49,21 @@ class KPEditorNode(KPEditorItem): painter.end() - class hiddenProxy(QtGui.QGraphicsProxyWidget): - def __init__(self, button): - QtGui.QGraphicsProxyWidget.__init__(self) + class HiddenProxy(QtGui.QGraphicsProxyWidget): + def __init__(self, button, parent, x, y): + QtGui.QGraphicsProxyWidget.__init__(self, parent) self.setWidget(button) - self.setZValue(self.zValue()+1000) + self.setPos(x, y) + self.setZValue(parent.zValue()+1000) self.hide() - class levelSlotSpinner(QtGui.QSpinBox): - + class LevelSlotSpinner(QtGui.QSpinBox): def __init__(self): QtGui.QSpinBox.__init__(self) self.setRange(1, 99) - self.setPalette(QtGui.QPalette(QtGui.QColor(0,0,0,0))) @@ -81,23 +77,25 @@ class KPEditorNode(KPEditorItem): self.setZValue(101) self._boundingRect = QtCore.QRectF(-24, -24, 48, 48) - self._tinyRect = QtCore.QRectF(-12, -12, 24, 24) + self._levelRect = self._boundingRect + self._stopRect = QtCore.QRectF(-12, -12, 24, 24) + self._tinyRect = QtCore.QRectF(-6, -6, 12, 12) if not hasattr(KPEditorNode, 'SELECTION_PEN'): KPEditorNode.SELECTION_PEN = QtGui.QPen(Qt.blue, 1, Qt.DotLine) - self.button = self.toggleButton() - self.buttonProxy = self.hiddenProxy(self.button) + self.button = self.ToggleButton() + self.buttonProxy = self.HiddenProxy(self.button, self, 12, -12) self.button.stateToggled.connect(self.stateChange) - self.world = self.levelSlotSpinner() - self.worldProxy = self.hiddenProxy(self.world) + self.world = self.LevelSlotSpinner() + self.worldProxy = self.HiddenProxy(self.world, self, -42, 24) self.world.valueChanged.connect(self.worldChange) - self.stage = self.levelSlotSpinner() - self.stageProxy = self.hiddenProxy(self.stage) + self.stage = self.LevelSlotSpinner() + self.stageProxy = self.HiddenProxy(self.stage, self, 6, 24) self.stage.valueChanged.connect(self.stageChange) @@ -111,6 +109,7 @@ class KPEditorNode(KPEditorItem): node = self._nodeRef() if state == 1: + node.isStop = True node.level = [1, 1] self.world.setValue(node.level[0]) self.stage.setValue(node.level[1]) @@ -145,19 +144,12 @@ class KPEditorNode(KPEditorItem): node = self._nodeRef() x, y = node.position self.setPos(x+12, y+12) - self.buttonProxy.setPos(self.x()+12, self.y()-24) - self.worldProxy.setPos(self.x()-42, self.y()+24) - self.stageProxy.setPos(self.x()+6, self.y()+24) def _itemMoved(self, oldX, oldY, newX, newY): node = self._nodeRef() node.position = (newX-12, newY-12) - self.buttonProxy.setPos(newX+12, newY-24) - self.worldProxy.setPos(newX-42, newY+24) - self.stageProxy.setPos(newX+6, newY+24) - for exit in node.exits: exit.qtItem.updatePosition() @@ -172,14 +164,14 @@ class KPEditorNode(KPEditorItem): painter.setBrush(QtGui.QColor(0, 0, 0, 0)) painter.setPen(QtGui.QColor(0, 0, 0, 0)) painter.drawPixmap(self._boundingRect.topLeft(), QtGui.QPixmap("Resources/BlackLevel.png")) - selectionRect = self._boundingRect.adjusted(-1,-1,1,1) + selectionRect = self._boundingRect.adjusted(1,5,-1,-5) elif node.isStop: brush = QtGui.QBrush(QtGui.QColor(255, 220, 220)) painter.setPen(QtGui.QColor(255, 255, 255)) painter.setBrush(brush) - painter.drawEllipse(self._tinyRect) - selectionRect = self._tinyRect.adjusted(-1,-1,1,1) + painter.drawEllipse(self._stopRect) + selectionRect = self._stopRect.adjusted(-1,-1,1,1) else: brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) @@ -218,10 +210,6 @@ class KPEditorNode(KPEditorItem): layer.nodes.remove(node) - self.scene().removeItem(self.buttonProxy) - self.scene().removeItem(self.stageProxy) - self.scene().removeItem(self.worldProxy) - if len(node.exits) == 2: # let's try to join the two! pathOne, pathTwo = node.exits -- cgit v1.2.3