From 5a9439be8028d4f7650100b8ee2498f5e7275690 Mon Sep 17 00:00:00 2001 From: tzutalin Date: Wed, 1 Mar 2017 20:13:02 +0800 Subject: [PATCH] Fix the issue about undefined pos variable --- libs/canvas.py | 68 +++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/libs/canvas.py b/libs/canvas.py index 95f6d912..431ee87d 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -184,27 +184,7 @@ class Canvas(QWidget): if ev.button() == Qt.LeftButton: if self.drawing(): - if self.current and self.current.reachMaxPoints() is False: - initPos = self.current[0] - minX = initPos.x() - minY = initPos.y() - targetPos = self.line[1] - maxX = targetPos.x() - maxY = targetPos.y() - self.current.addPoint(QPointF(maxX, minY)) - self.current.addPoint(targetPos) - self.current.addPoint(QPointF(minX, maxY)) - self.current.addPoint(initPos) - self.line[0] = self.current[-1] - if self.current.isClosed(): - self.finalise() - elif not self.outOfPixmap(pos): - self.current = Shape() - self.current.addPoint(pos) - self.line.points = [pos, pos] - self.setHiding() - self.drawingPolygon.emit(True) - self.update() + self.handleDrawing(pos) else: self.selectShapePoint(pos) self.prevPoint = pos @@ -226,28 +206,9 @@ class Canvas(QWidget): elif ev.button() == Qt.LeftButton and self.selectedShape: self.overrideCursor(CURSOR_GRAB) elif ev.button() == Qt.LeftButton: + pos = self.transformPos(ev.pos()) if self.drawing(): - if self.current and self.current.reachMaxPoints() is False: - initPos = self.current[0] - minX = initPos.x() - minY = initPos.y() - targetPos = self.line[1] - maxX = targetPos.x() - maxY = targetPos.y() - self.current.addPoint(QPointF(maxX, minY)) - self.current.addPoint(targetPos) - self.current.addPoint(QPointF(minX, maxY)) - self.current.addPoint(initPos) - self.line[0] = self.current[-1] - if self.current.isClosed(): - self.finalise() - elif not self.outOfPixmap(pos): - self.current = Shape() - self.current.addPoint(pos) - self.line.points = [pos, pos] - self.setHiding() - self.drawingPolygon.emit(True) - self.update() + self.handleDrawing(pos) def endMove(self, copy=False): assert self.selectedShape and self.selectedShapeCopy @@ -273,6 +234,29 @@ class Canvas(QWidget): self.setHiding(True) self.repaint() + def handleDrawing(self, pos): + if self.current and self.current.reachMaxPoints() is False: + initPos = self.current[0] + minX = initPos.x() + minY = initPos.y() + targetPos = self.line[1] + maxX = targetPos.x() + maxY = targetPos.y() + self.current.addPoint(QPointF(maxX, minY)) + self.current.addPoint(targetPos) + self.current.addPoint(QPointF(minX, maxY)) + self.current.addPoint(initPos) + self.line[0] = self.current[-1] + if self.current.isClosed(): + self.finalise() + elif not self.outOfPixmap(pos): + self.current = Shape() + self.current.addPoint(pos) + self.line.points = [pos, pos] + self.setHiding() + self.drawingPolygon.emit(True) + self.update() + def setHiding(self, enable=True): self._hideBackround = self.hideBackround if enable else False