diff --git a/animations/rotation.cpp b/animations/rotation.cpp index dbe46b271..5e951fcda 100644 --- a/animations/rotation.cpp +++ b/animations/rotation.cpp @@ -51,19 +51,15 @@ public: * be combined (i.e. Center|Up) */ qint8 reference; - - QWeakPointer animation; - - }; void RotationAnimation::setWidgetToAnimate(QGraphicsWidget *widget) { - Animation::setWidgetToAnimate(widget); - if (d->animation.data()) { - delete d->animation.data(); - d->animation.clear(); + if(widget == widgetToAnimate()) { + return; } + + Animation::setWidgetToAnimate(widget); } RotationAnimation::RotationAnimation(QObject *parent, @@ -84,11 +80,44 @@ RotationAnimation::~RotationAnimation() delete d; } -QPropertyAnimation *RotationAnimation::render(QObject *parent) +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; +} + +void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { - Q_UNUSED(parent); QGraphicsWidget *m_object = widgetToAnimate(); + if (!m_object) { + return; + } + QVector3D vector(0, 0, 0); const qreal widgetWidth = m_object->size().width(); @@ -156,47 +185,21 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent) transformation.append(d->rotation); m_object->setTransformations(transformation); - QPropertyAnimation *rotationAnimation = d->animation.data(); - if (!rotationAnimation) { - rotationAnimation = new QPropertyAnimation(d->rotation, "angle", m_object); - d->animation = rotationAnimation; + if ((oldState == Stopped) && (newState == Running)) { + d->rotation->setAngle(direction() == Forward ? 0 : angle()); + } else if (newState == Stopped) { + d->rotation->setAngle(direction() == Forward ? angle() : 0); } - - rotationAnimation->setStartValue(0); - rotationAnimation->setEndValue(angle()); - rotationAnimation->setDuration(duration()); - - return rotationAnimation; } -Qt::Axis RotationAnimation::axis() const +void RotationAnimation::updateCurrentTime(int currentTime) { - 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; + QGraphicsWidget *w = widgetToAnimate(); + if (w) { + qreal delta = currentTime / qreal(duration()); + delta = angle() * delta; + d->rotation->setAngle(delta); + } } } diff --git a/animations/rotation_p.h b/animations/rotation_p.h index 8806f585c..5d3bf300d 100644 --- a/animations/rotation_p.h +++ b/animations/rotation_p.h @@ -87,6 +87,10 @@ public: void setWidgetToAnimate(QGraphicsWidget *widget); +protected: + void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); + void updateCurrentTime(int currentTime); + private: RotationAnimationPrivate *const d; };