Exemple #1
0
 def mouseMoveEvent(self, event):
     canvasPos = event.localPos()
     widget = self.parent()
     if self._itemTuple is not None:
         if self._shouldPrepareUndo:
             self._glyph.prepareUndo()
             self._shouldPrepareUndo = False
         dx = canvasPos.x() - self._origin.x()
         dy = canvasPos.y() - self._origin.y()
         for anchor in self._glyph.anchors:
             if anchor.selected:
                 anchor.move((dx, dy))
         for contour in self._glyph:
             moveUISelection(contour, (dx, dy))
         for component in self._glyph.components:
             if component.selected:
                 component.move((dx, dy))
         self._origin = canvasPos
     else:
         self._rubberBandRect = QRectF(self._origin, canvasPos).normalized()
         items = widget.items(self._rubberBandRect)
         points = set(items["points"])
         if event.modifiers() & Qt.ShiftModifier:
             points ^= self._oldSelection
         # TODO: fine-tune this more, maybe add optional args to items...
         if event.modifiers() & Qt.AltModifier:
             points = set(pt for pt in points if pt.segmentType)
         if points != self._glyph.selection:
             # TODO: doing this takes more time than by-contour
             # discrimination for large point count
             self._glyph.selection = points
     widget.update()
Exemple #2
0
 def mouseMoveEvent(self, event):
     canvasPos = event.localPos()
     widget = self.parent()
     if self._itemTuple is not None:
         if self._shouldPrepareUndo:
             self._glyph.prepareUndo()
             self._shouldPrepareUndo = False
         modifiers = event.modifiers()
         # Alt: move point along handles
         if modifiers & Qt.AltModifier and len(self._glyph.selection) == 1:
             item, parent = self._itemTuple
             if parent is not None:
                 x, y = canvasPos.x(), canvasPos.y()
                 didMove = self._moveOnCurveAlongHandles(parent, item, x, y)
                 if didMove:
                     return
         # Shift: clamp pos on axis
         elif modifiers & Qt.ShiftModifier:
             item, parent = self._itemTuple
             if parent is not None:
                 if item.segmentType is None:
                     onCurve = self._getOffCurveSiblingPoint(parent, item)
                     canvasPos = self.clampToOrigin(
                         canvasPos, QPointF(onCurve.x, onCurve.y))
         dx = canvasPos.x() - self._origin.x()
         dy = canvasPos.y() - self._origin.y()
         for anchor in self._glyph.anchors:
             if anchor.selected:
                 anchor.move((dx, dy))
         for contour in self._glyph:
             moveUISelection(contour, (dx, dy))
         for component in self._glyph.components:
             if component.selected:
                 component.move((dx, dy))
         self._origin = canvasPos
     else:
         self._rubberBandRect = QRectF(self._origin, canvasPos).normalized()
         items = widget.items(self._rubberBandRect)
         points = set(items["points"])
         if event.modifiers() & Qt.ControlModifier:
             points ^= self._oldSelection
         # TODO: fine-tune this more, maybe add optional args to items...
         if event.modifiers() & Qt.AltModifier:
             points = set(pt for pt in points if pt.segmentType)
         if points != self._glyph.selection:
             # TODO: doing this takes more time than by-contour
             # discrimination for large point count
             self._glyph.selection = points
     widget.update()
Exemple #3
0
 def keyPressEvent(self, event):
     key = event.key()
     if key == platformSpecific.deleteKey:
         glyph = self._glyph
         # TODO: prune
         glyph.prepareUndo()
         preserveShape = not event.modifiers() & Qt.ShiftModifier
         for anchor in glyph.anchors:
             if anchor.selected:
                 glyph.removeAnchor(anchor)
         for contour in reversed(glyph):
             removeUISelection(contour, preserveShape)
         for component in glyph.components:
             if component.selected:
                 glyph.removeComponent(component)
     elif key in arrowKeys:
         # TODO: prune
         self._glyph.prepareUndo()
         delta = self._moveForEvent(event)
         # TODO: seems weird that glyph.selection and selected don't incl.
         # anchors and components while glyph.move does... see what glyphs
         # does
         hadSelection = False
         for anchor in self._glyph.anchors:
             if anchor.selected:
                 anchor.move(delta)
                 hadSelection = True
         for contour in self._glyph:
             moveUISelection(contour, delta)
             # XXX: shouldn't have to recalc this
             if contour.selection:
                 hadSelection = True
         for component in self._glyph.components:
             if component.selected:
                 component.move(delta)
                 hadSelection = True
         if not hadSelection:
             event.ignore()
     elif key in navKeys:
         pack = self._getSelectedCandidatePoint()
         if pack is not None:
             point, contour = pack
             point.selected = False
             index = contour.index(point)
             offset = int(key == Qt.Key_Greater) or -1
             newPoint = contour.getPoint(index + offset)
             newPoint.selected = True
             contour.postNotification(
                 notification="Contour.SelectionChanged")
Exemple #4
0
 def mouseMoveEvent(self, event):
     canvasPos = event.localPos()
     widget = self.parent()
     if self._itemTuple is not None:
         if self._shouldPrepareUndo:
             self._glyph.prepareUndo()
             self._shouldPrepareUndo = False
         modifiers = event.modifiers()
         # Alt: move point along handles
         if modifiers & Qt.AltModifier and len(self._glyph.selection) == 1:
             item, parent = self._itemTuple
             if parent is not None:
                 x, y = canvasPos.x(), canvasPos.y()
                 didMove = self._moveOnCurveAlongHandles(parent, item, x, y)
                 if didMove:
                     return
         # Shift: clamp pos on axis
         elif modifiers & Qt.ShiftModifier:
             item, parent = self._itemTuple
             if parent is not None:
                 if item.segmentType is None:
                     onCurve = self._getOffCurveSiblingPoint(parent, item)
                     canvasPos = self.clampToOrigin(
                         canvasPos, QPointF(onCurve.x, onCurve.y))
         dx = canvasPos.x() - self._origin.x()
         dy = canvasPos.y() - self._origin.y()
         for anchor in self._glyph.anchors:
             if anchor.selected:
                 anchor.move((dx, dy))
         for contour in self._glyph:
             moveUISelection(contour, (dx, dy))
         for component in self._glyph.components:
             if component.selected:
                 component.move((dx, dy))
         self._origin = canvasPos
     else:
         self._rubberBandRect = QRectF(self._origin, canvasPos).normalized()
         items = widget.items(self._rubberBandRect)
         points = set(items["points"])
         if event.modifiers() & Qt.ControlModifier:
             points ^= self._oldSelection
         # TODO: fine-tune this more, maybe add optional args to items...
         if event.modifiers() & Qt.AltModifier:
             points = set(pt for pt in points if pt.segmentType)
         if points != self._glyph.selection:
             # TODO: doing this takes more time than by-contour
             # discrimination for large point count
             self._glyph.selection = points
     widget.update()
Exemple #5
0
 def keyPressEvent(self, event):
     key = event.key()
     if key == platformSpecific.deleteKey:
         glyph = self._glyph
         # TODO: prune
         glyph.prepareUndo()
         preserveShape = not event.modifiers() & Qt.ShiftModifier
         for anchor in glyph.anchors:
             if anchor.selected:
                 glyph.removeAnchor(anchor)
         for contour in reversed(glyph):
             removeUISelection(contour, preserveShape)
         for component in glyph.components:
             if component.selected:
                 glyph.removeComponent(component)
     elif key in arrowKeys:
         # TODO: prune
         self._glyph.prepareUndo()
         delta = self._moveForEvent(event)
         # TODO: seems weird that glyph.selection and selected don't incl.
         # anchors and components while glyph.move does... see what glyphs
         # does
         hadSelection = False
         for anchor in self._glyph.anchors:
             if anchor.selected:
                 anchor.move(delta)
                 hadSelection = True
         for contour in self._glyph:
             moveUISelection(contour, delta)
             # XXX: shouldn't have to recalc this
             if contour.selection:
                 hadSelection = True
         for component in self._glyph.components:
             if component.selected:
                 component.move(delta)
                 hadSelection = True
         if not hadSelection:
             event.ignore()
     elif key in navKeys:
         pack = self._getSelectedCandidatePoint()
         if pack is not None:
             point, contour = pack
             point.selected = False
             index = contour.index(point)
             offset = int(key == Qt.Key_Greater) or -1
             newPoint = contour.getPoint(index + offset)
             newPoint.selected = True
             contour.postNotification(
                 notification="Contour.SelectionChanged")