2009-12-27 23:16:11 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
|
|
|
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-10-22 21:46:16 +02:00
|
|
|
#include "rotation_p.h"
|
2009-10-15 21:53:49 +02:00
|
|
|
|
|
|
|
#include <QGraphicsRotation>
|
2009-12-08 20:29:03 +01:00
|
|
|
#include <QEasingCurve>
|
2009-10-15 21:53:49 +02:00
|
|
|
|
2009-10-22 06:00:02 +02:00
|
|
|
#include <kdebug.h>
|
|
|
|
|
2009-10-15 21:53:49 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-01-12 23:24:58 +01:00
|
|
|
RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle)
|
2009-12-09 15:35:27 +01:00
|
|
|
: Animation(parent)
|
2009-10-16 21:52:43 +02:00
|
|
|
{
|
2009-10-21 07:32:04 +02:00
|
|
|
setAngle(angle);
|
|
|
|
setAxis(axis);
|
|
|
|
setReference(reference);
|
2009-10-16 21:52:43 +02:00
|
|
|
|
2009-12-09 15:35:27 +01:00
|
|
|
m_rotation = new QGraphicsRotation(this);
|
2009-10-16 21:52:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RotationAnimation::~RotationAnimation()
|
2009-10-15 21:53:49 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-04 21:49:09 +01:00
|
|
|
Qt::Axis RotationAnimation::axis() const
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
return m_axis;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RotationAnimation::setAxis(const Qt::Axis &axis)
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
m_axis = axis;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qint8 RotationAnimation::reference() const
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
return m_reference;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RotationAnimation::setReference(const qint8 &reference)
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
m_reference = reference;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal RotationAnimation::angle() const
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
return m_angle;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RotationAnimation::setAngle(const qreal &angle)
|
|
|
|
{
|
2009-12-09 15:35:27 +01:00
|
|
|
m_angle = angle;
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
2009-10-15 21:53:49 +02:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *m_object = targetWidget();
|
2009-10-15 21:53:49 +02:00
|
|
|
|
2009-12-04 21:49:09 +01:00
|
|
|
if (!m_object) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:53:49 +02:00
|
|
|
QVector3D vector(0, 0, 0);
|
|
|
|
|
|
|
|
const qreal widgetWidth = m_object->size().width();
|
|
|
|
const qreal widgetHeight = m_object->size().height();
|
|
|
|
|
2009-10-21 07:32:04 +02:00
|
|
|
if (axis() == Qt::XAxis) {
|
|
|
|
switch (reference()) {
|
2009-10-22 06:00:02 +02:00
|
|
|
case Center:
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setX(widgetWidth/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
vector.setY(widgetHeight/2);
|
|
|
|
break;
|
|
|
|
case Up:
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setX(widgetWidth/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
vector.setY(0);
|
|
|
|
break;
|
|
|
|
case Down:
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setX(widgetWidth/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
vector.setY(widgetHeight);
|
|
|
|
break;
|
2009-10-15 21:53:49 +02:00
|
|
|
}
|
2009-10-21 07:35:56 +02:00
|
|
|
|
2009-10-21 07:32:04 +02:00
|
|
|
} else if(axis() == Qt::YAxis) {
|
|
|
|
switch (reference()) {
|
2009-10-22 06:00:02 +02:00
|
|
|
case Center:
|
|
|
|
vector.setX(widgetWidth/2);
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setY(widgetHeight/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
vector.setX(0);
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setY(widgetHeight/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
vector.setX(widgetWidth);
|
2010-01-09 18:30:40 +01:00
|
|
|
vector.setY(widgetHeight/2);
|
2009-10-22 06:00:02 +02:00
|
|
|
break;
|
2009-10-15 21:53:49 +02:00
|
|
|
}
|
2009-10-21 07:35:56 +02:00
|
|
|
|
2009-10-21 07:32:04 +02:00
|
|
|
} else if (axis() == Qt::ZAxis) {
|
|
|
|
switch (reference()) {
|
2009-10-22 06:00:02 +02:00
|
|
|
case Center:
|
|
|
|
vector.setX(widgetWidth/2);
|
|
|
|
vector.setY(widgetHeight/2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Center|Up:
|
|
|
|
vector.setX(widgetWidth/2);
|
|
|
|
vector.setY(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Center|Down:
|
|
|
|
vector.setX(widgetWidth/2);
|
|
|
|
vector.setY(widgetHeight);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Center|Left:
|
|
|
|
vector.setX(0);
|
|
|
|
vector.setY(widgetHeight/2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Center|Right:
|
|
|
|
vector.setX(widgetWidth);
|
|
|
|
vector.setY(widgetHeight/2);
|
|
|
|
break;
|
2009-10-15 21:53:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 15:35:27 +01:00
|
|
|
m_rotation->setOrigin(vector);
|
|
|
|
m_rotation->setAxis(axis());
|
2009-10-15 21:53:49 +02:00
|
|
|
|
|
|
|
QList<QGraphicsTransform *> transformation;
|
2009-12-09 15:35:27 +01:00
|
|
|
transformation.append(m_rotation);
|
2009-10-15 21:53:49 +02:00
|
|
|
m_object->setTransformations(transformation);
|
|
|
|
|
2009-12-04 21:49:09 +01:00
|
|
|
if ((oldState == Stopped) && (newState == Running)) {
|
2009-12-09 15:35:27 +01:00
|
|
|
m_rotation->setAngle(direction() == Forward ? 0 : angle());
|
2009-12-04 21:49:09 +01:00
|
|
|
} else if (newState == Stopped) {
|
2009-12-09 15:35:27 +01:00
|
|
|
m_rotation->setAngle(direction() == Forward ? angle() : 0);
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
2009-10-22 17:35:08 +02:00
|
|
|
}
|
|
|
|
|
2009-12-04 21:49:09 +01:00
|
|
|
void RotationAnimation::updateCurrentTime(int currentTime)
|
2009-10-22 17:35:08 +02:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-04 21:49:09 +01:00
|
|
|
if (w) {
|
2009-12-09 17:34:43 +01:00
|
|
|
qreal delta = Animation::easingCurve().valueForProgress(
|
|
|
|
currentTime / qreal(duration()));
|
2009-12-04 21:49:09 +01:00
|
|
|
delta = angle() * delta;
|
2009-12-09 15:35:27 +01:00
|
|
|
m_rotation->setAngle(delta);
|
2009-12-04 21:49:09 +01:00
|
|
|
}
|
2009-10-22 17:35:08 +02:00
|
|
|
}
|
|
|
|
|
2009-10-15 21:53:49 +02:00
|
|
|
}
|
2010-02-24 00:31:45 +01:00
|
|
|
|
|
|
|
#include <../rotation_p.moc>
|