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:
blacksun
2018-03-24 13:45:48 +00:00
parent ae8f23f659
commit a58274c219
3 changed files with 33 additions and 10 deletions

View File

@@ -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();