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

Adam Treat treat at kde.org
Thu Jun 7 19:56:27 CEST 2007


SVN commit 672625 by treat:

* Consolidate and refactor some of this


 M  +2 -10     boxitem.cpp  
 M  +1 -10     ellipseitem.cpp  
 M  +1 -11     labelitem.cpp  
 M  +2 -10     lineitem.cpp  
 M  +1 -10     pictureitem.cpp  
 M  +1 -10     plotitem.cpp  
 M  +1 -10     svgitem.cpp  
 M  +32 -0     viewitem.cpp  
 M  +6 -3      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/boxitem.cpp #672624:672625
@@ -29,17 +29,9 @@
 
 void CreateBoxCommand::createItem() {
   _item = new BoxItem(_view);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+
+  CreateCommand::createItem();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #672624:672625
@@ -38,18 +38,9 @@
 
 void CreateEllipseCommand::createItem() {
   _item = new EllipseItem(_view);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
 
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+  CreateCommand::createItem();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #672624:672625
@@ -69,19 +69,9 @@
   }
 
   _item = new LabelItem(_view, text);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::IBeamCursor);
 
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
-
+  CreateCommand::createItem();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #672624:672625
@@ -74,17 +74,9 @@
 
 void CreateLineCommand::createItem() {
   _item = new LineItem(_view);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+
+  CreateCommand::createItem();
 }
 
 LineItemFactory::LineItemFactory()
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #672624:672625
@@ -47,18 +47,9 @@
     return;
 
   _item = new PictureItem(_view, QImage(file));
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
 
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+  CreateCommand::createItem();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #672624:672625
@@ -29,18 +29,9 @@
 
 void CreatePlotCommand::createItem() {
   _item = new PlotItem(_view);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
 
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+  CreateCommand::createItem();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.cpp #672624:672625
@@ -47,18 +47,9 @@
     return;
 
   _item = new SvgItem(_view, file);
-  _view->setMouseMode(View::Create);
   _view->setCursor(Qt::CrossCursor);
 
-  //If the mouseMode is changed again before we're done with creation
-  //delete ourself.
-  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
-  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
-          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
-  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
-  //If the item is interrupted while creating itself it will destroy itself
-  //need to delete this too in response...
-  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+  CreateCommand::createItem();
 }
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #672624:672625
@@ -107,6 +107,21 @@
 }
 
 
+void ViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+  QGraphicsRectItem::mouseMoveEvent(event);
+}
+
+
+void ViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+  QGraphicsRectItem::mousePressEvent(event);
+}
+
+
+void ViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
+  QGraphicsRectItem::mouseReleaseEvent(event);
+}
+
+
 void ViewItem::mouseModeChanged() {
   if (parentView()->mouseMode() == View::Move)
     _originalPosition = pos();
@@ -161,6 +176,23 @@
 }
 
 
+void CreateCommand::createItem() {
+  Q_ASSERT(_item);
+
+  _view->setMouseMode(View::Create);
+
+  //If the mouseMode is changed again before we're done with creation
+  //delete ourself.
+  connect(_view, SIGNAL(mouseModeChanged()), _item, SLOT(deleteLater()));
+  connect(_view, SIGNAL(creationPolygonChanged(View::CreationEvent)),
+          _item, SLOT(creationPolygonChanged(View::CreationEvent)));
+  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
+  //If the item is interrupted while creating itself it will destroy itself
+  //need to delete this too in response...
+  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+}
+
+
 void CreateCommand::creationComplete() {
   _view->undoStack()->push(this);
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #672624:672625
@@ -45,6 +45,9 @@
 
 protected:
   virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 
 private Q_SLOTS:
   void mouseModeChanged();
@@ -75,7 +78,7 @@
 
   virtual void undo();
   virtual void redo();
-  virtual void createItem() = 0;
+  virtual void createItem();
 
 public Q_SLOTS:
   void creationComplete();
@@ -88,11 +91,11 @@
 {
 public:
   MoveCommand(QPointF originalPos, QPointF newPos)
-      : ViewItemCommand(QObject::tr("Move Item")),
+      : ViewItemCommand(QObject::tr("Move")),
         _originalPos(originalPos),
         _newPos(newPos) {}
   MoveCommand(ViewItem *item, QPointF originalPos, QPointF newPos)
-      : ViewItemCommand(item, QObject::tr("Move Item")),
+      : ViewItemCommand(item, QObject::tr("Move")),
         _originalPos(originalPos),
         _newPos(newPos) {}
 


More information about the Kst mailing list