From a1bf0fd085e8ffb249557448c5d2d2d5499127f0 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Da Silva Date: Wed, 21 Oct 2009 05:32:04 +0000 Subject: [PATCH] Moving rotation related parameters to common location (now it should be possible to use AbstractAnimation properties to use rotation animation). svn path=/trunk/KDE/kdelibs/; revision=1038337 --- animations/abstractanimation.cpp | 33 ++++++++++++++++ animations/abstractanimation.h | 53 +++++++++++++++++++++++++ animations/rotation.cpp | 58 +++++++--------------------- animations/rotation.h | 23 ----------- private/abstractanimationprivate_p.h | 16 ++++++++ 5 files changed, 116 insertions(+), 67 deletions(-) diff --git a/animations/abstractanimation.cpp b/animations/abstractanimation.cpp index 19bc2acb7..ff9c7f360 100644 --- a/animations/abstractanimation.cpp +++ b/animations/abstractanimation.cpp @@ -88,6 +88,39 @@ bool AbstractAnimation::isVisible() const return d->animVisible; } + +Qt::Axis AbstractAnimation::axis() const +{ + return d->axis; +} + +void AbstractAnimation::setAxis(const Qt::Axis &axis) +{ + d->axis = axis; +} + +qint8 AbstractAnimation::reference() const +{ + return d->reference; +} + +void AbstractAnimation::setReference(const qint8 &reference) +{ + d->reference = reference; +} + +qreal AbstractAnimation::angle() const +{ + return d->angle; +} + +void AbstractAnimation::setAngle(const qreal &angle) +{ + d->angle = angle; +} + + + } //namespace Plasma #include <../abstractanimation.moc> diff --git a/animations/abstractanimation.h b/animations/abstractanimation.h index b3fe91ab6..f445f06a2 100644 --- a/animations/abstractanimation.h +++ b/animations/abstractanimation.h @@ -51,9 +51,26 @@ class PLASMA_EXPORT AbstractAnimation : public QObject Q_PROPERTY(qreal distance READ distance WRITE setDistance) Q_PROPERTY(bool isVisible READ isVisible WRITE setVisible) Q_PROPERTY(QGraphicsWidget *widgetToAnimate READ widgetToAnimate WRITE setWidgetToAnimate) + /** + * TODO: add missing properties (e.g. angle, axis, reference, etc) + */ + Q_PROPERTY(Qt::Axis axis READ axis WRITE setAxis) + Q_PROPERTY(qint8 reference READ reference WRITE setReference) + Q_PROPERTY(qreal angle READ angle WRITE setAngle) + public: + /* FIXME: find a better place and name for it. */ + enum Reference{ + Center, + Up, + Down, + Left, + Right + }; + + AbstractAnimation(QObject *parent = 0); virtual ~AbstractAnimation(); @@ -117,6 +134,42 @@ public: */ bool isVisible() const; + /** + * get animation rotation axis (e.g. YAxis, ZAxis, XAxis) + */ + Qt::Axis axis() const; + + /** + * set animation rotation axis + * @arg axis Rotation (e.g. YAxis, ZAxis, XAxis) + */ + void setAxis(const Qt::Axis &axis); + + /** + * Rotation reference (e.g. Center, Up, Down, Left, Right) can + * be combined (i.e. Center|Up) + */ + qint8 reference() const; + + /** + * Set rotation reference (e.g. Center, Up, Down, Left, Right) can + * be combined (i.e. Center|Up) + * @arg reference The reference + */ + void setReference(const qint8 &reference); + + /** + * Animation rotation angle (e.g. 45, 180, etc) + */ + qreal angle() const; + + /** + * Set animation rotation angle (e.g. 45, 180, etc) + * @arg angle The angle + */ + void setAngle(const qreal &angle); + + public slots: /** diff --git a/animations/rotation.cpp b/animations/rotation.cpp index 62b06eb2e..800907cc3 100644 --- a/animations/rotation.cpp +++ b/animations/rotation.cpp @@ -21,6 +21,9 @@ ///////////////////////////////////////////////////////////////////////// #include "rotation.h" +/* TODO: + * - revise coding style + */ #include namespace Plasma @@ -37,18 +40,15 @@ class RotationAnimationPrivate { } QGraphicsRotation *rotation; - qreal angle; - Qt::Axis axis; - qint8 reference; }; RotationAnimation::RotationAnimation(const qint8 &reference, const Qt::Axis &axis, const qreal &angle) : d(new RotationAnimationPrivate) { - d->angle = angle; - d->axis = axis; - d->reference = reference; + setAngle(angle); + setAxis(axis); + setReference(reference); d->rotation = new QGraphicsRotation(this); } @@ -58,36 +58,6 @@ RotationAnimation::~RotationAnimation() delete d; } -Qt::Axis RotationAnimation::axis() const -{ - return d->axis; -} - -void RotationAnimation::setAxis(const Qt::Axis &axis) -{ - d->axis = axis; -} - -qint8 RotationAnimation::reference() const -{ - return d->reference; -} - -void RotationAnimation::setReference(const qint8 &reference) -{ - d->reference = reference; -} - -qreal RotationAnimation::angle() const -{ - return d->angle; -} - -void RotationAnimation::setAngle(const qreal &angle) -{ - d->angle = angle; -} - QPropertyAnimation *RotationAnimation::render(QObject *parent) { Q_UNUSED(parent); @@ -98,8 +68,8 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) const qreal widgetWidth = m_object->size().width(); const qreal widgetHeight = m_object->size().height(); - if (d->axis == Qt::XAxis) { - switch(d->reference) { + if (axis() == Qt::XAxis) { + switch (reference()) { case Center: vector.setY(widgetHeight/2); break; @@ -110,8 +80,8 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) vector.setY(widgetHeight); break; } - } else if(d->axis == Qt::YAxis) { - switch(d->reference) { + } else if(axis() == Qt::YAxis) { + switch (reference()) { case Center: vector.setX(widgetWidth/2); break; @@ -122,8 +92,8 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) vector.setX(widgetWidth); break; } - }else if (d->axis == Qt::ZAxis) { - switch(d->reference) { + } else if (axis() == Qt::ZAxis) { + switch (reference()) { case Center: vector.setX(widgetWidth/2); vector.setY(widgetHeight/2); @@ -152,7 +122,7 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) } d->rotation->setOrigin(vector); - d->rotation->setAxis(d->axis); + d->rotation->setAxis(axis()); QList transformation; transformation.append(d->rotation); @@ -160,7 +130,7 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) QPropertyAnimation *rotationAnimation= new QPropertyAnimation(d->rotation, "angle", m_object); - rotationAnimation->setEndValue(d->angle); + rotationAnimation->setEndValue(angle()); rotationAnimation->setDuration(duration()); return rotationAnimation; diff --git a/animations/rotation.h b/animations/rotation.h index d74de949e..387307d22 100644 --- a/animations/rotation.h +++ b/animations/rotation.h @@ -31,20 +31,6 @@ class RotationAnimationPrivate; class PLASMA_EXPORT RotationAnimation : public Animation { - Q_OBJECT - Q_PROPERTY(Qt::Axis axis READ axis WRITE setAxis) - Q_PROPERTY(qint8 reference READ reference WRITE setReference) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) - - public: - enum Reference{ - Center, - Up, - Down, - Left, - Right - }; - public: RotationAnimation(const qint8 &reference = Center, const Qt::Axis &axis = Qt::ZAxis, const qreal &angle = 180); @@ -52,15 +38,6 @@ class PLASMA_EXPORT RotationAnimation : public Animation QPropertyAnimation* render(QObject* parent = 0); - Qt::Axis axis() const; - void setAxis(const Qt::Axis &axis); - - qint8 reference() const; - void setReference(const qint8 &reference); - - qreal angle() const; - void setAngle(const qreal &angle); - private: RotationAnimationPrivate *const d; }; diff --git a/private/abstractanimationprivate_p.h b/private/abstractanimationprivate_p.h index 8a6a66374..8960631f1 100644 --- a/private/abstractanimationprivate_p.h +++ b/private/abstractanimationprivate_p.h @@ -57,6 +57,22 @@ public: */ QEasingCurve::Type easingCurve; + /** + * Animation rotation angle (e.g. 45, 180, etc) + */ + qreal angle; + + /** + * Rotation axis (e.g. X, Y, Z) + */ + Qt::Axis axis; + + /** + * Rotation reference (e.g. Center, Up, Down, Left, Right) can + * be combined (i.e. Center|Up) + */ + qint8 reference; + }; }