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-12-03 20:30:02 +01:00
|
|
|
GrowAnimation::GrowAnimation(QObject *parent, qreal factor)
|
|
|
|
: Animation(parent), m_animFactor(factor)
|
2009-10-15 21:36:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-27 14:59:40 +01:00
|
|
|
void GrowAnimation::setFactor(const qreal factor)
|
2009-10-22 18:25:48 +02:00
|
|
|
{
|
2009-10-27 14:59:40 +01:00
|
|
|
m_animFactor = qMax(qreal(0.0), factor);
|
2009-10-22 18:25:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal GrowAnimation::factor() const
|
|
|
|
{
|
|
|
|
return m_animFactor;
|
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
void GrowAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
Animation::setWidgetToAnimate(widget);
|
|
|
|
if (animation.data()) {
|
|
|
|
delete animation.data();
|
|
|
|
animation.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2009-10-27 23:03:14 +01:00
|
|
|
QSizeF minimum = m_object->effectiveSizeHint(Qt::MinimumSize);
|
|
|
|
QSizeF maximum = m_object->effectiveSizeHint(Qt::MaximumSize);
|
2009-10-15 21:36:38 +02:00
|
|
|
qreal w = geometry.width();
|
|
|
|
qreal h = geometry.height();
|
2009-11-02 09:59:00 +01:00
|
|
|
qreal factor = m_animFactor;
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
//compute new geometry values
|
2009-11-02 09:59:00 +01:00
|
|
|
qreal newWidth;
|
|
|
|
qreal newHeight;
|
2009-12-03 20:30:02 +01:00
|
|
|
if (direction() == QAbstractAnimation::Forward) {
|
2009-11-02 09:59:00 +01:00
|
|
|
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());
|
|
|
|
}
|
2009-10-27 23:03:14 +01:00
|
|
|
|
2009-11-02 09:59:00 +01:00
|
|
|
qreal newX;
|
|
|
|
qreal newY;
|
|
|
|
newX = geometry.x() - (newWidth - w)/2;
|
|
|
|
newY = geometry.y() - (newHeight - h)/2;
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-10-23 20:39:57 +02:00
|
|
|
//Recreate only if needed
|
2009-12-03 20:30:02 +01:00
|
|
|
QPropertyAnimation *anim = animation.data();
|
2009-10-23 20:39:57 +02:00
|
|
|
if (!anim) {
|
2009-12-03 20:30:02 +01:00
|
|
|
anim = new QPropertyAnimation(m_object, "geometry", m_object);
|
|
|
|
animation = anim;
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
//Prevents from deforming (with multiple clicks)
|
|
|
|
QAbstractAnimation::State temp = anim->state();
|
|
|
|
if (temp == QAbstractAnimation::Running) {
|
|
|
|
return anim;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction() == QAbstractAnimation::Forward) {
|
2009-11-02 09:59:00 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
qDebug()<<"start value:"<<anim->startValue()<<"end value:"<<anim->endValue();
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
anim->setDuration(duration());
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
return anim;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|