add support for easing curves
svn path=/trunk/KDE/kdelibs/; revision=1060395
This commit is contained in:
parent
296f30394a
commit
9e736804c9
@ -69,12 +69,12 @@ QGraphicsWidget* Animation::widgetToAnimate()
|
|||||||
return d->animObject.data();
|
return d->animObject.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::setEasingCurveType(QEasingCurve::Type easingCurve)
|
void Animation::setEasingCurve(QEasingCurve easingCurve)
|
||||||
{
|
{
|
||||||
d->easingCurve = easingCurve;
|
d->easingCurve = easingCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
QEasingCurve::Type Animation::easingCurveType() const
|
QEasingCurve Animation::easingCurve() const
|
||||||
{
|
{
|
||||||
return d->easingCurve;
|
return d->easingCurve;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class PLASMA_EXPORT Animation : public QAbstractAnimation
|
|||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int duration READ duration WRITE setDuration)
|
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)
|
Q_PROPERTY(QGraphicsWidget *widgetToAnimate READ widgetToAnimate WRITE setWidgetToAnimate)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -82,12 +82,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Set the animation easing curve type
|
* Set the animation easing curve type
|
||||||
*/
|
*/
|
||||||
void setEasingCurveType(QEasingCurve::Type easingCurve);
|
void setEasingCurve(QEasingCurve easingCurve);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the animation easing curve type
|
* Get the animation easing curve type
|
||||||
*/
|
*/
|
||||||
QEasingCurve::Type easingCurveType() const;
|
QEasingCurve easingCurve() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ void FadeAnimation::updateCurrentTime(int currentTime)
|
|||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = currentTime / qreal(duration());
|
||||||
delta = (m_startOpacity - m_targetOpacity) * delta;
|
delta = (m_startOpacity - m_targetOpacity) *
|
||||||
|
easingCurve().valueForProgress(delta);
|
||||||
w->setOpacity(m_startOpacity - delta);
|
w->setOpacity(m_startOpacity - delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,8 @@ void GeometryAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(
|
||||||
|
currentTime / qreal(duration()));
|
||||||
|
|
||||||
QRectF newGeo = m_startGeometry;
|
QRectF newGeo = m_startGeometry;
|
||||||
newGeo.adjust((-m_startGeometry.x() + m_targetGeometry.x()) * delta,
|
newGeo.adjust((-m_startGeometry.x() + m_targetGeometry.x()) * delta,
|
||||||
|
@ -44,7 +44,8 @@ void GrowAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w && state() == QAbstractAnimation::Running) {
|
if (w && state() == QAbstractAnimation::Running) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(
|
||||||
|
currentTime / qreal(duration()));
|
||||||
QRectF geometry;
|
QRectF geometry;
|
||||||
geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
|
geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
|
||||||
geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta));
|
geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta));
|
||||||
|
@ -98,7 +98,8 @@ void PulseAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = under;
|
QGraphicsWidget *w = under;
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(
|
||||||
|
currentTime / qreal(duration()));
|
||||||
delta = (1 - endScale) * delta;
|
delta = (1 - endScale) * delta;
|
||||||
w->setScale(1 - delta);
|
w->setScale(1 - delta);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "rotation_p.h"
|
#include "rotation_p.h"
|
||||||
|
|
||||||
#include <QGraphicsRotation>
|
#include <QGraphicsRotation>
|
||||||
|
#include <QEasingCurve>
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
@ -196,7 +197,8 @@ void RotationAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(
|
||||||
|
currentTime / qreal(duration()));
|
||||||
delta = angle() * delta;
|
delta = angle() * delta;
|
||||||
d->rotation->setAngle(delta);
|
d->rotation->setAngle(delta);
|
||||||
}
|
}
|
||||||
|
@ -150,12 +150,14 @@ void RotationStackedAnimation::updateCurrentTime(int currentTime)
|
|||||||
if(w) {
|
if(w) {
|
||||||
qreal delta;
|
qreal delta;
|
||||||
if (currentTime <= duration()/2) {
|
if (currentTime <= duration()/2) {
|
||||||
delta = (currentTime*2)/qreal(duration());
|
delta = easingCurve().valueForProgress(
|
||||||
|
(currentTime * 2) / qreal(duration()));
|
||||||
sLayout->setCurrentWidgetIndex(0);
|
sLayout->setCurrentWidgetIndex(0);
|
||||||
delta = frontEndAngle * delta;
|
delta = frontEndAngle * delta;
|
||||||
frontRotation->setAngle(delta);
|
frontRotation->setAngle(delta);
|
||||||
} else {
|
} else {
|
||||||
delta = (currentTime/2) / qreal(duration());
|
delta = easingCurve().valueForProgress(
|
||||||
|
(currentTime/2) / qreal(duration()));
|
||||||
sLayout->setCurrentWidgetIndex(1);
|
sLayout->setCurrentWidgetIndex(1);
|
||||||
delta = backEndAngle * delta;
|
delta = backEndAngle * delta;
|
||||||
backRotation->setAngle(delta);
|
backRotation->setAngle(delta);
|
||||||
|
@ -62,7 +62,8 @@ void SlideAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w && state() == QAbstractAnimation::Running) {
|
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));
|
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ void ZoomAnimation::updateCurrentTime(int currentTime)
|
|||||||
{
|
{
|
||||||
QGraphicsWidget *w = widgetToAnimate();
|
QGraphicsWidget *w = widgetToAnimate();
|
||||||
if (w) {
|
if (w) {
|
||||||
qreal delta = currentTime / qreal(duration());
|
qreal delta = easingCurve().valueForProgress(
|
||||||
|
currentTime / qreal(duration()));
|
||||||
delta = (1 - m_zoom) * delta;
|
delta = (1 - m_zoom) * delta;
|
||||||
w->setScale( 1 - delta);
|
w->setScale( 1 - delta);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Animation easing curve type
|
* Animation easing curve type
|
||||||
*/
|
*/
|
||||||
QEasingCurve::Type easingCurve;
|
QEasingCurve easingCurve;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Duration of the animation. Default is 250ms.
|
* Duration of the animation. Default is 250ms.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user