From 465fe34d773fbcde2e151be91f643f7de58a4b69 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Da Silva Date: Mon, 7 Dec 2009 23:22:47 +0000 Subject: [PATCH] Moved all variables from a pimple to data members in stackedrotation (saves one new/delete operation). svn path=/trunk/KDE/kdelibs/; revision=1060048 --- animations/rotationstacked.cpp | 111 +++++++++++++-------------------- animations/rotationstacked.h | 63 +++++++++++-------- 2 files changed, 83 insertions(+), 91 deletions(-) diff --git a/animations/rotationstacked.cpp b/animations/rotationstacked.cpp index b3f731ef2..48dc4a551 100644 --- a/animations/rotationstacked.cpp +++ b/animations/rotationstacked.cpp @@ -20,11 +20,9 @@ /***********************************************************************/ #include "rotationstacked.h" - #include #include #include - #include #include "stackedlayout.h" @@ -33,77 +31,58 @@ 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 backWidget; - StackedLayout *sLayout; -}; - RotationStackedAnimation::RotationStackedAnimation(QObject *parent) - : Animation(parent), - d(new RotationStackedAnimationPrivate) + : Animation(parent) { - d->backRotation = new QGraphicsRotation(this); - d->frontRotation = new QGraphicsRotation(this); - - d->sLayout = new StackedLayout; -} - -void RotationStackedAnimation::setMovementDirection(const qint8 &direction) -{ - d->animDirection = static_cast(direction); -} - -qint8 RotationStackedAnimation::movementDirection() const -{ - return static_cast(d->animDirection); + backRotation = new QGraphicsRotation(this); + frontRotation = new QGraphicsRotation(this); + sLayout = new StackedLayout; } RotationStackedAnimation::~RotationStackedAnimation() { - delete d; + /* TODO: test what is lacking a parent and delete it */ } +void RotationStackedAnimation::setMovementDirection(const qint8 &direction) +{ + animDirection = static_cast(direction); +} + +qint8 RotationStackedAnimation::movementDirection() const +{ + return static_cast(animDirection); +} + + void RotationStackedAnimation::setReference(const qint8 &reference) { - d->reference = reference; + m_reference = reference; } qint8 RotationStackedAnimation::reference() const { - return d->reference; + return m_reference; } QGraphicsWidget *RotationStackedAnimation::backWidget() { - return d->backWidget.data(); + return m_backWidget.data(); } void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget) { - d->backWidget = backWidget; + m_backWidget = backWidget; if(widgetToAnimate()) { - d->sLayout->addWidget(widgetToAnimate()); - d->sLayout->addWidget(d->backWidget.data()); + sLayout->addWidget(widgetToAnimate()); + sLayout->addWidget(m_backWidget.data()); } - //render(parent()); } QGraphicsLayoutItem *RotationStackedAnimation::layout() { - return d->sLayout; + return sLayout; } void RotationStackedAnimation::updateState( @@ -128,40 +107,40 @@ void RotationStackedAnimation::updateState( 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 (animDirection == MoveLeft || animDirection == MoveRight) { + frontRotation->setAxis(Qt::YAxis); + backRotation->setAxis(Qt::YAxis); - if (d->animDirection == MoveLeft) { + if (animDirection == MoveLeft) { /* TODO: the order way */ } else { - d->frontStartAngle = 0; - d->frontEndAngle = 90; - d->backStartAngle = 265; //hack - d->backEndAngle = 360; + frontStartAngle = 0; + frontEndAngle = 90; + backStartAngle = 265; //hack + backEndAngle = 360; } } } - d->frontRotation->setOrigin(vector.first); - d->backRotation->setOrigin(vector.second); + frontRotation->setOrigin(vector.first); + backRotation->setOrigin(vector.second); QList backTransformation; QList frontTransformation; - frontTransformation.append(d->frontRotation); - backTransformation.append(d->backRotation); + frontTransformation.append(frontRotation); + backTransformation.append(backRotation); widgets.first->setTransformations(frontTransformation); widgets.second->setTransformations(backTransformation); if (oldState == Stopped && newState == Running) { - d->frontRotation->setAngle(direction() == Forward ? d->frontStartAngle : d->frontEndAngle); - d->backRotation->setAngle(direction() == Forward ? d->backStartAngle : d->backEndAngle); + frontRotation->setAngle(direction() == Forward ? frontStartAngle : frontEndAngle); + backRotation->setAngle(direction() == Forward ? backStartAngle : backEndAngle); } else if(newState == Stopped) { - d->frontRotation->setAngle(direction() == Forward ? d->frontEndAngle : d->frontStartAngle); - d->backRotation->setAngle(direction() == Forward ? d->backEndAngle : d->backStartAngle); + frontRotation->setAngle(direction() == Forward ? frontEndAngle : frontStartAngle); + backRotation->setAngle(direction() == Forward ? backEndAngle : backStartAngle); } } @@ -172,14 +151,14 @@ void RotationStackedAnimation::updateCurrentTime(int currentTime) qreal delta; if (currentTime <= duration()/2) { delta = (currentTime*2)/qreal(duration()); - d->sLayout->setCurrentWidgetIndex(0); - delta = d->frontEndAngle * delta; - d->frontRotation->setAngle(delta); + sLayout->setCurrentWidgetIndex(0); + delta = frontEndAngle * delta; + frontRotation->setAngle(delta); } else { delta = (currentTime/2) / qreal(duration()); - d->sLayout->setCurrentWidgetIndex(1); - delta = d->backEndAngle * delta; - d->backRotation->setAngle(delta); + sLayout->setCurrentWidgetIndex(1); + delta = backEndAngle * delta; + backRotation->setAngle(delta); } } } diff --git a/animations/rotationstacked.h b/animations/rotationstacked.h index 28570b937..4f2a1ad9c 100644 --- a/animations/rotationstacked.h +++ b/animations/rotationstacked.h @@ -26,15 +26,14 @@ #include #include +class QGraphicsRotation; +class StackedLayout; namespace Plasma { -class RotationStackedAnimationPrivate; - /* TODO: * create a parent class for rotations */ - class RotationStackedAnimation : public Animation { Q_OBJECT @@ -43,35 +42,49 @@ class RotationStackedAnimation : public Animation Q_PROPERTY(qint8 reference READ reference WRITE setReference) Q_PROPERTY(QGraphicsWidget* backWidget READ backWidget WRITE setBackWidget) - public: - RotationStackedAnimation(QObject *parent = 0); - ~RotationStackedAnimation(); +public: + RotationStackedAnimation(QObject *parent = 0); - /** - * Set the animation direction - * @arg direction animation direction - */ - void setMovementDirection(const qint8 &direction); + ~RotationStackedAnimation(); - /** - * Get the animation direction - */ - qint8 movementDirection() const; + /** + * Set the animation direction + * @arg direction animation direction + */ + void setMovementDirection(const qint8 &direction); - void setReference(const qint8 &reference); - qint8 reference() const; + /** + * Get the animation direction + */ + qint8 movementDirection() const; - QGraphicsLayoutItem *layout(); + void setReference(const qint8 &reference); + qint8 reference() const; - QGraphicsWidget *backWidget(); - void setBackWidget(QGraphicsWidget *backWidget); + QGraphicsLayoutItem *layout(); - protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateCurrentTime(int currentTime); + QGraphicsWidget *backWidget(); + void setBackWidget(QGraphicsWidget *backWidget); + +protected: + void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); + void updateCurrentTime(int currentTime); + +private: + qint8 m_reference; + /** + * Animation direction: where the animation will move. + */ + Plasma::AnimationDirection animDirection; + int frontStartAngle; + int frontEndAngle; + int backStartAngle; + int backEndAngle; + QWeakPointer m_backWidget; + QGraphicsRotation *backRotation; + QGraphicsRotation *frontRotation; + StackedLayout *sLayout; - private: - RotationStackedAnimationPrivate *d; }; } // Plasma