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

Adam Treat treat at kde.org
Fri Aug 31 21:05:02 CEST 2007


SVN commit 707003 by treat:

* Sep out resize and scale in command pattern


 M  +13 -2     viewitem.cpp  
 M  +31 -8     viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #707002:707003
@@ -946,6 +946,7 @@
   } else if (parentView()->mouseMode() == View::Resize ||
              parentView()->mouseMode() == View::Scale ||
              parentView()->mouseMode() == View::Rotate) {
+    _originalRect = rect();
     _originalTransform = transform();
   } else if (oldMode == View::Move) {
 
@@ -953,9 +954,9 @@
 
     new MoveCommand(this, _originalPosition, pos());
   } else if (oldMode == View::Resize) {
-    new ResizeCommand(this, _originalTransform, transform());
+    new ResizeCommand(this, _originalRect, rect());
   } else if (oldMode == View::Scale) {
-    //new ScaleCommand(this, _originalTransform, transform());
+    new ScaleCommand(this, _originalTransform, transform());
   } else if (oldMode == View::Rotate) {
     new RotateCommand(this, _originalTransform, transform());
   }
@@ -1040,6 +1041,16 @@
 }
 
 
+void ResizeCommand::undo() {
+  _item->setViewRect(_originalRect);
+}
+
+
+void ResizeCommand::redo() {
+  _item->setViewRect(_newRect);
+}
+
+
 void RemoveCommand::undo() {
   _item->show();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #707002:707003
@@ -142,6 +142,7 @@
   bool _lockAspectRatio;
   ViewGridLayout *_layout;
   QPointF _originalPosition;
+  QRectF _originalRect;
   QTransform _originalTransform;
   QLineF _normalLine;
   QLineF _rotationLine;
@@ -183,11 +184,11 @@
 class KST_EXPORT MoveCommand : public ViewItemCommand
 {
 public:
-  MoveCommand(QPointF originalPos, QPointF newPos)
+  MoveCommand(const QPointF &originalPos, const QPointF &newPos)
       : ViewItemCommand(QObject::tr("Move")),
         _originalPos(originalPos),
         _newPos(newPos) {}
-  MoveCommand(ViewItem *item, QPointF originalPos, QPointF newPos)
+  MoveCommand(ViewItem *item, const QPointF &originalPos, const QPointF &newPos)
       : ViewItemCommand(item, QObject::tr("Move")),
         _originalPos(originalPos),
         _newPos(newPos) {}
@@ -202,6 +203,28 @@
   QPointF _newPos;
 };
 
+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;
+};
+
 class KST_EXPORT RemoveCommand : public ViewItemCommand
 {
 public:
@@ -266,16 +289,16 @@
   QTransform _newTransform;
 };
 
-class KST_EXPORT ResizeCommand : public TransformCommand
+class KST_EXPORT ScaleCommand : public TransformCommand
 {
 public:
-  ResizeCommand(const QTransform &originalTransform, const QTransform &newTransform)
-      : TransformCommand(originalTransform, newTransform, QObject::tr("Resize")) {}
+  ScaleCommand(const QTransform &originalTransform, const QTransform &newTransform)
+      : TransformCommand(originalTransform, newTransform, QObject::tr("Scale")) {}
 
-  ResizeCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
-      : TransformCommand(item, originalTransform, newTransform, QObject::tr("Resize")) {}
+  ScaleCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
+      : TransformCommand(item, originalTransform, newTransform, QObject::tr("Scale")) {}
 
-  virtual ~ResizeCommand() {}
+  virtual ~ScaleCommand() {}
 };
 
 class KST_EXPORT RotateCommand : public TransformCommand


More information about the Kst mailing list