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 "slide_p.h"
|
2009-10-15 21:36:38 +02:00
|
|
|
|
|
|
|
#include <QPointF>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
void SlideAnimation::setDistance(qreal distance)
|
|
|
|
{
|
2010-01-22 19:55:37 +01:00
|
|
|
m_animDistance = QPointF(distance, 0.0);
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
qreal SlideAnimation::distance() const
|
2010-01-22 19:55:37 +01:00
|
|
|
{
|
|
|
|
return m_animDistance.x();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::setDistancePointF(const QPointF &distance)
|
|
|
|
{
|
|
|
|
m_animDistance = distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF SlideAnimation::distancePointF() const
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
|
|
|
return m_animDistance;
|
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
SlideAnimation::~SlideAnimation()
|
|
|
|
{
|
|
|
|
}
|
2009-12-03 20:30:02 +01:00
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
SlideAnimation::SlideAnimation(QObject *parent,
|
2010-01-12 23:24:58 +01:00
|
|
|
MovementDirection direction,
|
2010-04-08 19:07:33 +02:00
|
|
|
qreal distance) : EasingAnimation(parent)
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
|
|
|
setMovementDirection(direction);
|
|
|
|
setDistance(distance);
|
2010-01-12 23:24:58 +01:00
|
|
|
setEasingCurve(QEasingCurve::OutCirc);
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
void SlideAnimation::setMovementDirection(const Animation::MovementDirection &direction)
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
2010-02-01 19:02:53 +01:00
|
|
|
m_animDirection = direction;
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
Animation::MovementDirection SlideAnimation::movementDirection() const
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
2010-02-01 19:02:53 +01:00
|
|
|
return m_animDirection;
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void SlideAnimation::updateEffectiveTime(int currentTime)
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-05 13:08:08 +01:00
|
|
|
if (w && state() == QAbstractAnimation::Running) {
|
2010-04-23 01:10:29 +02:00
|
|
|
const qreal delta = currentTime / qreal(duration());
|
2009-12-05 16:25:44 +01:00
|
|
|
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
|
2009-12-05 13:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
|
|
|
{
|
|
|
|
if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
|
2010-01-04 10:18:11 +01:00
|
|
|
if (!targetWidget()) {
|
2009-12-05 13:08:08 +01:00
|
|
|
return;
|
2009-12-05 00:00:05 +01:00
|
|
|
}
|
2010-01-04 10:18:11 +01:00
|
|
|
m_startPos = targetWidget()->pos();
|
2009-12-05 00:00:05 +01:00
|
|
|
|
2009-12-05 13:08:08 +01:00
|
|
|
qreal newX = m_startPos.x();
|
|
|
|
qreal newY = m_startPos.y();
|
|
|
|
|
2010-01-22 19:55:37 +01:00
|
|
|
QPointF actualDistance = (direction() == \
|
|
|
|
QAbstractAnimation::Forward ? \
|
|
|
|
distancePointF():-distancePointF());
|
2009-12-05 13:08:08 +01:00
|
|
|
|
2010-02-01 19:02:53 +01:00
|
|
|
bool moveAnyOnly = true;
|
2009-12-05 13:08:08 +01:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animDirection.testFlag(MoveUp)) {
|
2010-02-01 19:02:53 +01:00
|
|
|
newY -= actualDistance.x();
|
|
|
|
moveAnyOnly = false;
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animDirection.testFlag(MoveDown)) {
|
2010-01-22 19:55:37 +01:00
|
|
|
newY += actualDistance.x();
|
2010-02-01 19:02:53 +01:00
|
|
|
moveAnyOnly = false;
|
|
|
|
}
|
2009-12-05 13:08:08 +01:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animDirection.testFlag(MoveRight)) {
|
2010-01-22 19:55:37 +01:00
|
|
|
newX += actualDistance.x();
|
2010-02-01 19:02:53 +01:00
|
|
|
moveAnyOnly = false;
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animDirection.testFlag(MoveLeft)) {
|
2010-01-22 19:55:37 +01:00
|
|
|
newX -= actualDistance.x();
|
2010-02-01 19:02:53 +01:00
|
|
|
moveAnyOnly = false;
|
|
|
|
}
|
2010-01-22 19:55:37 +01:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (moveAnyOnly && m_animDirection.testFlag(MoveAny)) {
|
2010-01-22 19:55:37 +01:00
|
|
|
newX = actualDistance.x();
|
|
|
|
newY = actualDistance.y();
|
2009-12-05 13:08:08 +01:00
|
|
|
}
|
|
|
|
|
2009-12-05 16:25:44 +01:00
|
|
|
if (direction() == QAbstractAnimation::Forward) {
|
|
|
|
m_targetPos = QPointF(newX, newY);
|
|
|
|
} else {
|
|
|
|
m_targetPos = m_startPos;
|
|
|
|
m_startPos = QPointF(newX, newY);
|
|
|
|
}
|
2009-12-05 00:00:05 +01:00
|
|
|
}
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
|
|
|
|
2009-10-15 21:36:38 +02:00
|
|
|
} //namespace Plasma
|
|
|
|
|
2010-02-24 00:31:45 +01:00
|
|
|
#include <../slide_p.moc>
|