Example #1
0
 def mouseMoveEvent(self, event):
     contour = self._targetContour
     if contour is None:
         return
     # we don't make any check here, mousePressEvent did it for us
     pos = event.localPos()
     # selected point
     pt = contour[-1]
     if not contour.open:
         pt_ = contour[0]
         if pt_.selected:
             pt = pt_
     if pt.segmentType and not self._shouldMoveOnCurve:
         # don't make a curve until enough distance is reached
         widget = self.parent()
         rect = QRectF(self._origin, pos)
         widgetRect = widget.mapRectFromCanvas(rect)
         if (widgetRect.bottomRight() - widgetRect.topLeft(
                 )).manhattanLength() < 10:
             return
         # go
         pt.selected = False
         pt.smooth = not event.modifiers() & Qt.AltModifier
         contour.holdNotifications()
         if pt.segmentType == "line":
             self._coerceSegmentToCurve(contour, pt, pos)
         # TODO: defer this if Alt is pressed
         elif pt.smooth and contour.open:
             # if there's a curve segment behind, we need to update the
             # offCurve's position to inverse
             if len(contour) > 1:
                 onCurveBefore = contour[-2]
                 onCurveBefore.x = 2 * pt.x - pos.x()
                 onCurveBefore.y = 2 * pt.y - pos.y()
         if contour.open:
             contour.addPoint((pos.x(), pos.y()))
         contour[-1].selected = True
         contour.postNotification(
             notification="Contour.SelectionChanged")
         contour.releaseHeldNotifications()
     else:
         if pt.segmentType:
             onCurve = pt
         elif contour.open:
             onCurve = contour[-2]
         else:
             onCurve = contour[0]
         if event.modifiers() & Qt.ShiftModifier:
             pos = self.clampToOrigin(
                 pos, QPointF(onCurve.x, onCurve.y))
         if self._shouldMoveOnCurve:
             dx = pos.x() - pt.x
             dy = pos.y() - pt.y
             moveUIPoint(contour, onCurve, (dx, dy))
         else:
             pt.x = pos.x()
             pt.y = pos.y()
             if contour.open and len(contour) >= 3 and onCurve.smooth:
                 if onCurve.segmentType == "line":
                     self._coerceSegmentToCurve(contour, onCurve, pos)
                 otherSidePoint = contour[-3]
                 otherSidePoint.x = 2 * onCurve.x - pos.x()
                 otherSidePoint.y = 2 * onCurve.y - pos.y()
         contour.dirty = True
Example #2
0
 def mouseMoveEvent(self, event):
     if not event.buttons() & Qt.LeftButton:
         super().mouseMoveEvent(event)
         return
     contour = self._targetContour
     if contour is None:
         return
     # we don't make any check here, mousePressEvent did it for us
     pos = event.pos()
     # selected point
     pt = contour[-1]
     if not contour.open:
         pt_ = contour[0]
         if pt_.selected:
             pt = pt_
     if pt.segmentType and not self._shouldMoveOnCurve:
         # don't make a curve until enough distance is reached
         widget = self.parent()
         rect = QRectF(self._origin, event.localPos())
         widgetRect = widget.mapRectFromCanvas(rect)
         if (widgetRect.bottomRight() - widgetRect.topLeft()).manhattanLength() < 10:
             return
         # go
         onSmooth = not event.modifiers() & Qt.AltModifier
         pt.selected = False
         pt.smooth = len(contour) > 1 and onSmooth
         contour.holdNotifications()
         if pt.segmentType == "line" and onSmooth:
             self._coerceSegmentToCurve(contour, pt, pos)
         elif pt.smooth and contour.open:
             # if there's a curve segment behind, we need to update the
             # offCurve's position to inverse
             if len(contour) > 1:
                 onCurveBefore = contour[-2]
                 onCurveBefore.x = 2 * pt.x - pos.x()
                 onCurveBefore.y = 2 * pt.y - pos.y()
         if contour.open:
             contour.addPoint((pos.x(), pos.y()))
         contour[-1].selected = True
         contour.postNotification(notification="Contour.SelectionChanged")
         contour.releaseHeldNotifications()
     else:
         if pt.segmentType:
             onCurve = pt
         elif contour.open:
             onCurve = contour[-2]
         else:
             onCurve = contour[0]
         if event.modifiers() & Qt.ShiftModifier:
             pos = self.clampToOrigin(
                 event.localPos(), QPointF(onCurve.x, onCurve.y)
             ).toPoint()
         if self._shouldMoveOnCurve:
             dx = pos.x() - pt.x
             dy = pos.y() - pt.y
             moveUIPoint(contour, onCurve, (dx, dy))
         else:
             pt.x = pos.x()
             pt.y = pos.y()
             if contour.open and len(contour) >= 3 and onCurve.smooth:
                 if onCurve.segmentType == "line":
                     self._coerceSegmentToCurve(contour, onCurve, pos)
                 otherSidePoint = contour[-3]
                 otherSidePoint.x = 2 * onCurve.x - pos.x()
                 otherSidePoint.y = 2 * onCurve.y - pos.y()
         contour.dirty = True
Example #3
0
 def mouseMoveEvent(self, event):
     contour = self._targetContour
     if contour is None:
         return
     # we don't make any check here, mousePressEvent did it for us
     pos = event.localPos()
     pt = contour[-1]
     if pt.segmentType and not self._shouldMoveOnCurve:
         # don't make a curve until enough distance is reached
         widget = self.parent()
         rect = QRectF(self._origin, pos)
         widgetRect = widget.mapRectFromCanvas(rect)
         if (widgetRect.bottomRight() - widgetRect.topLeft(
                 )).manhattanLength() < 10:
             return
         # go
         pt.selected = False
         pt.smooth = not event.modifiers() & Qt.AltModifier
         contour.holdNotifications()
         # TODO: defer this if Alt is pressed
         if not contour.open:
             # pt is the last point before contour start
             if pt.segmentType:
                 contour.addPoint((pt.x, pt.y))
             startPt = contour[0]
             startPt.segmentType = "curve"
         elif pt.segmentType == "line":
             # remove the onCurve
             contour.removePoint(pt)
             # add the first of two offCurves
             otherPt = contour[-1]
             contour.addPoint((otherPt.x, otherPt.y))
             # add an offCurve before pt
             inverseX = 2 * pt.x - pos.x()
             inverseY = 2 * pt.y - pos.y()
             contour.addPoint((inverseX, inverseY))
             # now add pt back as curve point
             pt.segmentType = "curve"
             contour.insertPoint(len(self._targetContour), pt)
         else:
             # if there's a curve segment behind, we need to update the
             # offCurve's position to inverse
             if len(contour) > 1:
                 onCurveBefore = contour[-2]
                 onCurveBefore.x = 2 * pt.x - pos.x()
                 onCurveBefore.y = 2 * pt.y - pos.y()
         contour.addPoint((pos.x(), pos.y()))
         contour[-1].selected = True
         contour.releaseHeldNotifications()
     else:
         if pt.segmentType:
             onCurve = pt
         elif contour.open:
             onCurve = contour[-2]
         else:
             onCurve = contour[0]
         if event.modifiers() & Qt.ShiftModifier:
             pos = self.clampToOrigin(
                 pos, QPointF(onCurve.x, onCurve.y))
         if self._shouldMoveOnCurve:
             dx = pos.x() - pt.x
             dy = pos.y() - pt.y
             moveUIPoint(contour, onCurve, (dx, dy))
         else:
             pt.x = pos.x()
             pt.y = pos.y()
             if contour.open and len(contour) >= 3 and onCurve.smooth:
                 otherSidePoint = contour[-3]
                 otherSidePoint.x = 2 * onCurve.x - pos.x()
                 otherSidePoint.y = 2 * onCurve.y - pos.y()
         contour.dirty = True