From ba959d67836d483007c384f1a87fcfba12332295 Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Mon, 21 May 2012 01:41:02 -0500 Subject: Added copying, proper top-dwn selection --- src/ui.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 6 deletions(-) (limited to 'src/ui.py') diff --git a/src/ui.py b/src/ui.py index 568a0a8..dc95f85 100644 --- a/src/ui.py +++ b/src/ui.py @@ -3,7 +3,7 @@ from common import * from editorui.editorcommon import * from editorui.editormain import * -import os +import os, copy import os.path @@ -963,6 +963,7 @@ class KPMainWindow(QtGui.QMainWindow): self.setIconSize(QtCore.QSize(16, 16)) self.scene = KPMapScene() + self.clipboard = None self.editor = KPEditorWidget(self.scene) self.setCentralWidget(self.editor) @@ -1003,13 +1004,14 @@ class KPMainWindow(QtGui.QMainWindow): self.ff = f.addAction('Export...', self.exportMap, QKeySequence("Ctrl+Shift+E")) f.addSeparator() self.fg = f.addAction('Take Screenshot...', self.screenshot, QKeySequence("Ctrl+Alt+S")) + self.fh = f.addAction('Export Doodads...', self.exportDoodads, QKeySequence("Ctrl+Alt+Shift+D")) f.addSeparator() # self.fi = f.addAction('Quit') e = mb.addMenu('Edit') - self.ea = e.addAction('Copy') # C + self.ea = e.addAction('Copy', self.copy, QKeySequence.Copy) self.eb = e.addAction('Cut') # X - self.ec = e.addAction('Paste') # V + self.ec = e.addAction('Paste', self.paste, QKeySequence.Paste) e.addSeparator() self.ed = e.addAction('Select All', self.selectAll, QKeySequence.SelectAll) self.ee = e.addAction('Deselect', self.deSelect, QKeySequence("Ctrl+D")) @@ -1038,11 +1040,13 @@ class KPMainWindow(QtGui.QMainWindow): w = mb.addMenu('Window') self.wa = w.addAction('Show Grid', self.showGrid, QKeySequence("Ctrl+G")) + self.wa.setCheckable(True) w.addSeparator() self.wb = w.addAction('Zoom In', self.ZoomIn, QKeySequence.ZoomIn) self.wc = w.addAction('Zoom Out', self.ZoomOut, QKeySequence.ZoomOut) self.wd = w.addAction('Actual Size', self.ZoomActual, QKeySequence("Ctrl+=")) - self.wh = w.addAction('Show Wii Zoom', self.showWiiZoom) + self.wh = w.addAction('Show Wii Zoom', self.showWiiZoom, QKeySequence("Ctrl+F")) + self.wh.setCheckable(True) w.addSeparator() layerAction = self.layerListDock.toggleViewAction() @@ -1305,6 +1309,17 @@ class KPMainWindow(QtGui.QMainWindow): ScreenshotImage.save(fn, 'PNG', 50) + @QtCore.pyqtSlot() + def exportDoodads(self): + fn = QtGui.QFileDialog.getExistingDirectory(self, 'Choose a folder') + if fn == '': return + fn = unicode(fn) + + for d in KP.map.doodadDefinitions: + d[1].save(fn + d[0] + '.png', 'PNG') + + + # Edit ######################## @QtCore.pyqtSlot() @@ -1319,6 +1334,39 @@ class KPMainWindow(QtGui.QMainWindow): self.scene.clearSelection() + @QtCore.pyqtSlot() + def copy(self): + self.clipboard = self.scene.selectedItems() + + + @QtCore.pyqtSlot() + def paste(self): + self.scene.clearSelection() + for paper in self.clipboard: + layer = paper._layerRef() + + if isinstance(paper, KPEditorObject): + co = copy.deepcopy(paper._objRef()) + + co.updateCache() + layer.objects.append(co) + layer.updateCache() + + q = KPEditorObject(co, layer) + self.scene.addItem(q) + q.setSelected(True) + + if isinstance(paper, KPEditorDoodad): + cd = copy.copy(paper._doodadRef()) + + layer.objects.append(cd) + + cd.setupAnimations() + q = KPEditorDoodad(cd, layer) + self.scene.addItem(q) + q.setSelected(True) + + # Layers ######################## @QtCore.pyqtSlot() @@ -1510,15 +1558,22 @@ class KPMainWindow(QtGui.QMainWindow): if self.scene.grid == True: self.scene.grid = False + self.wa.setChecked(False) else: self.scene.grid = True + self.wa.setChecked(True) - print self.scene.grid self.scene.update() @QtCore.pyqtSlot(bool) def showWiiZoom(self): - pass + if self.editor.grid == True: + self.editor.grid = False + + else: + self.editor.grid = True + + self.editor.update() # Help -- cgit v1.2.3