add support for easing curves

svn path=/trunk/KDE/kdelibs/; revision=1060395
This commit is contained in:
Igor Trindade Oliveira 2009-12-08 19:29:03 +00:00
parent 296f30394a
commit 9e736804c9
11 changed files with 25 additions and 15 deletions

View File

@ -69,12 +69,12 @@ QGraphicsWidget* Animation::widgetToAnimate()
return d->animObject.data();
}
void Animation::setEasingCurveType(QEasingCurve::Type easingCurve)
void Animation::setEasingCurve(QEasingCurve easingCurve)
{
d->easingCurve = easingCurve;
}
QEasingCurve::Type Animation::easingCurveType() const
QEasingCurve Animation::easingCurve() const
{
return d->easingCurve;
}

View File

@ -46,7 +46,7 @@ class PLASMA_EXPORT Animation : public QAbstractAnimation
Q_OBJECT
Q_PROPERTY(int duration READ duration WRITE setDuration)
Q_PROPERTY(QEasingCurve::Type easingCurveType READ easingCurveType WRITE setEasingCurveType)
Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve)
Q_PROPERTY(QGraphicsWidget *widgetToAnimate READ widgetToAnimate WRITE setWidgetToAnimate)
public:
@ -82,12 +82,12 @@ public:
/**
* Set the animation easing curve type
*/
void setEasingCurveType(QEasingCurve::Type easingCurve);
void setEasingCurve(QEasingCurve easingCurve);
/**
* Get the animation easing curve type
*/
QEasingCurve::Type easingCurveType() const;
QEasingCurve easingCurve() const;
protected:

View File

@ -88,7 +88,8 @@ void FadeAnimation::updateCurrentTime(int currentTime)
QGraphicsWidget *w = widgetToAnimate();
if (w) {
qreal delta = currentTime / qreal(duration());
delta = (m_startOpacity - m_targetOpacity) * delta;
delta = (m_startOpacity - m_targetOpacity) *
easingCurve().valueForProgress(delta);
w->setOpacity(m_startOpacity - delta);
}

View File

@ -78,7 +78,8 @@ void GeometryAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = widgetToAnimate();
if (w) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
QRectF newGeo = m_startGeometry;
newGeo.adjust((-m_startGeometry.x() + m_targetGeometry.x()) * delta,

View File

@ -44,7 +44,8 @@ void GrowAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = widgetToAnimate();
if (w && state() == QAbstractAnimation::Running) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
QRectF geometry;
geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta));

View File

@ -98,7 +98,8 @@ void PulseAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = under;
if (w) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
delta = (1 - endScale) * delta;
w->setScale(1 - delta);
}

View File

@ -22,6 +22,7 @@
#include "rotation_p.h"
#include <QGraphicsRotation>
#include <QEasingCurve>
#include <kdebug.h>
@ -196,7 +197,8 @@ void RotationAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = widgetToAnimate();
if (w) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
delta = angle() * delta;
d->rotation->setAngle(delta);
}

View File

@ -150,12 +150,14 @@ void RotationStackedAnimation::updateCurrentTime(int currentTime)
if(w) {
qreal delta;
if (currentTime <= duration()/2) {
delta = (currentTime*2)/qreal(duration());
delta = easingCurve().valueForProgress(
(currentTime * 2) / qreal(duration()));
sLayout->setCurrentWidgetIndex(0);
delta = frontEndAngle * delta;
frontRotation->setAngle(delta);
} else {
delta = (currentTime/2) / qreal(duration());
delta = easingCurve().valueForProgress(
(currentTime/2) / qreal(duration()));
sLayout->setCurrentWidgetIndex(1);
delta = backEndAngle * delta;
backRotation->setAngle(delta);

View File

@ -62,7 +62,8 @@ void SlideAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = widgetToAnimate();
if (w && state() == QAbstractAnimation::Running) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
}
}

View File

@ -64,7 +64,8 @@ void ZoomAnimation::updateCurrentTime(int currentTime)
{
QGraphicsWidget *w = widgetToAnimate();
if (w) {
qreal delta = currentTime / qreal(duration());
qreal delta = easingCurve().valueForProgress(
currentTime / qreal(duration()));
delta = (1 - m_zoom) * delta;
w->setScale( 1 - delta);
}

View File

@ -41,7 +41,7 @@ public:
/**
* Animation easing curve type
*/
QEasingCurve::Type easingCurve;
QEasingCurve easingCurve;
/**
* Duration of the animation. Default is 250ms.