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

Adam Treat treat at kde.org
Wed May 30 09:52:44 CEST 2007


SVN commit 669732 by treat:

* Probably a better way, but this works for now


 M  +12 -10    labelitem.cpp  
 M  +5 -1      labelitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #669731:669732
@@ -37,19 +37,21 @@
 }
 
 
-QVariant LabelItem::itemChange(GraphicsItemChange change, const QVariant &value) {
-  if (change == ItemPositionChange && scene()) {
-    QPointF originalPos = pos();
-    QPointF newPos = value.toPointF();
-    // FIXME this is too greedy as it produces too many undo commands.
-    // Ideally, we'd only record the move from right before the item
-    // becomes the mouse grabber to right after.
-    new MoveCommand(this, originalPos, newPos);
-  }
-  return QGraphicsItem::itemChange(change, value);
+void LabelItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+  QGraphicsSimpleTextItem::mousePressEvent(event);
+  _originalPos = pos();
 }
 
 
+void LabelItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
+  QGraphicsSimpleTextItem::mouseReleaseEvent(event);
+
+  QPointF newPos = pos();
+  if (_originalPos != newPos)
+    new MoveCommand(this, _originalPos, newPos);
+}
+
+
 void LabelItem::creationPolygonChanged(View::CreationEvent event) {
   if (event == View::MousePress) {
 
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.h #669731:669732
@@ -27,10 +27,14 @@
   virtual QGraphicsItem *graphicsItem() { return this; }
 
 protected:
-  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+  void mousePressEvent(QGraphicsSceneMouseEvent *event);
+  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 
 private Q_SLOTS:
   void creationPolygonChanged(View::CreationEvent event);
+
+private:
+  QPointF _originalPos;
 };
 
 


More information about the Kst mailing list