mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-23 02:10:52 +01:00
Minor : dynamic element text item, the undo is now animated when user edit the text from the dock widget
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5273 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -31,8 +31,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property
|
|||||||
m_object(object),
|
m_object(object),
|
||||||
m_property_name(property_name),
|
m_property_name(property_name),
|
||||||
m_old_value(old_value),
|
m_old_value(old_value),
|
||||||
m_new_value(new_value),
|
m_new_value(new_value)
|
||||||
m_animate(false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +47,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property
|
|||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
m_object(object),
|
m_object(object),
|
||||||
m_property_name(property_name),
|
m_property_name(property_name),
|
||||||
m_old_value(old_value),
|
m_old_value(old_value)
|
||||||
m_animate(false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other)
|
QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other)
|
||||||
@@ -59,6 +57,7 @@ QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other)
|
|||||||
m_old_value = other->m_old_value;
|
m_old_value = other->m_old_value;
|
||||||
m_new_value = other->m_new_value;
|
m_new_value = other->m_new_value;
|
||||||
m_animate = other->m_animate;
|
m_animate = other->m_animate;
|
||||||
|
m_first_time = other->m_first_time;
|
||||||
setText(other->text());
|
setText(other->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +79,18 @@ void QPropertyUndoCommand::enableAnimation (bool animate) {
|
|||||||
m_animate = 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
|
* @brief QPropertyUndoCommand::mergeWith
|
||||||
* Try to merge this command with other command
|
* 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_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);
|
QPropertyAnimation *animation = new QPropertyAnimation(m_object, m_property_name);
|
||||||
animation->setStartValue(m_old_value);
|
animation->setStartValue(m_old_value);
|
||||||
@@ -111,7 +122,10 @@ void QPropertyUndoCommand::redo()
|
|||||||
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_object->setProperty(m_property_name, m_new_value);
|
m_object->setProperty(m_property_name, m_new_value);
|
||||||
|
m_first_time = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUndoCommand::redo();
|
QUndoCommand::redo();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class QPropertyUndoCommand : public QUndoCommand
|
|||||||
|
|
||||||
void setNewValue(const QVariant &new_value);
|
void setNewValue(const QVariant &new_value);
|
||||||
void enableAnimation (bool animate = true);
|
void enableAnimation (bool animate = true);
|
||||||
|
void setAnimated(bool animate = true, bool first_time = true);
|
||||||
|
|
||||||
int id() const override{return 10000;}
|
int id() const override{return 10000;}
|
||||||
bool mergeWith(const QUndoCommand *other) override;
|
bool mergeWith(const QUndoCommand *other) override;
|
||||||
@@ -46,10 +47,11 @@ class QPropertyUndoCommand : public QUndoCommand
|
|||||||
void undo() override;
|
void undo() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QObject *m_object;
|
QObject *m_object = nullptr;
|
||||||
const char *m_property_name;
|
const char *m_property_name;
|
||||||
QVariant m_old_value, m_new_value;
|
QVariant m_old_value, m_new_value;
|
||||||
bool m_animate;
|
bool m_animate = false,
|
||||||
|
m_first_time = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QPROPERTYUNDOCOMMAND_H
|
#endif // QPROPERTYUNDOCOMMAND_H
|
||||||
|
|||||||
@@ -454,7 +454,8 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
|||||||
int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt();
|
int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt();
|
||||||
if (fs != deti->fontSize())
|
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"));
|
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();
|
qreal text_width = text_qsi->child(width_txt_row, 1)->data(Qt::EditRole).toDouble();
|
||||||
if(text_width != deti->textWidth())
|
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"));
|
quc->setText(tr("Modifier la largeur d'un texte d'élément"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,6 +489,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
|||||||
if(p != deti->pos())
|
if(p != deti->pos())
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
|
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"));
|
quc->setText(tr("Déplacer un texte d'élément"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -498,6 +501,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
|||||||
if(rot != deti->rotation())
|
if(rot != deti->rotation())
|
||||||
{
|
{
|
||||||
QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "rotation", QVariant(deti->rotation()), QVariant(rot), undo);
|
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"));
|
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();
|
qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
|
||||||
if(group->rotation() != rotation)
|
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();
|
int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
|
||||||
if(group->verticalAdjustment() != v_adjustment)
|
if(group->verticalAdjustment() != v_adjustment)
|
||||||
|
|||||||
Reference in New Issue
Block a user