Fix the issue about undefined pos variable

This commit is contained in:
tzutalin 2017-03-01 20:13:02 +08:00
parent a81bc381f7
commit 5a9439be80

View File

@ -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