Moved all variables from a pimple to data members in stackedrotation
(saves one new/delete operation). svn path=/trunk/KDE/kdelibs/; revision=1060048
This commit is contained in:
parent
6afab7d906
commit
465fe34d77
@ -20,11 +20,9 @@
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
|
||||||
#include "rotationstacked.h"
|
#include "rotationstacked.h"
|
||||||
|
|
||||||
#include <QGraphicsRotation>
|
#include <QGraphicsRotation>
|
||||||
#include <QSequentialAnimationGroup>
|
#include <QSequentialAnimationGroup>
|
||||||
#include <QWeakPointer>
|
#include <QWeakPointer>
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
#include "stackedlayout.h"
|
#include "stackedlayout.h"
|
||||||
@ -33,77 +31,58 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class RotationStackedAnimationPrivate {
|
|
||||||
public:
|
|
||||||
QGraphicsRotation *backRotation;
|
|
||||||
QGraphicsRotation *frontRotation;
|
|
||||||
int frontStartAngle, frontEndAngle;
|
|
||||||
int backStartAngle, backEndAngle;
|
|
||||||
|
|
||||||
qint8 reference;
|
|
||||||
/**
|
|
||||||
* Animation direction: where the animation will move.
|
|
||||||
*/
|
|
||||||
Plasma::AnimationDirection animDirection;
|
|
||||||
|
|
||||||
QWeakPointer<QGraphicsWidget> backWidget;
|
|
||||||
StackedLayout *sLayout;
|
|
||||||
};
|
|
||||||
|
|
||||||
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
|
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
|
||||||
: Animation(parent),
|
: Animation(parent)
|
||||||
d(new RotationStackedAnimationPrivate)
|
|
||||||
{
|
{
|
||||||
d->backRotation = new QGraphicsRotation(this);
|
backRotation = new QGraphicsRotation(this);
|
||||||
d->frontRotation = new QGraphicsRotation(this);
|
frontRotation = new QGraphicsRotation(this);
|
||||||
|
sLayout = new StackedLayout;
|
||||||
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()
|
RotationStackedAnimation::~RotationStackedAnimation()
|
||||||
{
|
{
|
||||||
delete d;
|
/* TODO: test what is lacking a parent and delete it */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RotationStackedAnimation::setMovementDirection(const qint8 &direction)
|
||||||
|
{
|
||||||
|
animDirection = static_cast<Plasma::AnimationDirection>(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
qint8 RotationStackedAnimation::movementDirection() const
|
||||||
|
{
|
||||||
|
return static_cast<qint8>(animDirection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotationStackedAnimation::setReference(const qint8 &reference)
|
void RotationStackedAnimation::setReference(const qint8 &reference)
|
||||||
{
|
{
|
||||||
d->reference = reference;
|
m_reference = reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint8 RotationStackedAnimation::reference() const
|
qint8 RotationStackedAnimation::reference() const
|
||||||
{
|
{
|
||||||
return d->reference;
|
return m_reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsWidget *RotationStackedAnimation::backWidget()
|
QGraphicsWidget *RotationStackedAnimation::backWidget()
|
||||||
{
|
{
|
||||||
return d->backWidget.data();
|
return m_backWidget.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
|
void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
|
||||||
{
|
{
|
||||||
d->backWidget = backWidget;
|
m_backWidget = backWidget;
|
||||||
|
|
||||||
if(widgetToAnimate()) {
|
if(widgetToAnimate()) {
|
||||||
d->sLayout->addWidget(widgetToAnimate());
|
sLayout->addWidget(widgetToAnimate());
|
||||||
d->sLayout->addWidget(d->backWidget.data());
|
sLayout->addWidget(m_backWidget.data());
|
||||||
}
|
}
|
||||||
//render(parent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsLayoutItem *RotationStackedAnimation::layout()
|
QGraphicsLayoutItem *RotationStackedAnimation::layout()
|
||||||
{
|
{
|
||||||
return d->sLayout;
|
return sLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotationStackedAnimation::updateState(
|
void RotationStackedAnimation::updateState(
|
||||||
@ -128,40 +107,40 @@ void RotationStackedAnimation::updateState(
|
|||||||
vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0);
|
vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0);
|
||||||
vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0);
|
vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0);
|
||||||
|
|
||||||
if (d->animDirection == MoveLeft || d->animDirection == MoveRight) {
|
if (animDirection == MoveLeft || animDirection == MoveRight) {
|
||||||
d->frontRotation->setAxis(Qt::YAxis);
|
frontRotation->setAxis(Qt::YAxis);
|
||||||
d->backRotation->setAxis(Qt::YAxis);
|
backRotation->setAxis(Qt::YAxis);
|
||||||
|
|
||||||
if (d->animDirection == MoveLeft) {
|
if (animDirection == MoveLeft) {
|
||||||
/* TODO: the order way */
|
/* TODO: the order way */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
d->frontStartAngle = 0;
|
frontStartAngle = 0;
|
||||||
d->frontEndAngle = 90;
|
frontEndAngle = 90;
|
||||||
d->backStartAngle = 265; //hack
|
backStartAngle = 265; //hack
|
||||||
d->backEndAngle = 360;
|
backEndAngle = 360;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->frontRotation->setOrigin(vector.first);
|
frontRotation->setOrigin(vector.first);
|
||||||
d->backRotation->setOrigin(vector.second);
|
backRotation->setOrigin(vector.second);
|
||||||
|
|
||||||
QList<QGraphicsTransform *> backTransformation;
|
QList<QGraphicsTransform *> backTransformation;
|
||||||
QList<QGraphicsTransform *> frontTransformation;
|
QList<QGraphicsTransform *> frontTransformation;
|
||||||
|
|
||||||
frontTransformation.append(d->frontRotation);
|
frontTransformation.append(frontRotation);
|
||||||
backTransformation.append(d->backRotation);
|
backTransformation.append(backRotation);
|
||||||
|
|
||||||
widgets.first->setTransformations(frontTransformation);
|
widgets.first->setTransformations(frontTransformation);
|
||||||
widgets.second->setTransformations(backTransformation);
|
widgets.second->setTransformations(backTransformation);
|
||||||
|
|
||||||
if (oldState == Stopped && newState == Running) {
|
if (oldState == Stopped && newState == Running) {
|
||||||
d->frontRotation->setAngle(direction() == Forward ? d->frontStartAngle : d->frontEndAngle);
|
frontRotation->setAngle(direction() == Forward ? frontStartAngle : frontEndAngle);
|
||||||
d->backRotation->setAngle(direction() == Forward ? d->backStartAngle : d->backEndAngle);
|
backRotation->setAngle(direction() == Forward ? backStartAngle : backEndAngle);
|
||||||
} else if(newState == Stopped) {
|
} else if(newState == Stopped) {
|
||||||
d->frontRotation->setAngle(direction() == Forward ? d->frontEndAngle : d->frontStartAngle);
|
frontRotation->setAngle(direction() == Forward ? frontEndAngle : frontStartAngle);
|
||||||
d->backRotation->setAngle(direction() == Forward ? d->backEndAngle : d->backStartAngle);
|
backRotation->setAngle(direction() == Forward ? backEndAngle : backStartAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,14 +151,14 @@ void RotationStackedAnimation::updateCurrentTime(int currentTime)
|
|||||||
qreal delta;
|
qreal delta;
|
||||||
if (currentTime <= duration()/2) {
|
if (currentTime <= duration()/2) {
|
||||||
delta = (currentTime*2)/qreal(duration());
|
delta = (currentTime*2)/qreal(duration());
|
||||||
d->sLayout->setCurrentWidgetIndex(0);
|
sLayout->setCurrentWidgetIndex(0);
|
||||||
delta = d->frontEndAngle * delta;
|
delta = frontEndAngle * delta;
|
||||||
d->frontRotation->setAngle(delta);
|
frontRotation->setAngle(delta);
|
||||||
} else {
|
} else {
|
||||||
delta = (currentTime/2) / qreal(duration());
|
delta = (currentTime/2) / qreal(duration());
|
||||||
d->sLayout->setCurrentWidgetIndex(1);
|
sLayout->setCurrentWidgetIndex(1);
|
||||||
delta = d->backEndAngle * delta;
|
delta = backEndAngle * delta;
|
||||||
d->backRotation->setAngle(delta);
|
backRotation->setAngle(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,14 @@
|
|||||||
#include <plasma/plasma_export.h>
|
#include <plasma/plasma_export.h>
|
||||||
|
|
||||||
#include <QGraphicsLayoutItem>
|
#include <QGraphicsLayoutItem>
|
||||||
|
class QGraphicsRotation;
|
||||||
|
class StackedLayout;
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
class RotationStackedAnimationPrivate;
|
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* create a parent class for rotations
|
* create a parent class for rotations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RotationStackedAnimation : public Animation
|
class RotationStackedAnimation : public Animation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -43,8 +42,9 @@ class RotationStackedAnimation : public Animation
|
|||||||
Q_PROPERTY(qint8 reference READ reference WRITE setReference)
|
Q_PROPERTY(qint8 reference READ reference WRITE setReference)
|
||||||
Q_PROPERTY(QGraphicsWidget* backWidget READ backWidget WRITE setBackWidget)
|
Q_PROPERTY(QGraphicsWidget* backWidget READ backWidget WRITE setBackWidget)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RotationStackedAnimation(QObject *parent = 0);
|
RotationStackedAnimation(QObject *parent = 0);
|
||||||
|
|
||||||
~RotationStackedAnimation();
|
~RotationStackedAnimation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,12 +66,25 @@ class RotationStackedAnimation : public Animation
|
|||||||
QGraphicsWidget *backWidget();
|
QGraphicsWidget *backWidget();
|
||||||
void setBackWidget(QGraphicsWidget *backWidget);
|
void setBackWidget(QGraphicsWidget *backWidget);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||||
void updateCurrentTime(int currentTime);
|
void updateCurrentTime(int currentTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RotationStackedAnimationPrivate *d;
|
qint8 m_reference;
|
||||||
|
/**
|
||||||
|
* Animation direction: where the animation will move.
|
||||||
|
*/
|
||||||
|
Plasma::AnimationDirection animDirection;
|
||||||
|
int frontStartAngle;
|
||||||
|
int frontEndAngle;
|
||||||
|
int backStartAngle;
|
||||||
|
int backEndAngle;
|
||||||
|
QWeakPointer<QGraphicsWidget> m_backWidget;
|
||||||
|
QGraphicsRotation *backRotation;
|
||||||
|
QGraphicsRotation *frontRotation;
|
||||||
|
StackedLayout *sLayout;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // Plasma
|
} // Plasma
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user