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)
|
|
|
|
{
|
|
|
|
m_animDistance = distance;
|
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
qreal SlideAnimation::distance() const
|
|
|
|
{
|
|
|
|
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 10:55:42 +01:00
|
|
|
Direction direction,
|
2009-12-09 17:28:27 +01:00
|
|
|
qreal distance) : Animation(parent)
|
2009-12-03 23:42:34 +01:00
|
|
|
{
|
|
|
|
setMovementDirection(direction);
|
|
|
|
setDistance(distance);
|
2009-12-11 16:09:32 +01:00
|
|
|
Animation::setEasingCurveType(QEasingCurve::OutCirc);
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
2009-10-15 21:36:38 +02:00
|
|
|
|
2009-12-03 23:42:34 +01:00
|
|
|
void SlideAnimation::setMovementDirection(const qint8 &direction)
|
|
|
|
{
|
2010-01-12 10:55:42 +01:00
|
|
|
m_animDirection = static_cast<Direction>(direction);
|
2009-12-03 23:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qint8 SlideAnimation::movementDirection() const
|
|
|
|
{
|
|
|
|
return static_cast<qint8>(m_animDirection);
|
|
|
|
}
|
|
|
|
|
2009-12-05 00:00:05 +01:00
|
|
|
void SlideAnimation::updateCurrentTime(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) {
|
2009-12-09 17:28:27 +01:00
|
|
|
qreal delta = Animation::easingCurve().valueForProgress(
|
2009-12-08 20:29:03 +01:00
|
|
|
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();
|
|
|
|
|
2009-12-05 16:25:44 +01:00
|
|
|
int actualDistance = (direction() == QAbstractAnimation::Forward?distance():-distance());
|
2009-12-05 13:08:08 +01:00
|
|
|
switch (movementDirection()) {
|
|
|
|
case MoveUp:
|
2009-12-05 16:25:44 +01:00
|
|
|
newY -= actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveRight:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX += actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveDown:
|
2009-12-05 16:25:44 +01:00
|
|
|
newY += actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveLeft:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX -= actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveUpRight:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX += actualDistance;
|
|
|
|
newY -= actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveDownRight:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX += actualDistance;
|
|
|
|
newY += actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MoveDownLeft:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX -= actualDistance;
|
|
|
|
newY += actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MoveUpLeft:
|
2009-12-05 16:25:44 +01:00
|
|
|
newX -= actualDistance;
|
|
|
|
newY -= actualDistance;
|
2009-12-05 13:08:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
kDebug()<<"Compound direction is not supported";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|