diff options
| author | Adrien Tétar | 2015-07-05 17:56:10 +0200 | 
|---|---|---|
| committer | Adrien Tétar | 2015-07-05 17:56:10 +0200 | 
| commit | 55274d114757f6913f697d8dddd74b64b78598b5 (patch) | |
| tree | 8d7184aa4ca154e33e7ea112ff80d8465a3d9785 /Lib/defconQt/glyphView.py | |
| parent | 3c71aa4cc8940b1c4212f7ef2a331b0c1719110e (diff) | |
| download | trufont-55274d114757f6913f697d8dddd74b64b78598b5.tar.bz2 | |
glyphView: implement undo/redo
The depth is unlimited for now.
Diffstat (limited to 'Lib/defconQt/glyphView.py')
| -rw-r--r-- | Lib/defconQt/glyphView.py | 36 | 
1 files changed, 28 insertions, 8 deletions
diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py index 3239ced..280f43f 100644 --- a/Lib/defconQt/glyphView.py +++ b/Lib/defconQt/glyphView.py @@ -447,6 +447,8 @@ class GlyphScene(QGraphicsScene):          self._integerPlane = True          self._cachedRuler = None          self._rulerObject = None +        self._dataForUndo = [] +        self._dataForRedo = []          font = self.font()          font.setFamily("Roboto Mono") @@ -509,7 +511,23 @@ class GlyphScene(QGraphicsScene):                      self.removeItem(item)              event.accept()              return -        elif modifiers & Qt.ControlModifier and key == Qt.Key_A: +        elif event.matches(QKeySequence.Undo): +            if len(self._dataForUndo) > 0: +                undo = self._dataForUndo.pop() +                redo = self._glyphObject.getDataToSerializeForUndo() +                self._glyphObject.loadDeserializedDataFromUndo(undo) +                self._dataForRedo.append(redo) +            event.accept() +            return +        elif event.matches(QKeySequence.Redo): +            if len(self._dataForRedo) > 0: +                undo = self._glyphObject.getDataToSerializeForUndo() +                redo = self._dataForRedo.pop() +                self._dataForUndo.append(undo) +                self._glyphObject.loadDeserializedDataFromUndo(redo) +            event.accept() +            return +        elif event.matches(QKeySequence.SelectAll):              path = QPainterPath()              path.addRect(self.sceneRect())              view = self.views()[0] @@ -548,16 +566,18 @@ class GlyphScene(QGraphicsScene):          super(GlyphScene, self).keyReleaseEvent(event)      def mousePressEvent(self, event): -        currentTool = self.views()[0]._currentTool          view = self.views()[0]          touched = self.itemAt(event.scenePos(), view.transform()) -        if not currentTool == SceneTools.DrawingTool: -            if currentTool == SceneTools.RulerTool: -                self.rulerMousePress(event) -                return -            self._itemUnderMouse = touched -            super(GlyphScene, self).mousePressEvent(event) +        if view._currentTool == SceneTools.RulerTool: +            self.rulerMousePress(event)              return +        else: +            data = self._glyphObject.getDataToSerializeForUndo() +            self._dataForUndo.append(data) +            self._dataForRedo = [] +            if not view._currentTool == SceneTools.DrawingTool: +                super(GlyphScene, self).mousePressEvent(event) +                return          forceSelect = False          sel = self.selectedItems()          x, y = event.scenePos().x(), event.scenePos().y()  | 
