diff options
Diffstat (limited to '')
-rw-r--r-- | src/editorui.py | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/editorui.py b/src/editorui.py index 3b9b74e..6b0815c 100644 --- a/src/editorui.py +++ b/src/editorui.py @@ -237,6 +237,18 @@ class KPEditorObject(KPEditorItem): self._layerRef().updateCache() + def remove(self): + + obj = self._objRef() + layer = self._layerRef() + + index = layer.objects.index(obj) + layer.objects.pop(index) + layer.updateCache() + del obj + + + class KPEditorDoodad(QtGui.QGraphicsPixmapItem): def __init__(self, doodad, layer): QtGui.QGraphicsPixmapItem.__init__(self) @@ -400,8 +412,8 @@ class KPEditorDoodad(QtGui.QGraphicsPixmapItem): origX = originalPos.x() origY = originalPos.y() - dy = origY - objY - dx = origX - objX + dy = origY - objY + dx = origX - objX rads = math.atan2(dy, dx) origAngle = math.degrees(rads) @@ -409,8 +421,8 @@ class KPEditorDoodad(QtGui.QGraphicsPixmapItem): - dy = mouseY - objY - dx = mouseX - objX + dy = mouseY - objY + dx = mouseX - objX rads = math.atan2(dy, dx) angle = math.degrees(rads) @@ -431,7 +443,7 @@ class KPEditorDoodad(QtGui.QGraphicsPixmapItem): # Fucking Transform can't do independent transforms with doing matrix math directly. # And before anyone asks, using QTransform.scale() is no good. - + if self.resizing: obj = self._doodadRef() scenePos = event.scenePos() @@ -474,6 +486,17 @@ class KPEditorDoodad(QtGui.QGraphicsPixmapItem): KPEditorItem.mouseReleaseEvent(self, event) + def remove(self): + + doodad = self._doodadRef() + layer = self._layerRef() + + index = layer.objects.index(doodad) + layer.objects.pop(index) + del doodad + + + class KPMapScene(QtGui.QGraphicsScene): def __init__(self): @@ -753,3 +776,23 @@ class KPEditorWidget(QtGui.QGraphicsView): QtGui.QGraphicsView.mouseMoveEvent(self, event) + def keyPressEvent(self, event): + if event.key() == QtCore.Qt.Key_Delete or event.key() == QtCore.Qt.Key_Backspace: + scene = self.scene() + + selection = scene.selectedItems() + if len(selection) > 0: + for obj in selection: + obj.remove() + obj.setSelected(False) + scene.removeItem(obj) + scene.update() + self.update() + return + + else: + QtGui.QGraphicsView.keyPressEvent(self, event) + + + + |