[qet] [3202] move undo command: graphics item is animated when undo/redo ( testing) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3202
Author: blacksun
Date: 2014-07-09 18:50:30 +0200 (Wed, 09 Jul 2014)
Log Message:
-----------
move undo command: graphics item is animated when undo/redo (testing)
Modified Paths:
--------------
trunk/sources/diagramcommands.cpp
trunk/sources/diagramcommands.h
trunk/sources/qetgraphicsitem/conductor.h
Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp 2014-07-07 14:36:53 UTC (rev 3201)
+++ trunk/sources/diagramcommands.cpp 2014-07-09 16:50:30 UTC (rev 3202)
@@ -27,6 +27,7 @@
#include "qetgraphicsitem/diagramtextitem.h"
#include "qetgraphicsitem/diagramimageitem.h"
#include "conductorautonumerotation.h"
+#include <QPropertyAnimation>
/**
Constructeur
@@ -418,6 +419,7 @@
diagram(dia),
content_to_move(diagram_content),
movement(m),
+ m_anim_group(nullptr),
first_redo(true)
{
QString moved_content_sentence = content_to_move.sentence(
@@ -444,6 +446,7 @@
* Destructor
*/
MoveElementsCommand::~MoveElementsCommand() {
+ delete m_anim_group;
}
/**
@@ -451,7 +454,8 @@
*/
void MoveElementsCommand::undo() {
diagram -> showMe();
- move(-movement);
+ m_anim_group->setDirection(QAnimationGroup::Forward);
+ m_anim_group->start();
}
/**
@@ -459,8 +463,14 @@
*/
void MoveElementsCommand::redo() {
diagram -> showMe();
- if (first_redo) first_redo = false;
- else move(movement);
+ if (first_redo) {
+ first_redo = false;
+ move(-movement);
+ }
+ else {
+ m_anim_group->setDirection(QAnimationGroup::Backward);
+ m_anim_group->start();
+ }
}
/**
@@ -473,17 +483,20 @@
//Move every movable item, except conductor
foreach (QGraphicsItem *qgi, content_to_move.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes)) {
- qgi -> setPos(qgi->pos() + actual_movement);
+ if(qgi->toGraphicsObject()) {
+ setupAnimation(qgi->toGraphicsObject(), "pos", qgi->pos(), qgi->pos() + actual_movement);
+ }
+ else qgi -> setPos(qgi->pos() + actual_movement);
}
// Move some conductors
foreach(Conductor *conductor, content_to_move.conductorsToMove) {
- conductor -> setPos(conductor -> pos() + actual_movement);
+ setupAnimation(conductor, "pos", conductor->pos(), conductor->pos() + actual_movement);
}
// Recalcul the path of other conductor
foreach(Conductor *conductor, content_to_move.conductorsToUpdate) {
- conductor -> updatePath();
+ setupAnimation(conductor, "animPath", 1, 1);
}
}
@@ -504,6 +517,25 @@
}
/**
+ * @brief MoveElementsCommand::setupAnimation
+ * Set up the animation for this undo command
+ * @param target object to anim
+ * @param propertyName property to animate
+ * @param start value at start
+ * @param end value at end
+ */
+void MoveElementsCommand::setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant start, const QVariant end) {
+ //create animation group if not yet.
+ if (m_anim_group == nullptr) m_anim_group = new QParallelAnimationGroup();
+ QPropertyAnimation *animation = new QPropertyAnimation(target, propertyName);
+ animation->setDuration(300);
+ animation->setStartValue(start);
+ animation->setEndValue(end);
+ animation->setEasingCurve(QEasingCurve::OutQuad);
+ m_anim_group->addAnimation(animation);
+}
+
+/**
Constructeur
@param diagram Schema sur lequel on deplace des champs de texte
@param texts Liste des textes deplaces
Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h 2014-07-07 14:36:53 UTC (rev 3201)
+++ trunk/sources/diagramcommands.h 2014-07-09 16:50:30 UTC (rev 3202)
@@ -245,6 +245,9 @@
virtual void redo();
virtual void move(const QPointF &);
virtual void addConductorTextItemMovement(ConductorTextItem *, const QPointF &, const QPointF &);
+
+ private:
+ void setupAnimation (QObject * target, const QByteArray &propertyName, const QVariant start, const QVariant end);
// attributes
private:
@@ -254,6 +257,8 @@
DiagramContent content_to_move;
/// applied movement
QPointF movement;
+ ///animation group
+ QParallelAnimationGroup *m_anim_group;
/**
Moving elements impacts their conductors: either they are moved, or their path
needs to be generated again, which in turn tends to move their child text
Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h 2014-07-07 14:36:53 UTC (rev 3201)
+++ trunk/sources/qetgraphicsitem/conductor.h 2014-07-09 16:50:30 UTC (rev 3202)
@@ -34,6 +34,9 @@
class Conductor : public QObject, public QGraphicsPathItem {
Q_OBJECT
+
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+ Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
// constructors, destructor
public:
@@ -67,6 +70,12 @@
Diagram *diagram() const;
ConductorTextItem *textItem() const;
void updatePath(const QRectF & = QRectF());
+
+ //This method do nothing, it's only made to be used with Q_PROPERTY
+ //It's used to anim the path when is change
+ void updatePathAnimate(const int = 1) {updatePath();}
+ int fakePath() {return 1;}
+
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect() const;
virtual QPainterPath shape() const;