use the easing curve in all of our animations

svn path=/trunk/KDE/kdelibs/; revision=1112612
This commit is contained in:
Aaron J. Seigo 2010-04-08 17:07:33 +00:00
parent 2ab49f0057
commit 892d8ae1c0
21 changed files with 134 additions and 57 deletions

View File

@ -50,6 +50,7 @@ set(plasma_LIB_SRCS
abstracttoolbox.cpp
animator.cpp
animations/animation.cpp
animations/easinganimation.cpp
animations/fade.cpp
animations/grow.cpp
animations/slide.cpp

View File

@ -0,0 +1,39 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "easinganimation_p.h"
#include <kdebug.h>
namespace Plasma
{
EasingAnimation::EasingAnimation(QObject *parent)
: Animation(parent)
{
}
void EasingAnimation::updateCurrentTime(int currentTime)
{
updateEffectiveTime(easingCurve().valueForProgress(currentTime / qreal(qMax(1, duration()))) * duration());
}
} // namespace Plasma
#include "easinganimation_p.moc"

View File

@ -0,0 +1,46 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_EASINGANIMATION_H
#define PLASMA_EASINGANIMATION_H
#include "animation.h"
namespace Plasma
{
class EasingAnimation : public Animation
{
Q_OBJECT
public:
explicit EasingAnimation(QObject *parent = 0);
protected:
virtual void updateEffectiveTime(int currentTime) = 0;
private:
void updateCurrentTime(int currentTime);
};
} // namespace Plasma
#endif // PLASMA_EASINGANIMATION_H

View File

@ -27,7 +27,7 @@ namespace Plasma
{
FadeAnimation::FadeAnimation(QObject *parent)
: Animation(parent),
: EasingAnimation(parent),
m_startOpacity(0),
m_targetOpacity(1)
{
@ -71,7 +71,7 @@ void FadeAnimation::updateState(QAbstractAnimation::State newState, QAbstractAni
}
}
void FadeAnimation::updateCurrentTime(int currentTime)
void FadeAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w) {
@ -80,8 +80,6 @@ void FadeAnimation::updateCurrentTime(int currentTime)
Animation::easingCurve().valueForProgress(delta);
w->setOpacity(m_startOpacity - delta);
}
Animation::updateCurrentTime(currentTime);
}
} //namespace Plasma

View File

@ -24,7 +24,7 @@
#ifndef PLASMA_ANIMATIONS_FADE_P_H
#define PLASMA_ANIMATIONS_FADE_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -38,7 +38,7 @@ namespace Plasma
* value to a target value. The range is 0 (full translucent) to 1 (full
* opaque).
*/
class FadeAnimation : public Animation
class FadeAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qreal startOpacity READ startOpacity WRITE setStartOpacity)
@ -85,7 +85,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
/** Initial opacity */

View File

@ -27,7 +27,7 @@ namespace Plasma
{
GeometryAnimation::GeometryAnimation(QObject *parent)
: Animation(parent),
: EasingAnimation(parent),
m_startGeometry(-1, -1, -1, -1)
{
}
@ -74,7 +74,7 @@ void GeometryAnimation::updateState(QAbstractAnimation::State newState, QAbstrac
}
}
void GeometryAnimation::updateCurrentTime(int currentTime)
void GeometryAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w) {
@ -89,8 +89,6 @@ void GeometryAnimation::updateCurrentTime(int currentTime)
w->setGeometry(newGeo);
}
Animation::updateCurrentTime(currentTime);
}
} //namespace Plasma

View File

@ -24,7 +24,7 @@
#ifndef PLASMA_ANIMATIONS_GEOMETRY_P_H
#define PLASMA_ANIMATIONS_GEOMETRY_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -36,7 +36,7 @@ namespace Plasma
* Use this class when you want to change the geometry of an QGraphicsWidget
* in an animated way (you should at least set the target geometry).
*/
class GeometryAnimation : public Animation
class GeometryAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(QRectF startGeometry READ startGeometry WRITE setStartGeometry)
@ -83,7 +83,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
/** Initial geometry */

View File

@ -26,7 +26,7 @@ namespace Plasma
{
GrowAnimation::GrowAnimation(QObject *parent, qreal factor)
: Animation(parent), m_animFactor(factor)
: EasingAnimation(parent), m_animFactor(factor)
{
}
@ -40,7 +40,7 @@ qreal GrowAnimation::factor() const
return m_animFactor;
}
void GrowAnimation::updateCurrentTime(int currentTime)
void GrowAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w && state() == QAbstractAnimation::Running) {

View File

@ -24,7 +24,7 @@
#ifndef PLASMA_ANIMATIONS_GROW_P_H
#define PLASMA_ANIMATIONS_GROW_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -39,7 +39,7 @@ namespace Plasma
* (it does the animation by changing the objects geometry). Also see
* \ref ZoomAnimation.
*/
class GrowAnimation : public Animation
class GrowAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qreal factor READ factor WRITE setFactor)
@ -72,7 +72,7 @@ public:
void setFactor(const qreal factor);
protected:
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
private:

View File

@ -31,7 +31,7 @@ namespace Plasma
{
PixmapTransition::PixmapTransition(QObject *parent)
: Animation(parent)
: EasingAnimation(parent)
{
}
@ -48,7 +48,7 @@ void PixmapTransition::setStartPixmap(const QPixmap &pixmap)
m_startPixmap = pixmap;
//this will center the pixmaps if needed
updateCurrentTime(0);
updateEffectiveTime(0);
}
QPixmap PixmapTransition::startPixmap() const
@ -64,7 +64,7 @@ void PixmapTransition::setTargetPixmap(const QPixmap &pixmap)
m_targetPixmap = pixmap;
updateCurrentTime(0);
updateEffectiveTime(0);
}
QPixmap PixmapTransition::targetPixmap() const
@ -128,7 +128,7 @@ void PixmapTransition::updateState(QAbstractAnimation::State newState, QAbstract
w->update();
}
void PixmapTransition::updateCurrentTime(int currentTime)
void PixmapTransition::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w) {
@ -161,7 +161,6 @@ void PixmapTransition::updateCurrentTime(int currentTime)
}
}
Animation::updateCurrentTime(currentTime);
if (w) {
w->update();
}

View File

@ -25,7 +25,7 @@
#ifndef PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
#define PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -37,7 +37,7 @@ namespace Plasma
*
* Effect that paints a transition between two pixmaps
*/
class PixmapTransition : public Animation
class PixmapTransition : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(QPixmap startPixmap READ startPixmap WRITE setStartPixmap)
@ -76,7 +76,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
QPixmap m_startPixmap;

View File

@ -31,7 +31,7 @@ namespace Plasma
{
PulseAnimation::PulseAnimation(QObject *parent)
: Animation(parent),
: EasingAnimation(parent),
m_zvalue(0),
m_scale(0),
m_opacity(0),
@ -117,7 +117,7 @@ void PulseAnimation::updateState(QAbstractAnimation::State newState, QAbstractAn
}
}
void PulseAnimation::updateCurrentTime(int currentTime)
void PulseAnimation::updateEffectiveTime(int currentTime)
{
if (m_under.data()) {
qreal delta = Animation::easingCurve().valueForProgress( currentTime / qreal(duration()));

View File

@ -23,7 +23,7 @@
#ifndef PLASMA_ANIMATIONS_PULSER_P_H
#define PLASMA_ANIMATIONS_PULSER_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -38,7 +38,7 @@ class ShadowFake;
* Effect that pulses a shadow copy of any QGraphicsWidget making
* it more translucent and bigger along the time until it vanishes.
*/
class PulseAnimation : public Animation
class PulseAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qreal targetScale READ targetScale WRITE setTargetScale)
@ -75,7 +75,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
void setCopy();
private:

View File

@ -20,6 +20,7 @@
#include <QGraphicsRotation>
#include <QEasingCurve>
#include <QVector3D>
#include <kdebug.h>
@ -27,7 +28,7 @@ namespace Plasma
{
RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle)
: Animation(parent)
: EasingAnimation(parent)
{
setAngle(angle);
setAxis(axis);
@ -158,7 +159,7 @@ void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstrac
}
}
void RotationAnimation::updateCurrentTime(int currentTime)
void RotationAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w) {

View File

@ -23,10 +23,7 @@
#ifndef PLASMA_ROTATION_P_H
#define PLASMA_ROTATION_P_H
#include <plasma/animations/animation.h>
#include <plasma/plasma_export.h>
#include <QVector3D>
#include <plasma/animations/easinganimation_p.h>
class QGraphicsRotation;
@ -39,7 +36,7 @@ namespace Plasma {
* axis can be defined using properties). See also
* \ref StackedRotationAnimation.
*/
class RotationAnimation : public Animation
class RotationAnimation : public EasingAnimation
{
Q_OBJECT
@ -101,7 +98,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
/** Rotation transform object */

View File

@ -30,7 +30,7 @@ namespace Plasma
const int RotationStackedAnimation::s_sideAngle = 90;
RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
: Animation(parent)
: EasingAnimation(parent)
{
m_backRotation = new QGraphicsRotation(this);
m_frontRotation = new QGraphicsRotation(this);
@ -141,7 +141,7 @@ void RotationStackedAnimation::updateState(QAbstractAnimation::State newState,
}
}
void RotationStackedAnimation::updateCurrentTime(int currentTime)
void RotationStackedAnimation::updateEffectiveTime(int currentTime)
{
if (!targetWidget() || !backWidget()) {
return;

View File

@ -22,7 +22,7 @@
#ifndef PLASMA_ROTATIONSTACKED_P_H
#define PLASMA_ROTATIONSTACKED_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
#include <QGraphicsLayoutItem>
@ -41,7 +41,7 @@ namespace Plasma {
* Use this class when you want to rotate a widget along an axis (e.g. Y)
* and display a 'hidden' widget behind it. See also \ref RotationAnimation.
*/
class RotationStackedAnimation : public Animation
class RotationStackedAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(MovementDirection movementDirection READ movementDirection WRITE setMovementDirection)
@ -97,7 +97,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
/**

View File

@ -51,7 +51,7 @@ SlideAnimation::~SlideAnimation()
SlideAnimation::SlideAnimation(QObject *parent,
MovementDirection direction,
qreal distance) : Animation(parent)
qreal distance) : EasingAnimation(parent)
{
setMovementDirection(direction);
setDistance(distance);
@ -68,7 +68,7 @@ Animation::MovementDirection SlideAnimation::movementDirection() const
return m_animDirection;
}
void SlideAnimation::updateCurrentTime(int currentTime)
void SlideAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w && state() == QAbstractAnimation::Running) {

View File

@ -24,7 +24,7 @@
#ifndef PLASMA_ANIMATIONS_SLIDE_P_H
#define PLASMA_ANIMATIONS_SLIDE_P_H
#include "plasma/animations/animation.h"
#include "plasma/animations/easinganimation_p.h"
#include "plasma/plasma_export.h"
#include "plasma/plasma.h"
@ -39,7 +39,7 @@ class SlideAnimationPrivate;
* Effect that moves the object a specific distance in a given direction. The
* object is optionally made invisible at the beginning or at the end.
*/
class SlideAnimation : public Animation
class SlideAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qreal distance READ distance WRITE setDistance)
@ -76,7 +76,7 @@ public:
Animation::MovementDirection movementDirection() const;
protected:
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
private:

View File

@ -25,7 +25,7 @@ namespace Plasma
{
ZoomAnimation::ZoomAnimation(QObject *parent)
: Animation(parent),
: EasingAnimation(parent),
m_zoom(0)
{
}
@ -60,7 +60,7 @@ void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAni
}
}
void ZoomAnimation::updateCurrentTime(int currentTime)
void ZoomAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *w = targetWidget();
if (w) {
@ -73,8 +73,6 @@ void ZoomAnimation::updateCurrentTime(int currentTime)
w->setScale(delta);
}
}
Animation::updateCurrentTime(currentTime);
}
} //namespace Plasma

View File

@ -24,7 +24,7 @@
#ifndef PLASMA_ANIMATIONS_ZOOM_P_H
#define PLASMA_ANIMATIONS_ZOOM_P_H
#include <plasma/animations/animation.h>
#include <plasma/animations/easinganimation_p.h>
#include <plasma/plasma_export.h>
namespace Plasma
@ -35,7 +35,7 @@ namespace Plasma
* @short Zoom Animation
*
*/
class ZoomAnimation : public Animation
class ZoomAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom)
@ -49,7 +49,7 @@ public:
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateCurrentTime(int currentTime);
void updateEffectiveTime(int currentTime);
private:
qreal m_zoom;