diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/defconQt/glyphView.py | 70 | ||||
| -rw-r--r-- | Lib/defconQt/objects/defcon.py | 3 | 
2 files changed, 45 insertions, 28 deletions
| diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index da933c2..6ca8f07 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -626,7 +626,7 @@ class OffCurvePointItem(QGraphicsEllipseItem):          self._needsUngrab = False      def delete(self): -        self.parentItem()._CPDeleted() +        self.parentItem()._CPDeleted(self)      def itemChange(self, change, value):          if change == QGraphicsItem.ItemPositionChange: @@ -646,10 +646,9 @@ class OffCurvePointItem(QGraphicsEllipseItem):                  else:                      value.setY(0)          elif change == QGraphicsItem.ItemPositionHasChanged: -            self.parentItem()._CPMoved(value) -        # TODO: consider what to do w offCurves -        # elif change == QGraphicsItem.ItemSelectedHasChanged: -        #    pass#self.parentItem()._CPSelChanged(value) +            self.parentItem()._CPMoved(self, value) +        elif change == QGraphicsItem.ItemSelectedHasChanged: +            self.parentItem()._CPSelected(self, value)          return value      def mousePressEvent(self, event): @@ -775,26 +774,32 @@ class OnCurvePointItem(QGraphicsPathItem):                  index += 1          return index % len(self._contour.segments) -    def _CPDeleted(self): +    def _CPDeleted(self, item): +        # XXX: is this sufficient guard? +        if self.isSelected(): return          pointIndex = self.getPointIndex()          children = self.childItems() -        selected = 1 -        if not (children[1].isVisible() and children[1].isSelected()): -            selected = 3 +        if item == children[1]: +            delta = -1 +            segmentOn = 0 +        else: +            delta = 1 +            segmentOn = 3 -        firstSibling = self._contour[pointIndex + selected - 2] -        secondSibling = self._contour[pointIndex + (selected - 2) * 2] +        firstSibling = self._contour.getPoint(pointIndex + delta) +        secondSibling = self._contour.getPoint(pointIndex + delta * 2)          if (firstSibling.segmentType is None and                  secondSibling.segmentType is None):              # we have two offCurves, wipe them +            self._contour.getPoint(pointIndex + segmentOn).segmentType = "line"              self._contour.removePoint(firstSibling)              self._contour.removePoint(secondSibling) -    def _CPMoved(self, newValue): +    def _CPMoved(self, item, newValue):          pointIndex = self.getPointIndex()          children = self.childItems()          # nodes are stored after lines (for stacking order) -        if children[1].isSelected(): +        if item == children[1]:              selected = 1              propagate = 3          else: @@ -806,8 +811,8 @@ class OnCurvePointItem(QGraphicsPathItem):          if not len(children) > 4:              elemIndex = pointIndex - 2 + selected -            self._contour[elemIndex].x = self.pos().x() + newValue.x() -            self._contour[elemIndex].y = self.pos().y() + newValue.y() +            self._contour.getPoint(elemIndex).x = self.pos().x() + newValue.x() +            self._contour.getPoint(elemIndex).y = self.pos().y() + newValue.y()          if not (self._isSmooth and children[propagate].isVisible()):              self.setShallowDirty()              return @@ -829,11 +834,21 @@ class OnCurvePointItem(QGraphicsPathItem):          children[propagate].setFlag(QGraphicsItem.ItemSendsGeometryChanges)          children[propagate - 1].setLine(line.x1(),                                          line.y1(), tmpLine.x2(), tmpLine.y2()) -        propagateInContour = pointIndex - 2 + propagate -        self._contour[propagateInContour].x = self.pos().x() + tmpLine.x2() -        self._contour[propagateInContour].y = self.pos().y() + tmpLine.y2() +        propagateIn = pointIndex - 2 + propagate +        self._contour.getPoint(propagateIn).x = self.pos().x() + tmpLine.x2() +        self._contour.getPoint(propagateIn).y = self.pos().y() + tmpLine.y2()          self.setShallowDirty() +    def _CPSelected(self, item, value): +        pointIndex = self.getPointIndex() +        children = self.childItems() +        if item == children[1]: +            delta = -1 +        else: +            delta = 1 + +        self._contour[pointIndex + delta].selected = value +      def itemChange(self, change, value):          if change == QGraphicsItem.ItemPositionChange:              if self.scene()._integerPlane: @@ -848,12 +863,12 @@ class OnCurvePointItem(QGraphicsPathItem):              children = self.childItems()              if children[1].isVisible():                  prevPos = children[1].pos() -                self._contour[pointIndex - 1].x = self.pos().x() + prevPos.x() -                self._contour[pointIndex - 1].y = self.pos().y() + prevPos.y() +                self._contour.getPoint(pointIndex - 1).x = self.pos().x() + prevPos.x() +                self._contour.getPoint(pointIndex - 1).y = self.pos().y() + prevPos.y()              if children[3].isVisible():                  nextPos = children[3].pos() -                self._contour[pointIndex + 1].x = self.pos().x() + nextPos.x() -                self._contour[pointIndex + 1].y = self.pos().y() + nextPos.y() +                self._contour.getPoint(pointIndex + 1).x = self.pos().x() + nextPos.x() +                self._contour.getPoint(pointIndex + 1).y = self.pos().y() + nextPos.y()              self.setShallowDirty()          elif change == QGraphicsItem.ItemSelectedHasChanged:              self._point.selected = value @@ -886,11 +901,11 @@ class OnCurvePointItem(QGraphicsPathItem):          scene = self.scene()          scene._blocked = True          # if we have line segment, insert offCurve points -        insertIndex = (ptIndex + (i - 1) // 2) % len(self._contour) -        if self._contour[insertIndex].segmentType == "line": -            nextToCP = self._contour[(ptIndex - 2 + i) % len(self._contour)] +        insertIndex = ptIndex + (i - 1) // 2 +        if self._contour.getPoint(insertIndex).segmentType == "line": +            nextToCP = self._contour.getPoint(ptIndex - 2 + i)              assert(nextToCP.segmentType is not None) -            self._contour[insertIndex].segmentType = "curve" +            self._contour.getPoint(insertIndex).segmentType = "curve"              if i == 1:                  first, second = (                      self._point.x, self._point.y), (nextToCP.x, nextToCP.y) @@ -2179,14 +2194,13 @@ class GlyphView(QGraphicsView):      def updateActiveLayerPath(self):          self.updateLayerPath(              self._layer, representationKey="defconQt.NoComponentsQPainterPath") +        self.addStartPoints()      def updateLayerPath(self, layer,                          representationKey="defconQt.QPainterPath"):          glyph = layer[self._name] -        # scene = self.scene()  # unused          path = glyph.getRepresentation(representationKey)          self._sceneItems[layer].setPath(path) -        self.addStartPoints()      def _getSceneItems(self, key, clear=False):          items = self._sceneItems.get(key, None) diff --git a/Lib/defconQt/objects/defcon.py b/Lib/defconQt/objects/defcon.py index 496f1c6..bb1336b 100644 --- a/Lib/defconQt/objects/defcon.py +++ b/Lib/defconQt/objects/defcon.py @@ -93,6 +93,9 @@ class TContour(Contour):                                selected=point.selected)          pointPen.endPath() +    def getPoint(self, index): +        return self[index % len(self)] +  class TPoint(Point):      __slots__ = ["_selected"] | 
