Added Plasma::PendulumCurve class plus make it work with RotationAnimation

svn path=/trunk/KDE/kdelibs/; revision=1117942
This commit is contained in:
Bruno de Oliveira Abinader 2010-04-23 13:39:34 +00:00
parent abd0dd20b5
commit 2375cd6ce8
5 changed files with 130 additions and 27 deletions

View File

@ -51,6 +51,7 @@ set(plasma_LIB_SRCS
animator.cpp
animations/animation.cpp
animations/easinganimation.cpp
animations/pendulumcurve.cpp
animations/fade.cpp
animations/grow.cpp
animations/slide.cpp
@ -365,6 +366,7 @@ endif(PHONON_FOUND)
install(FILES
animations/animation.h
animations/pendulumcurve.h
DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/animations COMPONENT Devel)

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pendulumcurve.h"
/**
* This static method is used to create a custom easing curve type.
* @param progress animation progress value
* @return pendulum easing curve progress value
*/
static qreal pendulumFunction(qreal progress)
{
if (progress <= 0.25) {
progress *= 4;
} else if (progress <= 0.50) {
progress -= 0.25;
progress *= 4;
progress = 1 - progress;
} else if (progress <= 0.75) {
progress -= 0.50;
progress *= -4;
} else {
progress -= 0.75;
progress *= 4;
progress = 1 - progress;
progress *= -1;
}
return progress;
}
namespace Plasma
{
PendulumCurve::PendulumCurve()
: QEasingCurve()
{
setCustomType(pendulumFunction);
}
} // namespace Plasma

View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMA_ANIMATIONS_PENDULUMCURVE_H
#define PLASMA_ANIMATIONS_PENDULUMCURVE_H
#include <QtCore/QEasingCurve>
#include <plasma/plasma_export.h>
namespace Plasma
{
/*
* @class PendulumCurve plasma/animations/pendulumcurve.h
* @shot Pendulum Easing Curve
*
* This easing curve provides values which are split in 4 parts:
* from 0 to 1, from 1 to 0, from 0 to -1, and from -1 to 0, in a linear way.
*/
class PLASMA_EXPORT PendulumCurve : public QEasingCurve
{
public:
/**
* default constructor
*/
PendulumCurve();
};
} // namespace Plasma
#endif // PLASMA_ANIMATIONS_PENDULUMCURVE_H

View File

@ -16,25 +16,24 @@
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rotation_p.h"
#include <QGraphicsRotation>
#include <QEasingCurve>
#include <QVector3D>
#include <kdebug.h>
#include "kdebug.h"
#include "rotation_p.h"
namespace Plasma
{
RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle)
: EasingAnimation(parent)
: EasingAnimation(parent),
m_rotation(new QGraphicsRotation(this)),
m_angle(angle),
m_axis(axis),
m_reference(reference)
{
setAngle(angle);
setAxis(axis);
setReference(reference);
m_rotation = new QGraphicsRotation(this);
}
RotationAnimation::~RotationAnimation()
@ -151,12 +150,6 @@ void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstrac
QList<QGraphicsTransform *> transformation;
transformation.append(m_rotation);
m_object->setTransformations(transformation);
if ((oldState == Stopped) && (newState == Running)) {
m_rotation->setAngle(direction() == Forward ? 0 : angle());
} else if (newState == Stopped) {
m_rotation->setAngle(direction() == Forward ? angle() : 0);
}
}
void RotationAnimation::updateEffectiveTime(int currentTime)

View File

@ -45,7 +45,8 @@ class RotationAnimation : public EasingAnimation
Q_PROPERTY(qreal angle READ angle WRITE setAngle)
public:
/** Default constructor
/**
* Default constructor
*
* @param parent Animation object parent.
* @param reference See \ref Animation::Reference.
@ -66,18 +67,30 @@ public:
*/
Qt::Axis axis() const;
/**
* set animation rotation axis
* @arg axis Rotation (e.g. YAxis, ZAxis, XAxis)
*/
void setAxis(const Qt::Axis &axis);
/**
* Rotation reference (e.g. Center, Up, Down, Left, Right) can
* be combined (i.e. Center|Up)
*/
qint8 reference() const;
/**
* Animation rotation angle (e.g. 45, 180, etc)
*/
qreal angle() const;
/**
* Reimplemented from Plasma::Animation
* @arg curve Easing curve
*/
void setEasingCurve(const QEasingCurve &curve);
public slots:
/**
* set animation rotation axis
* @arg axis Rotation (e.g. YAxis, ZAxis, XAxis)
*/
void setAxis(const Qt::Axis &axis);
/**
* Set rotation reference (e.g. Center, Up, Down, Left, Right) can
* be combined (i.e. Center|Up)
@ -85,11 +98,6 @@ public:
*/
void setReference(const qint8 &reference);
/**
* Animation rotation angle (e.g. 45, 180, etc)
*/
qreal angle() const;
/**
* Set animation rotation angle (e.g. 45, 180, etc)
* @arg angle The angle