From d91d60aed23b5ebb1acde2189f1cbb29decdc312 Mon Sep 17 00:00:00 2001 From: blacksun Date: Sun, 9 Jun 2013 19:09:27 +0000 Subject: [PATCH] start work to define if conductor text item was moved by user or not git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2229 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/conductor.cpp | 8 ++++++-- sources/conductortextitem.cpp | 25 +++++++++++++++++++++++++ sources/conductortextitem.h | 3 +++ sources/diagramcommands.cpp | 17 ++++++++++++++++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/sources/conductor.cpp b/sources/conductor.cpp index e8fd1ba93..58f2de263 100644 --- a/sources/conductor.cpp +++ b/sources/conductor.cpp @@ -1113,6 +1113,7 @@ ConductorSegment *Conductor::middleSegment() { 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 @@ void Conductor::calculateTextItemPosition() { } 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); + } } } diff --git a/sources/conductortextitem.cpp b/sources/conductortextitem.cpp index 96e112feb..20241cb26 100644 --- a/sources/conductortextitem.cpp +++ b/sources/conductortextitem.cpp @@ -28,6 +28,7 @@ ConductorTextItem::ConductorTextItem(Conductor *parent_conductor, Diagram *paren 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 @@ ConductorTextItem::ConductorTextItem(const QString &text, Conductor *parent_cond 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 @@ -107,6 +109,14 @@ bool ConductorTextItem::wasMovedByUser() const { return(moved_by_user_); } +/** + * @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 @@ -122,6 +132,21 @@ void ConductorTextItem::forceMovedByUser(bool moved_by_user) { } +/** + * @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 diff --git a/sources/conductortextitem.h b/sources/conductortextitem.h index 7d027f9d0..34dac6702 100644 --- a/sources/conductortextitem.h +++ b/sources/conductortextitem.h @@ -48,7 +48,9 @@ class ConductorTextItem : public DiagramTextItem { 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 @@ class ConductorTextItem : public DiagramTextItem { private: Conductor *parent_conductor_; bool moved_by_user_; + bool rotate_by_user_; QPointF before_mov_pos_; bool first_move_; QPointF mouse_to_origin_movement_; diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index c0ff53741..acba4aaf7 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -601,7 +601,18 @@ void RotateElementsCommand::undo() { 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(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 @@ void RotateElementsCommand::redo() { rotateElement(e, e -> orientation().next()); } foreach(DiagramTextItem *dti, texts_to_rotate) { + if (ConductorTextItem *cti = qgraphicsitem_cast(dti)) { + previous_rotate_by_user_ = cti -> wasRotateByUser(); + cti -> forceRotateByUser(true); + } dti -> rotateBy(applied_rotation_angle_); } }