|
@@ -25,6 +25,7 @@ class Canvas(QWidget):
|
|
|
newShape = pyqtSignal(QPoint)
|
|
|
selectionChanged = pyqtSignal(bool)
|
|
|
shapeMoved = pyqtSignal()
|
|
|
+ drawMode = pyqtSignal(bool)
|
|
|
|
|
|
SELECT, EDIT = range(2)
|
|
|
|
|
@@ -50,12 +51,19 @@ class Canvas(QWidget):
|
|
|
self.hideBackround = False
|
|
|
self.highlightedShape = None
|
|
|
self._painter = QPainter()
|
|
|
+ self._cursor = CURSOR_DEFAULT
|
|
|
# Menus:
|
|
|
self.menus = (QMenu(), QMenu())
|
|
|
# Set widget options.
|
|
|
self.setMouseTracking(True)
|
|
|
self.setFocusPolicy(Qt.WheelFocus)
|
|
|
|
|
|
+ def enterEvent(self, ev):
|
|
|
+ self.overrideCursor(self._cursor)
|
|
|
+
|
|
|
+ def leaveEvent(self, ev):
|
|
|
+ self.restoreCursor()
|
|
|
+
|
|
|
def focusOutEvent(self, ev):
|
|
|
self.restoreCursor()
|
|
|
|
|
@@ -74,6 +82,24 @@ class Canvas(QWidget):
|
|
|
|
|
|
self.restoreCursor()
|
|
|
|
|
|
+ # Polygon drawing.
|
|
|
+ if self.editing():
|
|
|
+ self.overrideCursor(CURSOR_DRAW)
|
|
|
+ if self.current:
|
|
|
+ color = self.lineColor
|
|
|
+ if self.outOfPixmap(pos):
|
|
|
+ # Don't allow the user to draw outside the pixmap.
|
|
|
+ # Project the point to the pixmap's edges.
|
|
|
+ pos = self.intersectionPoint(self.current[-1], pos)
|
|
|
+ elif len(self.current) > 1 and self.closeEnough(pos, self.current[0]):
|
|
|
+ # Attract line to starting point and colorise to alert the user:
|
|
|
+ pos = self.current[0]
|
|
|
+ color = self.current.line_color
|
|
|
+ self.line[1] = pos
|
|
|
+ self.line.line_color = color
|
|
|
+ self.repaint()
|
|
|
+ return
|
|
|
+
|
|
|
# Polygon copy moving.
|
|
|
if Qt.RightButton & ev.buttons():
|
|
|
if self.selectedShapeCopy and self.prevPoint:
|
|
@@ -85,25 +111,6 @@ class Canvas(QWidget):
|
|
|
self.repaint()
|
|
|
return
|
|
|
|
|
|
- # Polygon drawing.
|
|
|
- if self.editing():
|
|
|
- self.overrideCursor(CURSOR_DRAW)
|
|
|
-
|
|
|
- if self.current and self.editing():
|
|
|
- color = self.lineColor
|
|
|
- if self.outOfPixmap(pos):
|
|
|
- # Don't allow the user to draw outside the pixmap.
|
|
|
- # Project the point to the pixmap's edges.
|
|
|
- pos = self.intersectionPoint(self.current[-1], pos)
|
|
|
- elif len(self.current) > 1 and self.closeEnough(pos, self.current[0]):
|
|
|
- # Attract line to starting point and colorise to alert the user:
|
|
|
- pos = self.current[0]
|
|
|
- color = self.current.line_color
|
|
|
- self.line[1] = pos
|
|
|
- self.line.line_color = color
|
|
|
- self.repaint()
|
|
|
- return
|
|
|
-
|
|
|
# Polygon moving.
|
|
|
if Qt.LeftButton & ev.buttons() and self.selectedShape and self.prevPoint:
|
|
|
self.overrideCursor(CURSOR_MOVE)
|
|
@@ -144,6 +151,7 @@ class Canvas(QWidget):
|
|
|
self.line.points = [pos, pos]
|
|
|
self.setHiding()
|
|
|
self.repaint()
|
|
|
+ self.drawMode.emit(True)
|
|
|
else:
|
|
|
self.selectShapePoint(pos)
|
|
|
self.prevPoint = pos
|
|
@@ -322,7 +330,6 @@ class Canvas(QWidget):
|
|
|
assert self.current
|
|
|
self.shapes.append(self.current)
|
|
|
self.current = None
|
|
|
- self.setEditing(False)
|
|
|
self.setHiding(False)
|
|
|
self.repaint()
|
|
|
self.newShape.emit(self.mapToGlobal(ev.pos()))
|
|
@@ -406,6 +413,7 @@ class Canvas(QWidget):
|
|
|
if ev.key() == Qt.Key_Escape and self.current:
|
|
|
self.current = None
|
|
|
self.repaint()
|
|
|
+ self.drawMode.emit(False)
|
|
|
|
|
|
def setLastLabel(self, text):
|
|
|
assert text
|
|
@@ -449,12 +457,12 @@ class Canvas(QWidget):
|
|
|
self.repaint()
|
|
|
|
|
|
def overrideCursor(self, cursor):
|
|
|
+ self._cursor = cursor
|
|
|
QApplication.setOverrideCursor(cursor)
|
|
|
|
|
|
def restoreCursor(self):
|
|
|
QApplication.restoreOverrideCursor()
|
|
|
|
|
|
-
|
|
|
def resetState(self):
|
|
|
self.restoreCursor()
|
|
|
self.pixmap = None
|