2009-12-05 21:23:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zoom_p.h"
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
ZoomAnimation::ZoomAnimation(QObject *parent)
|
2010-07-10 12:41:47 +02:00
|
|
|
: EasingAnimation(parent),
|
|
|
|
m_zoom(0)
|
2009-12-05 21:23:13 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ZoomAnimation::~ZoomAnimation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomAnimation::setZoom(qreal zoom)
|
|
|
|
{
|
|
|
|
m_zoom = zoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal ZoomAnimation::zoom() const
|
|
|
|
{
|
|
|
|
return m_zoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-05 21:23:13 +01:00
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldState == Stopped && newState == Running) {
|
2009-12-07 20:55:22 +01:00
|
|
|
w->setTransformOriginPoint(w->size().width()/2, w->size().height()/2);
|
2009-12-05 21:23:13 +01:00
|
|
|
w->setScale(direction() == Forward ? 1 : m_zoom);
|
|
|
|
} else if (newState == Stopped) {
|
|
|
|
w->setScale(direction() == Forward ? m_zoom : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void ZoomAnimation::updateEffectiveTime(int currentTime)
|
2009-12-05 21:23:13 +01:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-05 21:23:13 +01:00
|
|
|
if (w) {
|
2010-04-23 01:10:29 +02:00
|
|
|
qreal delta = currentTime / qreal(duration());
|
2009-12-16 23:31:00 +01:00
|
|
|
if (m_zoom != 1) {
|
|
|
|
delta = (1 - m_zoom) * delta;
|
|
|
|
w->setScale(1 - delta);
|
2009-12-17 16:51:24 +01:00
|
|
|
} else {
|
2009-12-16 23:31:00 +01:00
|
|
|
w->setScale(delta);
|
2009-12-17 16:51:24 +01:00
|
|
|
}
|
2009-12-05 21:23:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace Plasma
|