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)
|
2010-04-08 19:07:33 +02:00
|
|
|
: EasingAnimation(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;
|
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void GrowAnimation::updateEffectiveTime(int currentTime)
|
2009-12-03 20:30:02 +01:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-05 14:53:25 +01:00
|
|
|
if (w && state() == QAbstractAnimation::Running) {
|
2010-04-23 01:10:29 +02:00
|
|
|
const qreal delta = currentTime / qreal(duration());
|
2009-12-05 14:53:25 +01:00
|
|
|
QRectF geometry;
|
|
|
|
geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
|
|
|
|
geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta));
|
|
|
|
w->setGeometry(geometry);
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-05 14:53:25 +01:00
|
|
|
void GrowAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
|
|
|
{
|
|
|
|
if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *widget = targetWidget();
|
2009-12-05 14:53:25 +01:00
|
|
|
if (!widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF minimum = widget->effectiveSizeHint(Qt::MinimumSize);
|
|
|
|
QSizeF maximum = widget->effectiveSizeHint(Qt::MaximumSize);
|
|
|
|
m_startGeometry = widget->geometry();
|
|
|
|
qreal w = m_startGeometry.width();
|
|
|
|
qreal h = m_startGeometry.height();
|
|
|
|
qreal factor = m_animFactor;
|
|
|
|
|
|
|
|
//compute new geometry values
|
|
|
|
qreal newWidth;
|
|
|
|
qreal newHeight;
|
|
|
|
if (direction() == QAbstractAnimation::Forward) {
|
|
|
|
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;
|
|
|
|
qreal newY;
|
|
|
|
newX = m_startGeometry.x() - (newWidth - w)/2;
|
|
|
|
newY = m_startGeometry.y() - (newHeight - h)/2;
|
|
|
|
|
|
|
|
if (direction() == QAbstractAnimation::Forward) {
|
|
|
|
//the end geometry gets rounded to prevent things looking ugly
|
|
|
|
m_targetGeometry = QRect(newX, newY, newWidth, newHeight);
|
|
|
|
} else {
|
|
|
|
m_targetGeometry = m_startGeometry;
|
|
|
|
m_startGeometry = QRectF(newX, newY, newWidth, newHeight);
|
|
|
|
}
|
2009-11-02 09:59:00 +01:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|
2012-01-22 15:37:37 +01:00
|
|
|
#include "moc_grow_p.cpp"
|
2010-02-24 00:31:45 +01:00
|
|
|
|