[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Fri Jun 8 00:21:03 CEST 2007


SVN commit 672713 by treat:

* This still isn't right, but resizing will
also become an undo/redo command


 M  +4 -1      view.cpp  
 M  +19 -5     viewitem.cpp  
 M  +21 -0     viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #672712:672713
@@ -19,6 +19,7 @@
 #include <QUndoStack>
 #include <QResizeEvent>
 #include <QGLWidget>
+#include <QGraphicsItem>
 #include <QGraphicsScene>
 #include <QGraphicsSceneMouseEvent>
 
@@ -134,7 +135,9 @@
         QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
         _creationPolygonMove << e->scenePos();
         emit creationPolygonChanged(MouseMove);
-      } else if (_mouseMode == Default && scene()->mouseGrabberItem()) {
+      } else if (_mouseMode == Default && scene()->mouseGrabberItem() &&
+                 /*FIXME not a good way to detect resize mode*/
+                 scene()->mouseGrabberItem()->cursor().shape() == Qt::ArrowCursor) {
         setMouseMode(Move);
         _undoStack->beginMacro(tr("Move"));
       }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #672712:672713
@@ -129,7 +129,8 @@
         transformed.setBottomRight(event->pos());
       }
 /*      setRect(transformed);*/
-      transformToRect(transformed);
+      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
+      resize->redo();
       return;
     }
   case Qt::SizeBDiagCursor:
@@ -141,7 +142,8 @@
         transformed.setTopRight(event->pos());
       }
 /*      setRect(transformed);*/
-      transformToRect(transformed);
+      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
+      resize->redo();
       return;
     }
   case Qt::SizeVerCursor:
@@ -153,7 +155,8 @@
         transformed.setBottom(event->pos().y());
       }
 /*      setRect(transformed);*/
-      transformToRect(transformed);
+      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
+      resize->redo();
       return;
     }
   case Qt::SizeHorCursor:
@@ -165,8 +168,8 @@
         transformed.setRight(event->pos().x());
       }
 /*      setRect(transformed);*/
-      transformToRect(transformed);
-
+      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
+      resize->redo();
       return;
     }
   case Qt::ArrowCursor:
@@ -380,8 +383,19 @@
   _item->setZValue(_item->zValue() - 1);
 }
 
+
+void ResizeCommand::undo() {
+  _item->transformToRect(_originalRect);
 }
 
+
+void ResizeCommand::redo() {
+  _item->transformToRect(_newRect);
+}
+
+
+}
+
 #include "viewitem.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #672712:672713
@@ -155,6 +155,27 @@
   virtual void redo();
 };
 
+class KST_EXPORT ResizeCommand : public ViewItemCommand
+{
+public:
+  ResizeCommand(const QRectF &originalRect, const QRectF &newRect)
+      : ViewItemCommand(QObject::tr("Resize")),
+        _originalRect(originalRect), _newRect(newRect) {}
+
+  ResizeCommand(ViewItem *item, const QRectF &originalRect, const QRectF &newRect)
+      : ViewItemCommand(item, QObject::tr("Resize")),
+        _originalRect(originalRect), _newRect(newRect) {}
+
+  virtual ~ResizeCommand() {}
+
+  virtual void undo();
+  virtual void redo();
+
+private:
+  QRectF _originalRect;
+  QRectF _newRect;
+};
+
 }
 
 #endif


More information about the Kst mailing list