[qet] [2440] move image have now an undo/redo command

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2440
Author:   blacksun
Date:     2013-08-20 16:54:12 +0200 (Tue, 20 Aug 2013)
Log Message:
-----------
move image have now an undo/redo command

Modified Paths:
--------------
    branches/0.4/sources/diagramcommands.cpp
    branches/0.4/sources/diagramimageitem.cpp
    branches/0.4/sources/diagramimageitem.h
    branches/0.4/sources/elementsmover.cpp

Modified: branches/0.4/sources/diagramcommands.cpp
===================================================================
--- branches/0.4/sources/diagramcommands.cpp	2013-08-19 21:24:50 UTC (rev 2439)
+++ branches/0.4/sources/diagramcommands.cpp	2013-08-20 14:54:12 UTC (rev 2440)
@@ -352,7 +352,8 @@
 		DiagramContent::Elements |
 		DiagramContent::TextFields |
 		DiagramContent::ConductorsToUpdate |
-		DiagramContent::ConductorsToMove
+		DiagramContent::ConductorsToMove |
+		DiagramContent::Images
 	);
 	
 	setText(
@@ -413,6 +414,11 @@
 	foreach(DiagramTextItem *text, content_to_move.textFields) {
 		text -> setPos(text -> pos() + actual_movement);
 	}
+
+	// deplace les images
+	foreach (DiagramImageItem *dii, content_to_move.images) {
+		dii -> setPos(dii -> pos() + actual_movement);
+	}
 }
 
 /**

Modified: branches/0.4/sources/diagramimageitem.cpp
===================================================================
--- branches/0.4/sources/diagramimageitem.cpp	2013-08-19 21:24:50 UTC (rev 2439)
+++ branches/0.4/sources/diagramimageitem.cpp	2013-08-20 14:54:12 UTC (rev 2440)
@@ -38,7 +38,8 @@
  */
 DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, Diagram *parent_diagram) :
 	QGraphicsPixmapItem(pixmap, 0, parent_diagram),
-	rotation_angle_(0.0)
+	rotation_angle_(0.0),
+	first_move_(false)
 {
 	setCursor(Qt::PointingHandCursor);
 	setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
@@ -216,7 +217,11 @@
 	@param e Objet decrivant l'evenement souris
 */
 void DiagramImageItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
-	//todo
+	first_move_ = true;
+	if (e -> modifiers() & Qt::ControlModifier) {
+		setSelected(!isSelected());
+	}
+	QGraphicsItem::mousePressEvent(e);
 }
 
 /**
@@ -236,6 +241,53 @@
 }
 
 /**
+ * @brief DiagramImageItem::mouseMoveEvent
+ * Gere les mouvements de souris lies a l'image
+ * @param e Objet decrivant l'evenement souris
+ */
+void DiagramImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
+	if (isSelected() && e -> buttons() & Qt::LeftButton) {
+		//Image is moving
+		if(diagram()) {
+			if (first_move_) {
+				//It's the first movement, we signal it to parent diagram
+				diagram() -> beginMoveElements(this);
+			}
+		}
+
+		//we apply the mouse movement
+		QPointF old_pos = pos();
+		setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton)));
+		//we calcul the real movement apply by setPos()
+		QPointF effective_movement = pos() - old_pos;
+
+		if (diagram()) {
+			//we signal the real movement apply to diagram,
+			//who he apply to other selected item
+			diagram() -> continueMoveElements(effective_movement);
+		}
+	} else e -> ignore();
+
+	if (first_move_) first_move_ = false;
+}
+
+/**
+ * @brief DiagramImageItem::mouseReleaseEvent
+ * 	Gere le relachement de souris
+ *  Cette methode a ete reimplementee pour tenir a jour la liste
+ *  des images à deplacer au niveau du schema.
+ * @param e Objet decrivant l'evenement souris
+ */
+void DiagramImageItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
+	if (diagram()) {
+		diagram() -> endMoveElements();
+	}
+	if (!(e -> modifiers() & Qt::ControlModifier)) {
+		QGraphicsItem::mouseReleaseEvent(e);
+	}
+}
+
+/**
 	Effectue la rotation du image en elle-meme
 	Pour les DiagramImageItem, la rotation s'effectue autour du point (0, 0).
 	Cette methode peut toutefois etre redefinie dans des classes filles

Modified: branches/0.4/sources/diagramimageitem.h
===================================================================
--- branches/0.4/sources/diagramimageitem.h	2013-08-19 21:24:50 UTC (rev 2439)
+++ branches/0.4/sources/diagramimageitem.h	2013-08-20 14:54:12 UTC (rev 2440)
@@ -61,12 +61,14 @@
 	QPointF mapMovementToParent(const QPointF &) const;
 	QPointF mapMovementFromParent(const QPointF &) const;
 	
-	private:
+	protected:
 	void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
 	void focusInEvent(QFocusEvent *);
 	void focusOutEvent(QFocusEvent *);
 	void mousePressEvent(QGraphicsSceneMouseEvent *e);
 	void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
+	void mouseMoveEvent(QGraphicsSceneMouseEvent *);
+	void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
 	void applyRotation(const qreal &);
 	
 	signals:
@@ -81,5 +83,6 @@
 	private:
 	/// angle of rotation of the text field
 	qreal rotation_angle_;
+	bool first_move_;
 };
 #endif

Modified: branches/0.4/sources/elementsmover.cpp
===================================================================
--- branches/0.4/sources/elementsmover.cpp	2013-08-19 21:24:50 UTC (rev 2439)
+++ branches/0.4/sources/elementsmover.cpp	2013-08-20 14:54:12 UTC (rev 2440)
@@ -22,6 +22,7 @@
 #include "diagramcommands.h"
 #include "element.h"
 #include "independenttextitem.h"
+#include "diagramimageitem.h"
 
 /**
 	Constructeur
@@ -138,6 +139,13 @@
 		if (movement_driver_ && text_field == movement_driver_) continue;
 		text_field -> setPos(text_field -> pos() + movement);
 	}
+
+	//deplace les images
+	foreach(DiagramImageItem *dii, moved_content_.images) {
+		if (movement_driver_ && dii == movement_driver_) continue;
+		dii -> setPos(dii -> pos() + movement);
+	}
+
 }
 
 /**


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/