From 52e5b9aca49a0c05747e3c60b6bb9c200332688d Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Da Silva Date: Mon, 2 Nov 2009 08:59:00 +0000 Subject: [PATCH] Making possible to rewind a grow animation (as also fixing the newHeight parameter). To make possible to return to previous state, it is both necessary to use the oposite animation factor as also the start and end value used in the animation. svn path=/trunk/KDE/kdelibs/; revision=1043658 --- animations/grow.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/animations/grow.cpp b/animations/grow.cpp index 25d505c0e..955b5a554 100644 --- a/animations/grow.cpp +++ b/animations/grow.cpp @@ -49,14 +49,23 @@ QAbstractAnimation* GrowAnimation::render(QObject* parent){ QSizeF maximum = m_object->effectiveSizeHint(Qt::MaximumSize); qreal w = geometry.width(); qreal h = geometry.height(); + qreal factor = m_animFactor; //compute new geometry values - qreal factor = m_animFactor; - qreal newWidth = qBound(minimum.width(), w * factor, maximum.width()); - qreal newHeight = qBound(minimum.width(), h * factor, maximum.width()); + qreal newWidth; + qreal newHeight; + if (forwards()) { + newWidth = qBound(minimum.width(), w * factor, maximum.width()); + newHeight = qBound(minimum.height(), h * factor, maximum.height()); + } else { + newWidth = qBound(minimum.width(), w / factor, maximum.width()); + newHeight = qBound(minimum.height(), h / factor, maximum.height()); + } - qreal newX = geometry.x() - (newWidth - w)/2; - qreal newY = geometry.y() - (newHeight - h)/2; + qreal newX; + qreal newY; + newX = geometry.x() - (newWidth - w)/2; + newY = geometry.y() - (newHeight - h)/2; //Recreate only if needed QPropertyAnimation *anim = dynamic_cast(animation()); @@ -65,9 +74,14 @@ QAbstractAnimation* GrowAnimation::render(QObject* parent){ setAnimation(anim); } - anim->setEndValue(QRectF( - newX, newY, - newWidth, newHeight)); + if (forwards()) { + anim->setStartValue(QRectF(geometry.x(), geometry.y(), w, h)); + anim->setEndValue(QRectF(newX, newY, newWidth, newHeight)); + } else { + anim->setStartValue(QRectF(newX, newY, newWidth, newHeight)); + anim->setEndValue(QRectF(geometry.x(), geometry.y(), w, h)); + } + anim->setDuration(duration()); //QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));