diff options
| author | Adrien Tétar | 2015-09-29 10:44:58 +0200 | 
|---|---|---|
| committer | Adrien Tétar | 2015-09-29 11:48:28 +0200 | 
| commit | 2675fa8275a60bdd613de40e5d61f9947b856152 (patch) | |
| tree | 65a367c80689f65043b079c5767a6e47875f11c6 /Lib/defconQt/glyphView.py | |
| parent | 6b4593337cd4626b5b780d2774013063f537e793 (diff) | |
| download | trufont-2675fa8275a60bdd613de40e5d61f9947b856152.tar.bz2 | |
fontView,glyphView: generalize copy/paste and use app-wide clipboard
Diffstat (limited to 'Lib/defconQt/glyphView.py')
| -rw-r--r-- | Lib/defconQt/glyphView.py | 29 | 
1 files changed, 19 insertions, 10 deletions
| diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index 8fd0f24..c85d43b 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -1,5 +1,6 @@  from enum import Enum  from math import copysign +import pickle  from defconQt.objects.defcon import TContour, TGlyph  from defconQt.pens.copySelectionPen import CopySelectionPen  from fontTools.misc import bezierTools @@ -326,7 +327,7 @@ class ComponentItem(QGraphicsPathItem):              y = value.y()              printf( "ItemPositionChange: X=%d Y=%d" % (x, y)) -             +      def setBounds(self, path):          bounds_path = QPainterPath()          region = path.boundingRegion(QTransform()).boundingRect().getCoords() @@ -340,7 +341,7 @@ class ComponentItem(QGraphicsPathItem):          pen.setColor(Qt.green)          self.setPen(pen)          super(ComponentItem, self).paint(painter, option, widget) -         +  class OnCurvePointItem(QGraphicsPathItem):      def __init__(self, x, y, isSmooth, contour, point, scale=1, parent=None): @@ -758,19 +759,27 @@ class GlyphScene(QGraphicsScene):              return          elif event.matches(QKeySequence.Copy):              clipboard = QApplication.clipboard() -            mimeData = clipboard.mimeData() +            mimeData = QMimeData()              pen = CopySelectionPen()              self._glyphObject.drawPoints(pen) -            # XXX: clipboard should outlive the widget window! -            self._clipboardObject = pen.getGlyph().serializeForUndo() +            copyGlyph = pen.getGlyph() +            # TODO: somehow try to do this in the pen +            # pass the glyph to a controller object that holds a self._pen +            copyGlyph.width = self._glyphObject.width +            mimeData.setData("application/x-defconQt-glyph-data", pickle.dumps([copyGlyph.serializeForUndo(False)])) +            clipboard.setMimeData(mimeData)              event.accept()              return          elif event.matches(QKeySequence.Paste): -            if self._clipboardObject is None: return -            pen = self._glyphObject.getPointPen() -            pasteGlyph = TGlyph() -            pasteGlyph.deserializeFromUndo(self._clipboardObject) -            pasteGlyph.drawPoints(pen) +            clipboard = QApplication.clipboard() +            mimeData = clipboard.mimeData() +            if mimeData.hasFormat("application/x-defconQt-glyph-data"): +                data = pickle.loads(mimeData.data("application/x-defconQt-glyph-data")) +                if len(data) == 1: +                    pen = self._glyphObject.getPointPen() +                    pasteGlyph = TGlyph() +                    pasteGlyph.deserializeFromUndo(data[0]) +                    pasteGlyph.drawPoints(pen)              event.accept()              return          else: | 
