plasma-framework/animations/rotationstacked.cpp
Adenilson Cavalcanti Da Silva 818e93a576 Amazon sized patch... So many changes that I can hardly remember what they are,
but this is the list from what I can recall:
- removing expand animation (it is a case of grow animation)
- removing AbstractAnimation and using QAbstractAnimation as the common base
- animations are non longer factories, but real animation (so it is just no
issue to mesh then with user created animations)
- animation group will correctly revert the direction of all subanimations
(useful for rewinding an animation)
- fixed opacity effect in pulse animation (now it works correctly)
- there is not 'forward' property, but animation 'direction' (this is how
rewinding an animation must be done)
- direction now is movementDirection property (used in SlideAnimation and RotationStacked)
- the weakpointer for the actual animaiton is non longer in AnimationPrivate but
in each specialized animation class
- hide property is being removed (in progress) since it really is a case of Fade

I guess this is it, now is just a matter of iron out the remaining bugs and polish
the public API.



svn path=/trunk/KDE/kdelibs/; revision=1057993
2009-12-03 19:30:02 +00:00

217 lines
6.9 KiB
C++

/***********************************************************************/
/* rotationstacked.h */
/* */
/* 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, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */
/* 02110-1301 USA */
/***********************************************************************/
#include "rotationstacked.h"
#include "stackedlayout.h"
#include <QGraphicsRotation>
#include <QSequentialAnimationGroup>
#include <QWeakPointer>
#include <kdebug.h>
namespace Plasma
{
class RotationStackedAnimationPrivate {
public:
QGraphicsRotation *backRotation;
QGraphicsRotation *frontRotation;
qint8 reference;
/**
* Animation direction: where the animation will move.
*/
Plasma::AnimationDirection animDirection;
QWeakPointer<QGraphicsWidget> backWidget;
StackedLayout *sLayout;
QWeakPointer<QSequentialAnimationGroup> animation;
};
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
: Animation(parent),
d(new RotationStackedAnimationPrivate)
{
d->backRotation = new QGraphicsRotation(this);
d->frontRotation = new QGraphicsRotation(this);
d->sLayout = new StackedLayout;
}
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
{
d->animDirection = static_cast<Plasma::AnimationDirection>(direction);
}
qint8 RotationStackedAnimation::movementDirection() const
{
return static_cast<qint8>(d->animDirection);
}
RotationStackedAnimation::~RotationStackedAnimation()
{
delete d;
}
void RotationStackedAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
{
Animation::setWidgetToAnimate(widget);
if (d->animation.data()) {
delete d->animation.data();
d->animation.clear();
}
}
void RotationStackedAnimation::setReference(const qint8 &reference)
{
d->reference = reference;
}
qint8 RotationStackedAnimation::reference() const
{
return d->reference;
}
QGraphicsWidget *RotationStackedAnimation::backWidget()
{
return d->backWidget.data();
}
void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
{
d->backWidget = backWidget;
if(widgetToAnimate()) {
d->sLayout->addWidget(widgetToAnimate());
d->sLayout->addWidget(d->backWidget.data());
}
render(parent());
}
QGraphicsLayoutItem *RotationStackedAnimation::layout()
{
return d->sLayout;
}
QAbstractAnimation *RotationStackedAnimation::render(QObject *parent)
{
Q_UNUSED(parent);
bool dirty = false;
if (!backWidget()) {
return d->animation.data();
}
QPair<QGraphicsWidget *,QGraphicsWidget *> widgets = qMakePair(widgetToAnimate(), backWidget());
QPropertyAnimation *frontAnim, *backAnim;
QSequentialAnimationGroup *groupAnim = d->animation.data();
if (!groupAnim) {
groupAnim = new QSequentialAnimationGroup(parent);
frontAnim = new QPropertyAnimation(d->frontRotation, "angle", groupAnim);
backAnim = new QPropertyAnimation(d->backRotation, "angle", groupAnim);
d->animation = groupAnim;
dirty = true;
} else {
if (groupAnim->animationCount() == 2) {
frontAnim = dynamic_cast<QPropertyAnimation* >(groupAnim->animationAt(0));
backAnim = dynamic_cast<QPropertyAnimation* >(groupAnim->animationAt(1));
} else {
kDebug() << "_ Where are my little animations? Duh!";
return groupAnim;
}
}
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;
if (reference() == Center) {
vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0);
vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0);
if (d->animDirection == MoveLeft || d->animDirection == MoveRight) {
d->frontRotation->setAxis(Qt::YAxis);
d->backRotation->setAxis(Qt::YAxis);
if (d->animDirection == MoveLeft) {
/* TODO: the order way */
} else {
d->backRotation->setAngle(265);
backAnim->setStartValue(d->backRotation->angle());
frontAnim->setStartValue(0);
backAnim->setEndValue(360);
frontAnim->setEndValue(90);
}
}
}
d->frontRotation->setOrigin(vector.first);
d->backRotation->setOrigin(vector.second);
QList<QGraphicsTransform *> backTransformation;
QList<QGraphicsTransform *> frontTransformation;
frontTransformation.append(d->frontRotation);
backTransformation.append(d->backRotation);
widgets.first->setTransformations(frontTransformation);
widgets.second->setTransformations(backTransformation);
frontAnim->setDuration(duration()/2);
backAnim->setDuration(duration()/2);
if (dirty) {
connect(frontAnim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)),
this, SLOT(animationStateChange(QAbstractAnimation::State, QAbstractAnimation::State)));
groupAnim->addAnimation(frontAnim);
groupAnim->addAnimation(backAnim);
}
return groupAnim;
}
void RotationStackedAnimation::animationStateChange(
QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
{
Q_UNUSED(oldState);
if (direction() == QAbstractAnimation::Backward) {
if ((newState == QAbstractAnimation::Running) &&
(oldState == QAbstractAnimation::Stopped)) {
d->sLayout->setCurrentWidgetIndex(0);
}
} else {
if((newState == QAbstractAnimation::Stopped) &&
(oldState == QAbstractAnimation::Running)) {
d->sLayout->setCurrentWidgetIndex(1);
}
}
}
}