[qet] [2229] start work to define if conductor text item was moved by user or not

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


Revision: 2229
Author:   blacksun
Date:     2013-06-09 21:09:27 +0200 (Sun, 09 Jun 2013)
Log Message:
-----------
start work to define if conductor text item was moved by user or not 

Modified Paths:
--------------
    trunk/sources/conductor.cpp
    trunk/sources/conductortextitem.cpp
    trunk/sources/conductortextitem.h
    trunk/sources/diagramcommands.cpp

Modified: trunk/sources/conductor.cpp
===================================================================
--- trunk/sources/conductor.cpp	2013-06-09 17:40:41 UTC (rev 2228)
+++ trunk/sources/conductor.cpp	2013-06-09 19:09:27 UTC (rev 2229)
@@ -1113,6 +1113,7 @@
 void Conductor::calculateTextItemPosition() {
 	if (!text_item) return;
 	
+	//position
 	if (text_item -> wasMovedByUser()) {
 		// le champ de texte a ete deplace par l'utilisateur :
 		// on verifie qu'il est encore a proximite du conducteur
@@ -1124,8 +1125,11 @@
 	} else {
 		// positionnement automatique basique
 		text_item -> setPos(middleSegment() -> middle());
-		middleSegment() -> isVertical()? text_item -> setRotationAngle(properties_.verti_rotate_text):
-										 text_item -> setRotationAngle(properties_.horiz_rotate_text);
+		//rotation
+		if (!text_item -> wasRotateByUser()) {
+			middleSegment() -> isVertical()? text_item -> setRotationAngle(properties_.verti_rotate_text):
+											 text_item -> setRotationAngle(properties_.horiz_rotate_text);
+		}
 	}
 }
 

Modified: trunk/sources/conductortextitem.cpp
===================================================================
--- trunk/sources/conductortextitem.cpp	2013-06-09 17:40:41 UTC (rev 2228)
+++ trunk/sources/conductortextitem.cpp	2013-06-09 19:09:27 UTC (rev 2229)
@@ -28,6 +28,7 @@
 	DiagramTextItem(parent_conductor, parent_diagram),
 	parent_conductor_(parent_conductor),
 	moved_by_user_(false),
+	rotate_by_user_(false),
 	first_move_(true)
 {
 	// par defaut, les DiagramTextItem sont Selectable et Movable
@@ -44,6 +45,7 @@
 	DiagramTextItem(text, parent_conductor, parent_diagram),
 	parent_conductor_(parent_conductor),
 	moved_by_user_(false),
+	rotate_by_user_(false),
 	first_move_(true)
 {
 	// par defaut, les DiagramTextItem sont Selectable et Movable
@@ -108,6 +110,14 @@
 }
 
 /**
+ * @brief ConductorTextItem::wasRotateByUser
+ * @return true if text was explicit moved by user else false
+ */
+bool ConductorTextItem::wasRotateByUser() const {
+	return(rotate_by_user_);
+}
+
+/**
 	@param moved_by_user true pour que la position du texte soit consideree
 	comme ayant ete definie par l'utilisateur (et donc soit sauvegardee), false
 	pour remettre le texte a sa position originelle
@@ -123,6 +133,21 @@
 }
 
 /**
+ * @brief ConductorTextItem::forceRotateByUser
+ * @param rotate_by_user true pour que la rotation du texte soit consideree
+	comme ayant ete definie par l'utilisateur (et donc soit sauvegardee), false
+	pour remettre le texte a sont angle originelle
+ */
+void ConductorTextItem::forceRotateByUser(bool rotate_by_user) {
+	if (rotate_by_user == rotate_by_user_) return;
+
+	rotate_by_user_ = rotate_by_user;
+	if (!rotate_by_user && parent_conductor_) {
+		parent_conductor_ -> adjustTextItemPosition();
+	}
+}
+
+/**
 	Gere les clics de souris lies au champ de texte
 	@param e Objet decrivant l'evenement souris
 */

Modified: trunk/sources/conductortextitem.h
===================================================================
--- trunk/sources/conductortextitem.h	2013-06-09 17:40:41 UTC (rev 2228)
+++ trunk/sources/conductortextitem.h	2013-06-09 19:09:27 UTC (rev 2229)
@@ -48,7 +48,9 @@
 	public:
 	virtual int type() const { return Type; }
 	virtual bool wasMovedByUser() const;
+	virtual bool wasRotateByUser() const;
 	virtual void forceMovedByUser(bool);
+	virtual void forceRotateByUser(bool);
 	
 	protected:
 	virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
@@ -59,6 +61,7 @@
 	private:
 	Conductor *parent_conductor_;
 	bool moved_by_user_;
+	bool rotate_by_user_;
 	QPointF before_mov_pos_;
 	bool first_move_;
 	QPointF mouse_to_origin_movement_;

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2013-06-09 17:40:41 UTC (rev 2228)
+++ trunk/sources/diagramcommands.cpp	2013-06-09 19:09:27 UTC (rev 2229)
@@ -601,7 +601,18 @@
 		rotateElement(e, elements_to_rotate[e]);
 	}
 	foreach(DiagramTextItem *dti, texts_to_rotate) {
-		dti -> rotateBy(-applied_rotation_angle_);
+		//ConductorTextItem have got a default rotation propertie
+		//so we apply specific undo method for him
+		if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
+			cti -> forceRotateByUser(previous_rotate_by_user_);
+			//previous_rotate_by_user is false mean the rotation is propertie rotation
+			if (previous_rotate_by_user_ == false) {cti -> parentConductor() ->adjustTextItemPosition();}
+			else {cti -> rotateBy(-applied_rotation_angle_);}
+		}
+		//this isn't a ConductorTextItem
+		else {
+			dti -> rotateBy(-applied_rotation_angle_);
+		}
 	}
 }
 
@@ -611,6 +622,10 @@
 		rotateElement(e, e -> orientation().next());
 	}
 	foreach(DiagramTextItem *dti, texts_to_rotate) {
+		if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
+			previous_rotate_by_user_ = cti -> wasRotateByUser();
+			cti -> forceRotateByUser(true);
+		}
 		dti -> rotateBy(applied_rotation_angle_);
 	}
 }


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