2009-10-15 21:36:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2009-10-22 21:46:16 +02:00
|
|
|
#include "grow_p.h"
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
#include <QRect>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-10-17 19:52:19 +02:00
|
|
|
GrowAnimation::GrowAnimation(qreal factor)
|
2009-10-20 23:04:49 +02:00
|
|
|
: m_animFactor(factor)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-22 18:25:48 +02:00
|
|
|
void GrowAnimation::setFactor(qreal factor)
|
|
|
|
{
|
|
|
|
m_animFactor = qBound(qreal(0.0), factor, qreal(1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal GrowAnimation::factor() const
|
|
|
|
{
|
|
|
|
return m_animFactor;
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
QAbstractAnimation* GrowAnimation::render(QObject* parent){
|
|
|
|
|
|
|
|
//get current geometry values
|
2009-10-20 23:21:40 +02:00
|
|
|
QGraphicsWidget *m_object = widgetToAnimate();
|
2009-10-15 21:36:38 +02:00
|
|
|
QRectF geometry = m_object->geometry();
|
|
|
|
qreal w = geometry.width();
|
|
|
|
qreal h = geometry.height();
|
|
|
|
|
|
|
|
//compute new geometry values
|
2009-10-20 23:04:49 +02:00
|
|
|
qreal factor = m_animFactor;
|
2009-10-17 19:35:02 +02:00
|
|
|
qreal newWidth = w * factor;
|
|
|
|
qreal newHeight = h * factor;
|
2009-10-15 21:36:38 +02:00
|
|
|
//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.
|
2009-10-17 19:35:02 +02:00
|
|
|
qreal locfactor = (factor - 1) / 2.0;
|
2009-10-15 21:36:38 +02:00
|
|
|
qreal newX = geometry.x() - w * locfactor;
|
|
|
|
qreal newY = geometry.y() - h * locfactor;
|
|
|
|
|
2009-10-23 20:39:57 +02:00
|
|
|
//Recreate only if needed
|
|
|
|
QPropertyAnimation *anim = dynamic_cast<QPropertyAnimation* >(animation());
|
|
|
|
if (!anim) {
|
|
|
|
anim = new QPropertyAnimation(m_object, "geometry", parent);
|
|
|
|
setAnimation(anim);
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
anim->setEndValue(QRectF(
|
|
|
|
newX, newY,
|
|
|
|
newWidth, newHeight));
|
2009-10-20 23:04:49 +02:00
|
|
|
anim->setDuration(duration());
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
//QObject::connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
|
|
|
|
|
|
|
return anim;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|