Beispiel #1
0
 def keyPressEvent(self, event):
     key = event.key()
     # XXX: this shouldn't be tool-specific!
     if key in arrowKeys:
         dx, dy = self._moveForEvent(event)
         modifiers = event.modifiers()
         slidePoints = modifiers & Qt.AltModifier
         moveUIGlyphElements(self._glyph, dx, dy, slidePoints=slidePoints)
     # TODO: nav shouldn't be specific to this tool
     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")
     elif key == Qt.Key_Return:
         self._glyph.beginUndoGroup()
         for contour in self._glyph:
             for index, point in enumerate(contour):
                 changed = False
                 if point.segmentType is not None and point.selected:
                     if all(
                             contour.getPoint(index + d).segmentType
                             for d in (-1, 1)):
                         continue
                     point.smooth = not point.smooth
                     changed = True
                 if changed:
                     contour.dirty = True
         self._glyph.endUndoGroup()
Beispiel #2
0
 def keyPressEvent(self, event):
     key = event.key()
     if platformSpecific.isDeleteEvent(event):
         glyph = self._glyph
         # TODO: fuse more the two methods, they're similar and delete is
         # Cut except not putting in the clipboard
         if event.modifiers() & Qt.AltModifier:
             deleteUISelection(glyph)
         else:
             preserveShape = not event.modifiers() & Qt.ShiftModifier
             # TODO: prune
             glyph.prepareUndo()
             removeUIGlyphElements(glyph, preserveShape)
     elif key in arrowKeys:
         # TODO: prune
         self._glyph.prepareUndo()
         dx, dy = 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
         moveUIGlyphElements(self._glyph, dx, dy)
     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")
Beispiel #3
0
 def mouseMoveEvent(self, event):
     if not event.buttons() & Qt.LeftButton:
         super().mouseMoveEvent(event)
         return
     if self._origin is None:
         return
     glyph = self._glyph
     widget = self.parent()
     if self._shouldMove or self._mouseItem is not None:
         canvasPos = event.pos()
         modifiers = event.modifiers()
         if modifiers & Qt.ShiftModifier:
             # we clamp to the mouseDownPos, unless we have a
             # single offCurve in which case we clamp it against
             # its parent
             canvasPos = self.clampToOrigin(canvasPos, self._origin)
             if isinstance(self._mouseItem, tuple):
                 selection = glyph.selection
                 if len(selection) == 1:
                     c, i = self._mouseItem
                     p_ = c[i]
                     if p_.segmentType is None:
                         for d in (-1, 1):
                             p__ = c.getPoint(i + d)
                             if p__.segmentType is not None:
                                 canvasPos = self.clampToOrigin(
                                     canvasPos, QPointF(p__.x, p__.y))
                                 p_.x = canvasPos.x()
                                 p_.y = canvasPos.y()
                                 c.dirty = True
                                 return
         dx = canvasPos.x() - self._prevPos.x()
         dy = canvasPos.y() - self._prevPos.y()
         kwargs = dict()
         if modifiers == platformSpecific.combinedModifiers():
             kwargs["nudgePoints"] = True
         elif modifiers & Qt.AltModifier:
             kwargs["slidePoints"] = True
         moveUIGlyphElements(glyph, dx, dy, **kwargs)
         self._prevPos = canvasPos
     else:
         canvasPos = event.localPos()
         self._rubberBandRect = QRectF(self._origin, canvasPos).normalized()
         items = widget.items(self._rubberBandRect)
         points = set(c[i] for c, i in 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
             glyph.selection = points
     widget.update()
Beispiel #4
0
 def mouseMoveEvent(self, event):
     glyph = self._glyph
     widget = self.parent()
     if self._shouldMove or self._itemTuple is not None:
         canvasPos = event.pos()
         if self._shouldPrepareUndo:
             self._glyph.prepareUndo()
             self._shouldPrepareUndo = False
         modifiers = event.modifiers()
         if self._itemTuple is not None:
             # Alt: move point along handles
             if modifiers & Qt.AltModifier and len(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))
                         else:
                             canvasPos = self.clampToOrigin(
                                 canvasPos, self._origin)
         dx = canvasPos.x() - self._prevPos.x()
         dy = canvasPos.y() - self._prevPos.y()
         moveUIGlyphElements(glyph, dx, dy)
         self._prevPos = canvasPos
     else:
         canvasPos = event.localPos()
         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
             glyph.selection = points
     widget.update()