2009-12-27 23:16:11 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.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 22:17:07 +02:00
|
|
|
|
2009-12-08 00:26:24 +01:00
|
|
|
#include "rotationstacked_p.h"
|
2009-10-22 22:17:07 +02:00
|
|
|
#include <QGraphicsRotation>
|
|
|
|
#include <QSequentialAnimationGroup>
|
2009-11-13 18:38:04 +01:00
|
|
|
#include <QWeakPointer>
|
2009-10-23 20:39:57 +02:00
|
|
|
#include <kdebug.h>
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2009-12-03 20:57:54 +01:00
|
|
|
#include "stackedlayout.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
|
2009-10-22 22:17:07 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
|
2009-12-08 00:22:47 +01:00
|
|
|
: Animation(parent)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
backRotation = new QGraphicsRotation(this);
|
|
|
|
frontRotation = new QGraphicsRotation(this);
|
|
|
|
sLayout = new StackedLayout;
|
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
RotationStackedAnimation::~RotationStackedAnimation()
|
|
|
|
{
|
|
|
|
/* TODO: test what is lacking a parent and delete it */
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
|
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
animDirection = static_cast<Plasma::AnimationDirection>(direction);
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qint8 RotationStackedAnimation::movementDirection() const
|
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
return static_cast<qint8>(animDirection);
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2009-11-12 21:15:43 +01:00
|
|
|
void RotationStackedAnimation::setReference(const qint8 &reference)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
m_reference = reference;
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-11-12 21:15:43 +01:00
|
|
|
qint8 RotationStackedAnimation::reference() const
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
return m_reference;
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-10-23 04:45:55 +02:00
|
|
|
QGraphicsWidget *RotationStackedAnimation::backWidget()
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
return m_backWidget.data();
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-10-23 04:45:55 +02:00
|
|
|
void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
m_backWidget = backWidget;
|
2009-10-23 04:45:55 +02:00
|
|
|
|
2010-01-04 10:18:11 +01:00
|
|
|
if(targetWidget()) {
|
|
|
|
sLayout->addWidget(targetWidget());
|
2009-12-08 00:22:47 +01:00
|
|
|
sLayout->addWidget(m_backWidget.data());
|
2009-10-23 04:45:55 +02:00
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-10-23 04:45:55 +02:00
|
|
|
QGraphicsLayoutItem *RotationStackedAnimation::layout()
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-08 00:22:47 +01:00
|
|
|
return sLayout;
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-05 15:54:06 +01:00
|
|
|
void RotationStackedAnimation::updateState(
|
|
|
|
QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2009-12-03 20:30:02 +01:00
|
|
|
if (!backWidget()) {
|
2009-12-05 15:54:06 +01:00
|
|
|
return;
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2010-01-04 10:18:11 +01:00
|
|
|
QPair<QGraphicsWidget *,QGraphicsWidget *> widgets = qMakePair(targetWidget(), backWidget());
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
const qreal widgetFrontWidth = widgets.first->size().width();
|
|
|
|
const qreal widgetFrontHeight = widgets.first->size().height();
|
|
|
|
|
|
|
|
const qreal widgetBackWidth = widgets.second->size().width();
|
|
|
|
const qreal widgetBackHeight = widgets.second->size().height();
|
|
|
|
|
|
|
|
QPair<QVector3D, QVector3D> vector;
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
if (reference() == Center) {
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0);
|
|
|
|
vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0);
|
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
if (animDirection == MoveLeft || animDirection == MoveRight) {
|
|
|
|
frontRotation->setAxis(Qt::YAxis);
|
|
|
|
backRotation->setAxis(Qt::YAxis);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
if (animDirection == MoveLeft) {
|
2009-12-05 15:54:06 +01:00
|
|
|
/* TODO: the order way */
|
2009-12-03 20:30:02 +01:00
|
|
|
|
2009-12-05 15:54:06 +01:00
|
|
|
} else {
|
2009-12-08 00:22:47 +01:00
|
|
|
frontStartAngle = 0;
|
|
|
|
frontEndAngle = 90;
|
|
|
|
backStartAngle = 265; //hack
|
|
|
|
backEndAngle = 360;
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
frontRotation->setOrigin(vector.first);
|
|
|
|
backRotation->setOrigin(vector.second);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
QList<QGraphicsTransform *> backTransformation;
|
|
|
|
QList<QGraphicsTransform *> frontTransformation;
|
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
frontTransformation.append(frontRotation);
|
|
|
|
backTransformation.append(backRotation);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
widgets.first->setTransformations(frontTransformation);
|
|
|
|
widgets.second->setTransformations(backTransformation);
|
|
|
|
|
2009-12-05 15:54:06 +01:00
|
|
|
if (oldState == Stopped && newState == Running) {
|
2009-12-08 00:22:47 +01:00
|
|
|
frontRotation->setAngle(direction() == Forward ? frontStartAngle : frontEndAngle);
|
|
|
|
backRotation->setAngle(direction() == Forward ? backStartAngle : backEndAngle);
|
2009-12-05 15:54:06 +01:00
|
|
|
} else if(newState == Stopped) {
|
2009-12-08 00:22:47 +01:00
|
|
|
frontRotation->setAngle(direction() == Forward ? frontEndAngle : frontStartAngle);
|
|
|
|
backRotation->setAngle(direction() == Forward ? backEndAngle : backStartAngle);
|
2009-10-23 20:39:57 +02:00
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-05 15:54:06 +01:00
|
|
|
void RotationStackedAnimation::updateCurrentTime(int currentTime)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2010-01-04 10:18:11 +01:00
|
|
|
QGraphicsWidget *w = targetWidget();
|
2009-12-05 15:54:06 +01:00
|
|
|
if(w) {
|
|
|
|
qreal delta;
|
|
|
|
if (currentTime <= duration()/2) {
|
2009-12-09 17:34:43 +01:00
|
|
|
delta = Animation::easingCurve().valueForProgress(
|
2009-12-08 20:29:03 +01:00
|
|
|
(currentTime * 2) / qreal(duration()));
|
2009-12-08 00:22:47 +01:00
|
|
|
sLayout->setCurrentWidgetIndex(0);
|
|
|
|
delta = frontEndAngle * delta;
|
|
|
|
frontRotation->setAngle(delta);
|
2009-12-05 15:54:06 +01:00
|
|
|
} else {
|
2009-12-09 17:34:43 +01:00
|
|
|
delta = Animation::easingCurve().valueForProgress(
|
2009-12-08 20:29:03 +01:00
|
|
|
(currentTime/2) / qreal(duration()));
|
2009-12-08 00:22:47 +01:00
|
|
|
sLayout->setCurrentWidgetIndex(1);
|
|
|
|
delta = backEndAngle * delta;
|
|
|
|
backRotation->setAngle(delta);
|
2009-11-13 17:41:26 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
}
|