mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
move undo command: graphics item is animated when undo/redo (testing)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3202 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include "qetgraphicsitem/diagramtextitem.h"
|
#include "qetgraphicsitem/diagramtextitem.h"
|
||||||
#include "qetgraphicsitem/diagramimageitem.h"
|
#include "qetgraphicsitem/diagramimageitem.h"
|
||||||
#include "conductorautonumerotation.h"
|
#include "conductorautonumerotation.h"
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -418,6 +419,7 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
diagram(dia),
|
diagram(dia),
|
||||||
content_to_move(diagram_content),
|
content_to_move(diagram_content),
|
||||||
movement(m),
|
movement(m),
|
||||||
|
m_anim_group(nullptr),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
QString moved_content_sentence = content_to_move.sentence(
|
QString moved_content_sentence = content_to_move.sentence(
|
||||||
@@ -444,6 +446,7 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
MoveElementsCommand::~MoveElementsCommand() {
|
MoveElementsCommand::~MoveElementsCommand() {
|
||||||
|
delete m_anim_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,7 +454,8 @@ MoveElementsCommand::~MoveElementsCommand() {
|
|||||||
*/
|
*/
|
||||||
void MoveElementsCommand::undo() {
|
void MoveElementsCommand::undo() {
|
||||||
diagram -> showMe();
|
diagram -> showMe();
|
||||||
move(-movement);
|
m_anim_group->setDirection(QAnimationGroup::Forward);
|
||||||
|
m_anim_group->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -459,8 +463,14 @@ void MoveElementsCommand::undo() {
|
|||||||
*/
|
*/
|
||||||
void MoveElementsCommand::redo() {
|
void MoveElementsCommand::redo() {
|
||||||
diagram -> showMe();
|
diagram -> showMe();
|
||||||
if (first_redo) first_redo = false;
|
if (first_redo) {
|
||||||
else move(movement);
|
first_redo = false;
|
||||||
|
move(-movement);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_anim_group->setDirection(QAnimationGroup::Backward);
|
||||||
|
m_anim_group->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -473,17 +483,20 @@ void MoveElementsCommand::move(const QPointF &actual_movement) {
|
|||||||
|
|
||||||
//Move every movable item, except conductor
|
//Move every movable item, except conductor
|
||||||
foreach (QGraphicsItem *qgi, content_to_move.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes)) {
|
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
|
// Move some conductors
|
||||||
foreach(Conductor *conductor, content_to_move.conductorsToMove) {
|
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
|
// Recalcul the path of other conductor
|
||||||
foreach(Conductor *conductor, content_to_move.conductorsToUpdate) {
|
foreach(Conductor *conductor, content_to_move.conductorsToUpdate) {
|
||||||
conductor -> updatePath();
|
setupAnimation(conductor, "animPath", 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,6 +516,25 @@ void MoveElementsCommand::addConductorTextItemMovement(ConductorTextItem *text_i
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
Constructeur
|
||||||
@param diagram Schema sur lequel on deplace des champs de texte
|
@param diagram Schema sur lequel on deplace des champs de texte
|
||||||
|
|||||||
@@ -245,6 +245,9 @@ class MoveElementsCommand : public QUndoCommand {
|
|||||||
virtual void redo();
|
virtual void redo();
|
||||||
virtual void move(const QPointF &);
|
virtual void move(const QPointF &);
|
||||||
virtual void addConductorTextItemMovement(ConductorTextItem *, const QPointF &, 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
|
// attributes
|
||||||
private:
|
private:
|
||||||
@@ -254,6 +257,8 @@ class MoveElementsCommand : public QUndoCommand {
|
|||||||
DiagramContent content_to_move;
|
DiagramContent content_to_move;
|
||||||
/// applied movement
|
/// applied movement
|
||||||
QPointF movement;
|
QPointF movement;
|
||||||
|
///animation group
|
||||||
|
QParallelAnimationGroup *m_anim_group;
|
||||||
/**
|
/**
|
||||||
Moving elements impacts their conductors: either they are moved, or their path
|
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
|
needs to be generated again, which in turn tends to move their child text
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
|||||||
class Conductor : public QObject, public QGraphicsPathItem {
|
class Conductor : public QObject, public QGraphicsPathItem {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||||
|
Q_PROPERTY(int animPath READ fakePath WRITE updatePathAnimate)
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
@@ -67,6 +70,12 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
|||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
ConductorTextItem *textItem() const;
|
ConductorTextItem *textItem() const;
|
||||||
void updatePath(const QRectF & = QRectF());
|
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 *);
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
virtual QPainterPath shape() const;
|
virtual QPainterPath shape() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user