Creating a QEasingCurve object in AnimationPrivate and allowing access to
it to all Animation derived classes. The idea is that the user can select the easing curve (if the it makes sense in the animation). svn path=/trunk/KDE/kdelibs/; revision=1060687
This commit is contained in:
parent
d960f3fcbb
commit
5a721b9bad
@ -69,12 +69,17 @@ QGraphicsWidget* Animation::widgetToAnimate()
|
||||
return d->animObject.data();
|
||||
}
|
||||
|
||||
void Animation::setEasingCurve(QEasingCurve easingCurve)
|
||||
void Animation::setEasingCurveType(QEasingCurve::Type type)
|
||||
{
|
||||
d->easingCurve = easingCurve;
|
||||
d->easingCurve.setType(type);
|
||||
}
|
||||
|
||||
QEasingCurve Animation::easingCurve() const
|
||||
QEasingCurve::Type Animation::easingCurveType() const
|
||||
{
|
||||
return d->easingCurve.type();
|
||||
}
|
||||
|
||||
QEasingCurve& Animation::easingCurve()
|
||||
{
|
||||
return d->easingCurve;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QAbstractAnimation>
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <QEasingCurve>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -46,7 +47,7 @@ class PLASMA_EXPORT Animation : public QAbstractAnimation
|
||||
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int duration READ duration WRITE setDuration)
|
||||
Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve)
|
||||
Q_PROPERTY(QEasingCurve::Type easingCurveType READ easingCurveType WRITE setEasingCurveType)
|
||||
Q_PROPERTY(QGraphicsWidget *widgetToAnimate READ widgetToAnimate WRITE setWidgetToAnimate)
|
||||
|
||||
public:
|
||||
@ -82,12 +83,12 @@ public:
|
||||
/**
|
||||
* Set the animation easing curve type
|
||||
*/
|
||||
void setEasingCurve(QEasingCurve easingCurve);
|
||||
void setEasingCurveType(QEasingCurve::Type type);
|
||||
|
||||
/**
|
||||
* Get the animation easing curve type
|
||||
*/
|
||||
QEasingCurve easingCurve() const;
|
||||
QEasingCurve::Type easingCurveType() const;
|
||||
|
||||
protected:
|
||||
|
||||
@ -99,6 +100,8 @@ protected:
|
||||
|
||||
virtual void updateCurrentTime(int currentTime);
|
||||
|
||||
QEasingCurve &easingCurve();
|
||||
|
||||
private:
|
||||
AnimationPrivate *const d;
|
||||
|
||||
|
@ -67,6 +67,7 @@ void FadeAnimation::setWidgetToAnimate(QGraphicsWidget *widget)
|
||||
if (widget) {
|
||||
widget->setOpacity(m_startOpacity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FadeAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
||||
@ -89,7 +90,7 @@ void FadeAnimation::updateCurrentTime(int currentTime)
|
||||
if (w) {
|
||||
qreal delta = currentTime / qreal(duration());
|
||||
delta = (m_startOpacity - m_targetOpacity) *
|
||||
easingCurve().valueForProgress(delta);
|
||||
Animation::easingCurve().valueForProgress(delta);
|
||||
w->setOpacity(m_startOpacity - delta);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ void GrowAnimation::updateCurrentTime(int currentTime)
|
||||
{
|
||||
QGraphicsWidget *w = widgetToAnimate();
|
||||
if (w && state() == QAbstractAnimation::Running) {
|
||||
qreal delta = easingCurve().valueForProgress(
|
||||
qreal delta = Animation::easingCurve().valueForProgress(
|
||||
currentTime / qreal(duration()));
|
||||
QRectF geometry;
|
||||
geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
|
||||
|
@ -58,7 +58,6 @@ protected:
|
||||
|
||||
private:
|
||||
qreal m_animFactor;
|
||||
|
||||
QRectF m_startGeometry;
|
||||
QRectF m_targetGeometry;
|
||||
};
|
||||
|
@ -41,8 +41,7 @@ SlideAnimation::~SlideAnimation()
|
||||
|
||||
SlideAnimation::SlideAnimation(QObject *parent,
|
||||
AnimationDirection direction,
|
||||
qreal distance)
|
||||
: Animation(parent)
|
||||
qreal distance) : Animation(parent)
|
||||
{
|
||||
setMovementDirection(direction);
|
||||
setDistance(distance);
|
||||
@ -62,7 +61,7 @@ void SlideAnimation::updateCurrentTime(int currentTime)
|
||||
{
|
||||
QGraphicsWidget *w = widgetToAnimate();
|
||||
if (w && state() == QAbstractAnimation::Running) {
|
||||
qreal delta = easingCurve().valueForProgress(
|
||||
qreal delta = Animation::easingCurve().valueForProgress(
|
||||
currentTime / qreal(duration()));
|
||||
w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "plasma/plasma_export.h"
|
||||
#include "plasma/plasma.h"
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
@ -88,7 +87,6 @@ private:
|
||||
* there is change in the position of animated widget.
|
||||
*/
|
||||
qreal m_animDistance;
|
||||
|
||||
QPointF m_startPos;
|
||||
QPointF m_targetPos;
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
/**
|
||||
* Animation easing curve type
|
||||
*/
|
||||
QEasingCurve::Type easingCurve;
|
||||
QEasingCurve easingCurve;
|
||||
|
||||
/**
|
||||
* Animation direction, the idea is to offer a way
|
||||
|
Loading…
Reference in New Issue
Block a user