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
|
|
|
{
|
2010-01-12 23:27:23 +01:00
|
|
|
m_backRotation = new QGraphicsRotation(this);
|
|
|
|
m_frontRotation = new QGraphicsRotation(this);
|
2010-01-29 22:00:57 +01:00
|
|
|
m_wLayout = new StackedLayout;
|
2009-12-08 00:22:47 +01:00
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2009-12-08 00:22:47 +01:00
|
|
|
RotationStackedAnimation::~RotationStackedAnimation()
|
|
|
|
{
|
2010-01-29 22:00:57 +01:00
|
|
|
delete m_wLayout.data();
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-03 20:30:02 +01:00
|
|
|
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
|
|
|
|
{
|
2010-01-12 23:27:23 +01:00
|
|
|
m_animDirection = static_cast<MovementDirection>(direction);
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qint8 RotationStackedAnimation::movementDirection() const
|
|
|
|
{
|
2010-01-12 23:27:23 +01:00
|
|
|
return static_cast<qint8>(m_animDirection);
|
2009-12-03 20:30:02 +01: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-29 22:00:57 +01:00
|
|
|
StackedLayout *layout = m_wLayout.data();
|
|
|
|
|
|
|
|
if(targetWidget() && backWidget && layout) {
|
|
|
|
layout->addWidget(targetWidget());
|
|
|
|
layout->addWidget(backWidget);
|
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
|
|
|
{
|
2010-01-29 22:00:57 +01:00
|
|
|
return m_wLayout.data();
|
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);
|
|
|
|
|
2010-01-12 23:27:23 +01:00
|
|
|
if (m_animDirection == MoveLeft || m_animDirection == MoveRight) {
|
|
|
|
m_frontRotation->setAxis(Qt::YAxis);
|
|
|
|
m_backRotation->setAxis(Qt::YAxis);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2010-01-12 23:27:23 +01:00
|
|
|
if (m_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 {
|
2010-01-12 23:27:23 +01:00
|
|
|
m_frontStartAngle = 0;
|
|
|
|
m_frontEndAngle = 90;
|
|
|
|
m_backStartAngle = 265; //hack
|
|
|
|
m_backEndAngle = 360;
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 23:27:23 +01:00
|
|
|
m_frontRotation->setOrigin(vector.first);
|
|
|
|
m_backRotation->setOrigin(vector.second);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
QList<QGraphicsTransform *> backTransformation;
|
|
|
|
QList<QGraphicsTransform *> frontTransformation;
|
|
|
|
|
2010-01-12 23:27:23 +01:00
|
|
|
frontTransformation.append(m_frontRotation);
|
|
|
|
backTransformation.append(m_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) {
|
2010-01-12 23:27:23 +01:00
|
|
|
m_frontRotation->setAngle(direction() == Forward ? m_frontStartAngle : m_frontEndAngle);
|
|
|
|
m_backRotation->setAngle(direction() == Forward ? m_backStartAngle : m_backEndAngle);
|
2009-12-05 15:54:06 +01:00
|
|
|
} else if(newState == Stopped) {
|
2010-01-12 23:27:23 +01:00
|
|
|
m_frontRotation->setAngle(direction() == Forward ? m_frontEndAngle : m_frontStartAngle);
|
|
|
|
m_backRotation->setAngle(direction() == Forward ? m_backEndAngle : m_backStartAngle);
|
|
|
|
}
|
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-29 22:00:57 +01:00
|
|
|
StackedLayout *layout = m_wLayout.data();
|
|
|
|
if (!layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *w = targetWidget();
|
|
|
|
if (w) {
|
|
|
|
qreal delta;
|
|
|
|
if (currentTime <= duration()/2) {
|
|
|
|
delta = Animation::easingCurve().valueForProgress(
|
|
|
|
(currentTime * 2) / qreal(duration()));
|
|
|
|
layout->setCurrentWidgetIndex(0);
|
|
|
|
delta = m_frontEndAngle * delta;
|
2010-01-12 23:27:23 +01:00
|
|
|
m_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()));
|
2010-01-29 22:00:57 +01:00
|
|
|
layout->setCurrentWidgetIndex(1);
|
2010-01-12 23:27:23 +01:00
|
|
|
delta = m_backEndAngle * delta;
|
|
|
|
m_backRotation->setAngle(delta);
|
2009-11-13 17:41:26 +01:00
|
|
|
}
|
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
}
|