mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02: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:
parent
844167f181
commit
5a8bb42153
@ -27,6 +27,7 @@
|
||||
#include "qetgraphicsitem/diagramtextitem.h"
|
||||
#include "qetgraphicsitem/diagramimageitem.h"
|
||||
#include "conductorautonumerotation.h"
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@ -418,6 +419,7 @@ MoveElementsCommand::MoveElementsCommand(
|
||||
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 @@ MoveElementsCommand::MoveElementsCommand(
|
||||
* Destructor
|
||||
*/
|
||||
MoveElementsCommand::~MoveElementsCommand() {
|
||||
delete m_anim_group;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -451,7 +454,8 @@ MoveElementsCommand::~MoveElementsCommand() {
|
||||
*/
|
||||
void MoveElementsCommand::undo() {
|
||||
diagram -> showMe();
|
||||
move(-movement);
|
||||
m_anim_group->setDirection(QAnimationGroup::Forward);
|
||||
m_anim_group->start();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,8 +463,14 @@ void MoveElementsCommand::undo() {
|
||||
*/
|
||||
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 @@ void MoveElementsCommand::move(const QPointF &actual_movement) {
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@param diagram Schema sur lequel on deplace des champs de texte
|
||||
|
@ -245,6 +245,9 @@ class MoveElementsCommand : public QUndoCommand {
|
||||
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 @@ class MoveElementsCommand : public QUndoCommand {
|
||||
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
|
||||
|
@ -34,6 +34,9 @@ typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
||||
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 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user