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
|
|
|
|
{
|
|
|
|
|
2010-01-31 16:54:14 +01:00
|
|
|
const int RotationStackedAnimation::s_sideAngle = 90;
|
|
|
|
|
2009-10-22 22:17:07 +02:00
|
|
|
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
|
2010-04-08 19:07:33 +02:00
|
|
|
: EasingAnimation(parent)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2010-01-12 23:24:58 +01:00
|
|
|
m_backRotation = new QGraphicsRotation(this);
|
|
|
|
m_frontRotation = new QGraphicsRotation(this);
|
2010-01-29 21:36:32 +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 21:36:32 +01:00
|
|
|
delete m_wLayout.data();
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
void RotationStackedAnimation::setMovementDirection(const Animation::MovementDirection &direction)
|
2009-12-03 20:30:02 +01:00
|
|
|
{
|
2010-02-01 19:01:40 +01:00
|
|
|
m_animDirection = direction;
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
|
|
|
|
QVector3D animDirection(0, 0, 0);
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animDirection.testFlag(MoveUp)) {
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
animDirection.setX(1);
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animDirection.testFlag(MoveDown)) {
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
animDirection.setX(-1);
|
2010-02-01 19:01:40 +01:00
|
|
|
}
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animDirection.testFlag(MoveLeft)) {
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
animDirection.setY(-1);
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animDirection.testFlag(MoveRight)) {
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
animDirection.setY(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frontRotation->setAxis(animDirection);
|
|
|
|
m_backRotation->setAxis(animDirection);
|
|
|
|
|
|
|
|
updateTransformations();
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
Animation::MovementDirection RotationStackedAnimation::movementDirection() const
|
2009-12-03 20:30:02 +01:00
|
|
|
{
|
2010-02-01 19:01:40 +01:00
|
|
|
return m_animDirection;
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
void RotationStackedAnimation::setReference(const Animation::Reference &reference)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2010-02-01 19:01:40 +01:00
|
|
|
m_animReference = reference;
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
|
|
|
|
if (!targetWidget() || !backWidget()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-27 21:43:56 +01:00
|
|
|
const QSizeF transformArea = targetWidget()->size().expandedTo(backWidget()->size());
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
|
2010-01-27 21:43:56 +01:00
|
|
|
QVector3D frontTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0);
|
|
|
|
QVector3D backTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0);
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animReference.testFlag(Up)) {
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
frontTransformOrigin.setY(0);
|
|
|
|
backTransformOrigin.setY(0);
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animReference.testFlag(Down)) {
|
2010-01-27 21:43:56 +01:00
|
|
|
frontTransformOrigin.setY(transformArea.height());
|
|
|
|
backTransformOrigin.setY(transformArea.height());
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
if (m_animReference.testFlag(Left)) {
|
2010-02-01 19:01:40 +01:00
|
|
|
frontTransformOrigin.setX(0);
|
|
|
|
backTransformOrigin.setX(0);
|
2010-02-02 14:36:23 +01:00
|
|
|
} else if (m_animReference.testFlag(Right)) {
|
2010-02-01 19:01:40 +01:00
|
|
|
frontTransformOrigin.setX(transformArea.width());
|
|
|
|
backTransformOrigin.setX(transformArea.width());
|
|
|
|
}
|
|
|
|
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
m_frontRotation->setOrigin(frontTransformOrigin);
|
|
|
|
m_backRotation->setOrigin(backTransformOrigin);
|
|
|
|
|
|
|
|
updateTransformations();
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2010-02-02 14:36:23 +01:00
|
|
|
Animation::Reference RotationStackedAnimation::reference() const
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
2010-02-01 19:01:40 +01:00
|
|
|
return m_animReference;
|
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 21:36:32 +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 21:36:32 +01:00
|
|
|
return m_wLayout.data();
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 21:43:56 +01:00
|
|
|
void RotationStackedAnimation::updateState(QAbstractAnimation::State newState,
|
|
|
|
QAbstractAnimation::State oldState)
|
|
|
|
{
|
|
|
|
if (oldState == Stopped && newState == Running) {
|
|
|
|
setReference(reference());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-08 19:07:33 +02:00
|
|
|
void RotationStackedAnimation::updateEffectiveTime(int currentTime)
|
2009-10-22 22:17:07 +02:00
|
|
|
{
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
if (!targetWidget() || !backWidget()) {
|
2009-12-05 15:54:06 +01:00
|
|
|
return;
|
2009-12-03 20:30:02 +01:00
|
|
|
}
|
|
|
|
|
2010-01-29 21:36:32 +01:00
|
|
|
StackedLayout *layout = m_wLayout.data();
|
|
|
|
if (!layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
qreal delta;
|
|
|
|
if (currentTime <= duration()/2) {
|
2010-01-29 21:36:32 +01:00
|
|
|
layout->setCurrentWidgetIndex(0);
|
2010-04-23 15:38:38 +02:00
|
|
|
delta = (currentTime*2) / qreal(duration());
|
2010-01-31 16:54:14 +01:00
|
|
|
delta *= s_sideAngle;
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
m_frontRotation->setAngle(delta);
|
|
|
|
} else {
|
2010-01-29 21:36:32 +01:00
|
|
|
layout->setCurrentWidgetIndex(1);
|
2010-04-23 15:38:38 +02:00
|
|
|
delta = 1 - (((currentTime*2) - duration()) / qreal(duration()));
|
2010-01-27 21:43:56 +01:00
|
|
|
delta = -delta;
|
2010-01-31 16:54:14 +01:00
|
|
|
delta *= s_sideAngle;
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
m_backRotation->setAngle(delta);
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
void RotationStackedAnimation::updateTransformations()
|
|
|
|
{
|
|
|
|
if (!targetWidget() || !backWidget()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
QList<QGraphicsTransform *> frontTransformation;
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
QList<QGraphicsTransform *> backTransformation;
|
2009-10-22 22:17:07 +02:00
|
|
|
|
2010-01-12 23:24:58 +01:00
|
|
|
frontTransformation.append(m_frontRotation);
|
|
|
|
backTransformation.append(m_backRotation);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
updates, cleans up and finishes the remaining Plasma::RotationStackedAnimation transformations. Now every combination of animation origin ( Up, Up | Left, Up | Right, Down, Down | Left, Down | Right, Left, Right) works with the animation movement directions ( MoveUp, MoveUpLeft, MoveUpRight, MoveDown, MoveDownLeft, MoveDownRight, MoveLeft, MoveRight).
Patch by: Bruno Abinader <brunoabinader@gmail.com>
svn path=/trunk/KDE/kdelibs/; revision=1080054
2010-01-25 14:37:57 +01:00
|
|
|
targetWidget()->setTransformations(frontTransformation);
|
|
|
|
backWidget()->setTransformations(backTransformation);
|
2009-10-22 22:17:07 +02:00
|
|
|
}
|
2010-02-24 00:31:45 +01:00
|
|
|
|
|
|
|
} //namespace Plasma
|
|
|
|
|
2012-01-22 15:37:37 +01:00
|
|
|
#include "moc_rotationstacked_p.cpp"
|