summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Noga <Tempus@chronometry.ca>2012-05-21 01:41:02 -0500
committerColin Noga <Tempus@chronometry.ca>2012-05-21 01:41:02 -0500
commitba959d67836d483007c384f1a87fcfba12332295 (patch)
tree67ebe1f6259c5f82c4e1fdc45a9249d9d0bede76
parent197fca6d7d16fa849c6e8e214008108a26ac4c7c (diff)
downloadkoopatlas-ba959d67836d483007c384f1a87fcfba12332295.tar.gz
koopatlas-ba959d67836d483007c384f1a87fcfba12332295.zip
Added copying, proper top-dwn selection
Diffstat (limited to '')
-rw-r--r--src/editorui/doodads.py9
-rw-r--r--src/editorui/editormain.py50
-rw-r--r--src/editorui/objects.py9
-rw-r--r--src/mapdata.py5
-rw-r--r--src/ui.py67
5 files changed, 109 insertions, 31 deletions
diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py
index 6bb4576..89ccfc7 100644
--- a/src/editorui/doodads.py
+++ b/src/editorui/doodads.py
@@ -426,9 +426,9 @@ class KPEditorDoodad(KPEditorItem):
def hoverMoveEvent(self, event):
- if self._layerRef() != KP.mapScene.currentLayer:
- self.setCursor(Qt.ArrowCursor)
- return
+ # if self._layerRef() != KP.mapScene.currentLayer:
+ # self.setCursor(Qt.ArrowCursor)
+ # return
pos = event.pos()
bit = self.resizerPortionAt(pos.x(), pos.y())
@@ -460,7 +460,8 @@ class KPEditorDoodad(KPEditorItem):
pos = event.pos()
bit = self.resizerPortionAt(pos.x(), pos.y())
- if self._layerRef() == KP.mapScene.currentLayer and bit:
+ # if self._layerRef() == KP.mapScene.currentLayer and bit:
+ if bit:
event.accept()
if (event.modifiers() & Qt.ShiftModifier):
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py
index 5dc8703..1a30fcf 100644
--- a/src/editorui/editormain.py
+++ b/src/editorui/editormain.py
@@ -379,6 +379,8 @@ class KPEditorWidget(QtGui.QGraphicsView):
QtGui.QGraphicsView.__init__(self, scene, parent)
self.setRenderHints(QtGui.QPainter.Antialiasing)
+ self.setViewportUpdateMode(self.FullViewportUpdate)
+ self.grid = False
self.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.setDragMode(self.RubberBandDrag)
@@ -393,29 +395,29 @@ class KPEditorWidget(QtGui.QGraphicsView):
def drawForeground(self, painter, rect):
- painter.setPen(Qt.red)
- painter.setBrush(Qt.transparent)
+ QtGui.QGraphicsView.drawForeground(self, painter, rect)
- c = rect.center()
- x = c.x()
- y = c.y()
+ if self.grid:
+ painter.setPen(Qt.red)
+ painter.setBrush(Qt.transparent)
- zooms = [5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 150.0, 200.0, 400.0]
- m = zooms[KP.mainWindow.ZoomLevel] / 100.0
+ c = rect.center()
+ x = c.x()
+ y = c.y()
- mx = 880.0 / 2.0 * m
- my = 660.0 / 2.0 * m
+ mx = 880.0
+ my = 660.0
- m2x = 1180.0 / 2.0 * m
- m2y = 660.0 / 2.0 * m
+ m2x = 1180.0
+ m2y = 660.0
- # mx = 1792.0 / 2.0 * m
- # my = 1344.0 / 2.0 * m
- newRect = QtCore.QRectF(x-mx, y-my, mx*2.0, my*2.0)
- painter.drawRect(newRect)
+ # mx = 1792.0
+ # my = 1344.0
+ newRect = QtCore.QRectF(x-(mx/2.0), y-(my/2.0), mx, my)
+ painter.drawRect(newRect)
- newRect2 = QtCore.QRectF(x-m2x, y-m2y, m2x*2.0, m2y*2.0)
- painter.drawRect(newRect2)
+ newRect2 = QtCore.QRectF(x-(m2x/2.0), y-(m2y/2.0), m2x, m2y)
+ painter.drawRect(newRect2)
def assignNewScene(self, scene):
self.setScene(scene)
@@ -727,10 +729,20 @@ class KPEditorWidget(QtGui.QGraphicsView):
def mousePressEvent(self, event):
+ itemsUnder = self.scene().items(self.mapToScene(event.pos()), Qt.IntersectsItemShape, Qt.AscendingOrder)
+
if event.button() == Qt.RightButton:
self._tryToPaint(event)
event.accept()
+ elif itemsUnder:
+ QtGui.QGraphicsView.mousePressEvent(self, event)
+
+ if len(self.scene().selectedItems()) < 2:
+ self.scene().clearSelection()
+ itemsUnder[0].setSelected(True)
+ itemsUnder[0].grabMouse()
+
else:
QtGui.QGraphicsView.mousePressEvent(self, event)
@@ -746,6 +758,10 @@ class KPEditorWidget(QtGui.QGraphicsView):
def mouseReleaseEvent(self, event):
QtGui.QGraphicsView.mouseReleaseEvent(self, event)
+ try:
+ self.scene().mouseGrabberItem().ungrabMouse()
+ except:
+ pass
self.userClick.emit()
diff --git a/src/editorui/objects.py b/src/editorui/objects.py
index 975b365..71566a6 100644
--- a/src/editorui/objects.py
+++ b/src/editorui/objects.py
@@ -51,9 +51,9 @@ class KPEditorObject(KPEditorItem):
def hoverMoveEvent(self, event):
- if self._layerRef() != KP.mapScene.currentLayer:
- self.setCursor(Qt.ArrowCursor)
- return
+ # if self._layerRef() != KP.mapScene.currentLayer:
+ # self.setCursor(Qt.ArrowCursor)
+ # return
pos = event.pos()
bit = self.resizerPortionAt(pos.x(), pos.y())
@@ -75,7 +75,8 @@ class KPEditorObject(KPEditorItem):
pos = event.pos()
bit = self.resizerPortionAt(pos.x(), pos.y())
- if self._layerRef() == KP.mapScene.currentLayer and bit:
+ # if self._layerRef() == KP.mapScene.currentLayer and bit:
+ if bit:
event.accept()
x, xSide, y, ySide = False, None, False, None
diff --git a/src/mapdata.py b/src/mapdata.py
index 4185a19..b4b5e4b 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -33,6 +33,8 @@ class KPLayer(object):
pass
def setActivated(self, value, listToUse=None):
+ return
+
flag1 = QtGui.QGraphicsItem.ItemIsSelectable
flag2 = QtGui.QGraphicsItem.ItemIsMovable
@@ -195,6 +197,8 @@ class KPPathTileLayer(KPLayer):
item.setVisible(value)
def setActivated(self, value, listToUse=None):
+ return
+
flag1 = QtGui.QGraphicsItem.ItemIsSelectable
flag2 = QtGui.QGraphicsItem.ItemIsMovable
@@ -527,6 +531,7 @@ class KPPathLayer(KPLayer):
item.setVisible(value)
def setActivated(self, value):
+ return
KPLayer.setActivated(self, value, self.nodes)
flag = QtGui.QGraphicsItem.ItemIsSelectable
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