From d53654784a67af34ab55328128892ffc7a55ae93 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 27 Oct 2009 22:03:14 +0000 Subject: [PATCH] bound the grow animation between maximum and minimum sizes svn path=/trunk/KDE/kdelibs/; revision=1041374 --- animations/grow.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/animations/grow.cpp b/animations/grow.cpp index c7c70cec0..25d505c0e 100644 --- a/animations/grow.cpp +++ b/animations/grow.cpp @@ -45,19 +45,18 @@ QAbstractAnimation* GrowAnimation::render(QObject* parent){ //get current geometry values QGraphicsWidget *m_object = widgetToAnimate(); QRectF geometry = m_object->geometry(); + QSizeF minimum = m_object->effectiveSizeHint(Qt::MinimumSize); + QSizeF maximum = m_object->effectiveSizeHint(Qt::MaximumSize); qreal w = geometry.width(); qreal h = geometry.height(); //compute new geometry values qreal factor = m_animFactor; - qreal newWidth = w * factor; - qreal newHeight = h * factor; - //locfactor is factor by which object must move up and left - //to compensate for its growth down and right, to keep the - //center in place. - qreal locfactor = (factor - 1) / 2.0; - qreal newX = geometry.x() - w * locfactor; - qreal newY = geometry.y() - h * locfactor; + qreal newWidth = qBound(minimum.width(), w * factor, maximum.width()); + qreal newHeight = qBound(minimum.width(), h * factor, maximum.width()); + + qreal newX = geometry.x() - (newWidth - w)/2; + qreal newY = geometry.y() - (newHeight - h)/2; //Recreate only if needed QPropertyAnimation *anim = dynamic_cast(animation());