port rotationanimation to new animation design: remove render and qpropertyanimation

svn path=/trunk/KDE/kdelibs/; revision=1058636
This commit is contained in:
Igor Trindade Oliveira 2009-12-04 20:49:09 +00:00
parent d6ce82052f
commit 61adef1780
2 changed files with 54 additions and 47 deletions

View File

@ -51,19 +51,15 @@ public:
* be combined (i.e. Center|Up) * be combined (i.e. Center|Up)
*/ */
qint8 reference; qint8 reference;
QWeakPointer<QPropertyAnimation> animation;
}; };
void RotationAnimation::setWidgetToAnimate(QGraphicsWidget *widget) void RotationAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
{ {
Animation::setWidgetToAnimate(widget); if(widget == widgetToAnimate()) {
if (d->animation.data()) { return;
delete d->animation.data();
d->animation.clear();
} }
Animation::setWidgetToAnimate(widget);
} }
RotationAnimation::RotationAnimation(QObject *parent, RotationAnimation::RotationAnimation(QObject *parent,
@ -84,11 +80,44 @@ RotationAnimation::~RotationAnimation()
delete d; 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(); QGraphicsWidget *m_object = widgetToAnimate();
if (!m_object) {
return;
}
QVector3D vector(0, 0, 0); QVector3D vector(0, 0, 0);
const qreal widgetWidth = m_object->size().width(); const qreal widgetWidth = m_object->size().width();
@ -156,47 +185,21 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent)
transformation.append(d->rotation); transformation.append(d->rotation);
m_object->setTransformations(transformation); m_object->setTransformations(transformation);
QPropertyAnimation *rotationAnimation = d->animation.data(); if ((oldState == Stopped) && (newState == Running)) {
if (!rotationAnimation) { d->rotation->setAngle(direction() == Forward ? 0 : angle());
rotationAnimation = new QPropertyAnimation(d->rotation, "angle", m_object); } else if (newState == Stopped) {
d->animation = rotationAnimation; 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; QGraphicsWidget *w = widgetToAnimate();
} if (w) {
qreal delta = currentTime / qreal(duration());
void RotationAnimation::setAxis(const Qt::Axis &axis) delta = angle() * delta;
{ d->rotation->setAngle(delta);
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;
} }
} }

View File

@ -87,6 +87,10 @@ public:
void setWidgetToAnimate(QGraphicsWidget *widget); void setWidgetToAnimate(QGraphicsWidget *widget);
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
private: private:
RotationAnimationPrivate *const d; RotationAnimationPrivate *const d;
}; };