mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Revamp code
-Move MoveElementsCommand class from diagramcommands file to movegraphicsitemcommand file. -Rename the to class MoveGraphicsItemCommand. -Minor code change to make it more modern.
This commit is contained in:
@@ -148,155 +148,6 @@ CutDiagramCommand::~CutDiagramCommand()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveElementsCommand::MoveElementsCommand
|
||||
Constructor
|
||||
@param dia diagram
|
||||
@param diagram_content diagram content (contain all items to be moved)
|
||||
@param m movement to applied
|
||||
@param parent parent undo command
|
||||
*/
|
||||
MoveElementsCommand::MoveElementsCommand(
|
||||
Diagram *dia,
|
||||
const DiagramContent &diagram_content,
|
||||
const QPointF &m,
|
||||
QUndoCommand *parent
|
||||
) :
|
||||
QUndoCommand (parent),
|
||||
diagram (dia),
|
||||
content_to_move (diagram_content),
|
||||
movement (m),
|
||||
m_anim_group (nullptr),
|
||||
first_redo (true)
|
||||
{
|
||||
QString moved_content_sentence = content_to_move.sentence(
|
||||
DiagramContent::Elements |
|
||||
DiagramContent::TextFields |
|
||||
DiagramContent::ConductorsToUpdate |
|
||||
DiagramContent::ConductorsToMove |
|
||||
DiagramContent::Images |
|
||||
DiagramContent::Shapes |
|
||||
DiagramContent::ElementTextFields |
|
||||
DiagramContent::TerminalStrip
|
||||
);
|
||||
|
||||
setText(
|
||||
QString(
|
||||
QObject::tr(
|
||||
"déplacer %1",
|
||||
"undo caption - %1 is a sentence listing the moved content"
|
||||
).arg(moved_content_sentence)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveElementsCommand::~MoveElementsCommand
|
||||
Destructor
|
||||
*/
|
||||
MoveElementsCommand::~MoveElementsCommand()
|
||||
{
|
||||
delete m_anim_group;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveElementsCommand::undo
|
||||
*/
|
||||
void MoveElementsCommand::undo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
m_anim_group->setDirection(QAnimationGroup::Forward);
|
||||
m_anim_group->start();
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveElementsCommand::redo
|
||||
*/
|
||||
void MoveElementsCommand::redo()
|
||||
{
|
||||
diagram -> showMe();
|
||||
if (first_redo) {
|
||||
first_redo = false;
|
||||
move(-movement);
|
||||
}
|
||||
else {
|
||||
m_anim_group->setDirection(QAnimationGroup::Backward);
|
||||
m_anim_group->start();
|
||||
}
|
||||
QUndoCommand::redo();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveElementsCommand::move
|
||||
Move item and conductor to actual_movement
|
||||
@param actual_movement movement to be applied
|
||||
*/
|
||||
void MoveElementsCommand::move(const QPointF &actual_movement)
|
||||
{
|
||||
typedef DiagramContent dc;
|
||||
|
||||
//Move every movable items, except conductor
|
||||
for (auto &&qgi : content_to_move.items(dc::Elements
|
||||
| dc::TextFields
|
||||
| dc::Images
|
||||
| dc::Shapes
|
||||
| dc::TextGroup
|
||||
| dc::ElementTextFields
|
||||
| dc::Tables
|
||||
| dc::TerminalStrip))
|
||||
{
|
||||
//If curent item have parent, and parent item is in content_to_move
|
||||
//we don't apply movement to this item, because this item will be moved by is parent.
|
||||
if (qgi->parentItem())
|
||||
if (content_to_move.items().contains(qgi->parentItem()))
|
||||
continue;
|
||||
|
||||
if(qgi->toGraphicsObject())
|
||||
setupAnimation(qgi->toGraphicsObject(), "pos",
|
||||
qgi->pos(), qgi->pos() + actual_movement);
|
||||
else if(qgi->type() == QGraphicsItemGroup::Type)
|
||||
{
|
||||
//ElementTextItemGroup is a QObject but not a QGraphicsObject
|
||||
if(ElementTextItemGroup *etig = dynamic_cast<ElementTextItemGroup *>(qgi))
|
||||
setupAnimation(etig, "pos", etig->pos(),
|
||||
etig->pos() + actual_movement);
|
||||
}
|
||||
else qgi -> setPos(qgi->pos() + actual_movement);
|
||||
}
|
||||
|
||||
// Move some conductors
|
||||
for (Conductor *conductor : content_to_move.m_conductors_to_move)
|
||||
setupAnimation(conductor, "pos", conductor->pos(),
|
||||
conductor->pos() + actual_movement);
|
||||
|
||||
// Recalcul the path of other conductor
|
||||
for (Conductor *conductor : content_to_move.m_conductors_to_update)
|
||||
setupAnimation(conductor, "animPath", 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MoveConductorsTextsCommand::MoveConductorsTextsCommand
|
||||
Constructeur
|
||||
|
||||
Reference in New Issue
Block a user