From 68e66b16255ea2603bd323083e3b5b43280caff1 Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Thu, 17 Nov 2011 06:44:17 -0600 Subject: Deleting Editor Items and their associated shitpiles of underlying abstractions is now implemented. --- src/editorui.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/ui.py | 2 +- 2 files changed, 49 insertions(+), 6 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) + + + + diff --git a/src/ui.py b/src/ui.py index 825a713..b785a69 100644 --- a/src/ui.py +++ b/src/ui.py @@ -145,7 +145,7 @@ class KPDoodadSelector(QtGui.QWidget): self.doodadList.keyPressEvent(event) - if event.key() == 0x1000003: + if event.key() == QtCore.Qt.Key_Delete or event.key() == QtCore.Qt.Key_Backspace: msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "Delete Doodad?", "Are you sure you want to delete this doodad? This action cannot be undone.", -- cgit v1.2.3