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

Adam Treat treat at kde.org
Fri Jun 8 19:42:51 CEST 2007


SVN commit 672992 by treat:

* Compress ResizeCommands and debuggify them


 M  +6 -12     view.cpp  
 M  +1 -1      view.h  
 M  +17 -15    viewitem.cpp  
 M  +8 -7      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #672991:672992
@@ -61,7 +61,11 @@
 
 void View::setMouseMode(MouseMode mode) {
 
-  if (_mouseMode == Create) {
+  //Clear the creation polygons if we're currently
+  //in Create mode.
+  MouseMode oldMode = _mouseMode;
+
+  if (oldMode == Create) {
     _creationPolygonPress.clear();
     _creationPolygonRelease.clear();
     _creationPolygonMove.clear();
@@ -76,21 +80,11 @@
     setDragMode(QGraphicsView::NoDrag);
   }
 
-  emit mouseModeChanged();
+  emit mouseModeChanged(oldMode);
 }
 
 
 QPolygonF View::creationPolygon(CreationEvents events) const {
-#if 0
-  QPolygonF resultSet;
-  if (events & View::MousePress)
-    resultSet = resultSet.united(_creationPolygonPress);
-  if (events & View::MouseRelease)
-    resultSet = resultSet.united(_creationPolygonRelease);
-  if (events & View::MouseMove)
-    resultSet = resultSet.united(_creationPolygonMove);
-  return resultSet;
-#endif
   if (events == View::MousePress)
      return _creationPolygonPress;
   if (events == View::MouseRelease)
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #672991:672992
@@ -44,7 +44,7 @@
   QPolygonF creationPolygon(CreationEvents events) const;
 
 Q_SIGNALS:
-  void mouseModeChanged();
+  void mouseModeChanged(View::MouseMode oldMode);
   void creationPolygonChanged(View::CreationEvent event);
 
 protected:
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #672991:672992
@@ -24,7 +24,8 @@
   : QObject(parent) {
   setAcceptsHoverEvents(true);
   setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
-  connect(parent, SIGNAL(mouseModeChanged()), this, SLOT(viewMouseModeChanged()));
+  connect(parent, SIGNAL(mouseModeChanged(View::MouseMode)),
+          this, SLOT(viewMouseModeChanged(View::MouseMode)));
 }
 
 
@@ -148,8 +149,7 @@
       } else {
         transformed.setBottomRight(event->pos());
       }
-      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
-      resize->redo();
+      transformToRect(transformed, true);
       return;
     }
   case Qt::SizeBDiagCursor:
@@ -160,8 +160,7 @@
       } else {
         transformed.setTopRight(event->pos());
       }
-      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
-      resize->redo();
+      transformToRect(transformed, true);
       return;
     }
   case Qt::SizeVerCursor:
@@ -172,8 +171,7 @@
       } else {
         transformed.setBottom(event->pos().y());
       }
-      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
-      resize->redo();
+      transformToRect(transformed, true);
       return;
     }
   case Qt::SizeHorCursor:
@@ -184,8 +182,7 @@
       } else {
         transformed.setRight(event->pos().x());
       }
-      ResizeCommand *resize = new ResizeCommand(this, rect(), transformed);
-      resize->redo();
+      transformToRect(transformed, true);
       return;
     }
   case Qt::ArrowCursor:
@@ -302,11 +299,16 @@
 }
 
 
-void ViewItem::viewMouseModeChanged() {
-  if (parentView()->mouseMode() == View::Move)
+void ViewItem::viewMouseModeChanged(View::MouseMode oldMode) {
+  if (parentView()->mouseMode() == View::Move) {
     _originalPosition = pos();
-  else if (_originalPosition != pos())
+  } else if (parentView()->mouseMode() == View::Resize) {
+    _originalTransform = transform();
+  } else if (oldMode == View::Move) {
     new MoveCommand(this, _originalPosition, pos());
+  } else if (oldMode == View::Resize) {
+    new ResizeCommand(this, _originalTransform, transform());
+  }
 }
 
 
@@ -363,7 +365,7 @@
 
   //If the mouseMode is changed again before we're done with creation
   //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
+  connect(_view, SIGNAL(mouseModeChanged(View::MouseMode)), _item, SLOT(deleteLater()));
   connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
           _item, SLOT(creationPolygonChanged(View::CreationEvent)));
   connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
@@ -421,12 +423,12 @@
 void ResizeCommand::undo() {
   /*FIXME Not combining this transform with previous ... undoes to much.
    * OTOH, combining it means we don't really undo...*/
-  _item->transformToRect(_originalRect);
+  _item->setTransform(_originalTransform);
 }
 
 
 void ResizeCommand::redo() {
-  _item->transformToRect(_newRect, true);
+  _item->setTransform(_newTransform);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #672991:672992
@@ -59,11 +59,12 @@
   virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
 
 private Q_SLOTS:
-  void viewMouseModeChanged();
+  void viewMouseModeChanged(View::MouseMode oldMode);
 
 private:
   MouseMode _mouseMode;
   QPointF _originalPosition;
+  QTransform _originalTransform;
 };
 
 class KST_EXPORT ViewItemCommand : public QUndoCommand
@@ -164,13 +165,13 @@
 class KST_EXPORT ResizeCommand : public ViewItemCommand
 {
 public:
-  ResizeCommand(const QRectF &originalRect, const QRectF &newRect)
+  ResizeCommand(const QTransform &originalTransform, const QTransform &newTransform)
       : ViewItemCommand(QObject::tr("Resize")),
-        _originalRect(originalRect), _newRect(newRect) {}
+        _originalTransform(originalTransform), _newTransform(newTransform) {}
 
-  ResizeCommand(ViewItem *item, const QRectF &originalRect, const QRectF &newRect)
+  ResizeCommand(ViewItem *item, const QTransform &originalTransform, const QTransform &newTransform)
       : ViewItemCommand(item, QObject::tr("Resize")),
-        _originalRect(originalRect), _newRect(newRect) {}
+        _originalTransform(originalTransform), _newTransform(newTransform) {}
 
   virtual ~ResizeCommand() {}
 
@@ -178,8 +179,8 @@
   virtual void redo();
 
 private:
-  QRectF _originalRect;
-  QRectF _newRect;
+  QTransform _originalTransform;
+  QTransform _newTransform;
 };
 
 }


More information about the Kst mailing list