diff --git a/sources/QPropertyUndoCommand/qpropertyundocommand.cpp b/sources/QPropertyUndoCommand/qpropertyundocommand.cpp index 6cb06c629..0a65c852d 100644 --- a/sources/QPropertyUndoCommand/qpropertyundocommand.cpp +++ b/sources/QPropertyUndoCommand/qpropertyundocommand.cpp @@ -31,8 +31,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property m_object(object), m_property_name(property_name), m_old_value(old_value), - m_new_value(new_value), - m_animate(false) + m_new_value(new_value) {} /** @@ -48,8 +47,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property QUndoCommand(parent), m_object(object), m_property_name(property_name), - m_old_value(old_value), - m_animate(false) + m_old_value(old_value) {} QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other) @@ -59,6 +57,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other) m_old_value = other->m_old_value; m_new_value = other->m_new_value; m_animate = other->m_animate; + m_first_time = other->m_first_time; setText(other->text()); } @@ -80,6 +79,18 @@ void QPropertyUndoCommand::enableAnimation (bool animate) { m_animate = animate; } +/** + * @brief QPropertyUndoCommand::setAnimated + * @param animate = true for animate this undo + * @param first_time = if true, the first animation is done at the first call of redo + * if false, the first animation is done at the second call of redo. + */ +void QPropertyUndoCommand::setAnimated(bool animate, bool first_time) +{ + m_animate = animate; + m_first_time = first_time; +} + /** * @brief QPropertyUndoCommand::mergeWith * Try to merge this command with other command @@ -103,7 +114,7 @@ void QPropertyUndoCommand::redo() { if (m_object->property(m_property_name) != m_new_value) { - if (m_animate) + if (m_animate && m_first_time) { QPropertyAnimation *animation = new QPropertyAnimation(m_object, m_property_name); animation->setStartValue(m_old_value); @@ -111,7 +122,10 @@ void QPropertyUndoCommand::redo() animation->start(QAbstractAnimation::DeleteWhenStopped); } else + { m_object->setProperty(m_property_name, m_new_value); + m_first_time = true; + } } QUndoCommand::redo(); diff --git a/sources/QPropertyUndoCommand/qpropertyundocommand.h b/sources/QPropertyUndoCommand/qpropertyundocommand.h index 9098422a4..91a95b5fc 100644 --- a/sources/QPropertyUndoCommand/qpropertyundocommand.h +++ b/sources/QPropertyUndoCommand/qpropertyundocommand.h @@ -39,6 +39,7 @@ class QPropertyUndoCommand : public QUndoCommand void setNewValue(const QVariant &new_value); void enableAnimation (bool animate = true); + void setAnimated(bool animate = true, bool first_time = true); int id() const override{return 10000;} bool mergeWith(const QUndoCommand *other) override; @@ -46,10 +47,11 @@ class QPropertyUndoCommand : public QUndoCommand void undo() override; private: - QObject *m_object; + QObject *m_object = nullptr; const char *m_property_name; QVariant m_old_value, m_new_value; - bool m_animate; + bool m_animate = false, + m_first_time = true; }; #endif // QPROPERTYUNDOCOMMAND_H diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index 3b67c2ddc..9efe235e7 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -454,7 +454,8 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt(); if (fs != deti->fontSize()) { - QUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo); + QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo); + quc->setAnimated(true, false); quc->setText(tr("Modifier la taille d'un texte d'élément")); } @@ -475,7 +476,8 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem qreal text_width = text_qsi->child(width_txt_row, 1)->data(Qt::EditRole).toDouble(); if(text_width != deti->textWidth()) { - QUndoCommand *quc = new QPropertyUndoCommand(deti, "textWidth", QVariant(deti->textWidth()), QVariant(text_width), undo); + QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "textWidth", QVariant(deti->textWidth()), QVariant(text_width), undo); + quc->setAnimated(true, false); quc->setText(tr("Modifier la largeur d'un texte d'élément")); } @@ -487,6 +489,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem if(p != deti->pos()) { QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo); + quc->setAnimated(true, false); quc->setText(tr("Déplacer un texte d'élément")); } } @@ -498,6 +501,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem if(rot != deti->rotation()) { QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "rotation", QVariant(deti->rotation()), QVariant(rot), undo); + quc->setAnimated(true, false); quc->setText(tr("Pivoter un texte d'élément")); } } @@ -536,7 +540,10 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup * qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble(); if(group->rotation() != rotation) - new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo); + { + QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo); + qpuc->enableAnimation(); + } int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt(); if(group->verticalAdjustment() != v_adjustment)