2007-06-08 07:24:19 +02:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
2007-07-06 18:26:48 +02:00
|
|
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
2007-06-08 07:24:19 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2007-06-08 07:24:19 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-04-25 01:21:17 +02:00
|
|
|
#ifndef ANIMATIONCONTROLLER_H
|
|
|
|
#define ANIMATIONCONTROLLER_H
|
2007-06-08 07:24:19 +02:00
|
|
|
|
2007-07-15 00:40:00 +02:00
|
|
|
#include <QtGui/QImage>
|
|
|
|
#include <QtCore/QObject>
|
2007-06-08 07:24:19 +02:00
|
|
|
|
2007-06-10 08:02:38 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-06-08 07:24:19 +02:00
|
|
|
|
|
|
|
class QGraphicsItem;
|
2007-06-10 09:09:07 +02:00
|
|
|
class QTimeLine;
|
2007-06-08 07:24:19 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @short A system for applying effects to Plasma elements
|
|
|
|
*/
|
2008-04-25 01:21:17 +02:00
|
|
|
class PLASMA_EXPORT AnimationDriver : public QObject
|
2007-06-08 07:24:19 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2007-08-04 14:46:29 +02:00
|
|
|
Q_ENUMS( Animation )
|
|
|
|
Q_ENUMS( CurveShape )
|
|
|
|
Q_ENUMS( Movement )
|
2007-06-08 07:24:19 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2008-04-25 00:30:53 +02:00
|
|
|
enum Animation
|
2007-06-19 23:56:03 +02:00
|
|
|
{
|
2008-04-25 00:30:53 +02:00
|
|
|
AppearAnimation = 0 /*<< Animate the appearance of an element */,
|
|
|
|
DisappearAnimation /*<< Animate the disappearance of an element */,
|
|
|
|
ActivateAnimation /*<< When something is activated or launched, such as an app icon being clicked */
|
2007-06-19 23:56:03 +02:00
|
|
|
};
|
|
|
|
|
2007-06-25 08:01:34 +02:00
|
|
|
enum CurveShape
|
|
|
|
{
|
|
|
|
EaseInCurve = 0,
|
|
|
|
EaseOutCurve,
|
|
|
|
EaseInOutCurve,
|
|
|
|
LinearCurve
|
|
|
|
};
|
|
|
|
|
2007-07-04 11:36:50 +02:00
|
|
|
enum Movement
|
|
|
|
{
|
2008-04-24 23:06:08 +02:00
|
|
|
SlideInMovement = 0,
|
|
|
|
SlideOutMovement,
|
|
|
|
FastSlideInMovement,
|
|
|
|
FastSlideOutMovement
|
2007-07-04 11:36:50 +02:00
|
|
|
};
|
|
|
|
|
2007-06-17 22:05:43 +02:00
|
|
|
/**
|
|
|
|
* Singleton accessor
|
|
|
|
**/
|
2008-04-25 01:21:17 +02:00
|
|
|
static AnimationDriver* self();
|
2007-06-17 22:05:43 +02:00
|
|
|
|
2008-04-25 01:21:17 +02:00
|
|
|
explicit AnimationDriver(QObject * parent = 0);
|
|
|
|
~AnimationDriver();
|
2007-06-08 07:24:19 +02:00
|
|
|
|
2007-08-04 14:46:29 +02:00
|
|
|
Q_INVOKABLE void animateItem(QGraphicsItem* item, Animation anim);
|
|
|
|
Q_INVOKABLE void moveItem(QGraphicsItem* item, Movement movement, const QPoint &destination);
|
2007-06-25 08:01:34 +02:00
|
|
|
|
2007-10-12 09:25:24 +02:00
|
|
|
/**
|
|
|
|
* Starts a custom animation, preventing the need to create a timeline
|
|
|
|
* with its own timer tick.
|
|
|
|
*
|
|
|
|
* @arg frames the number of frames this animation should persist for
|
|
|
|
* @arg duration the length, in milliseconds, the animation will take
|
|
|
|
* @arg curve the curve applied to the frame rate
|
|
|
|
* @arg receive the object that will handle the actual animation
|
2007-10-12 22:27:51 +02:00
|
|
|
* @arg method the method name of slot to be invoked on each update.
|
|
|
|
* It must take a qreal. So if the slot is animate(qreal),
|
|
|
|
* pass in "animate" as the method parameter.
|
2007-10-12 09:25:24 +02:00
|
|
|
*
|
|
|
|
* @return an id that can be used to identify this animation.
|
|
|
|
*/
|
2008-04-25 01:21:17 +02:00
|
|
|
Q_INVOKABLE int customAnimation(int frames, int duration, AnimationDriver::CurveShape curve,
|
2007-10-12 22:27:51 +02:00
|
|
|
QObject* receiver, const char* method);
|
2007-10-12 09:25:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops a custom animation. Note that it is not necessary to call
|
|
|
|
* this on object destruction, as custom animations associated with
|
|
|
|
* a given QObject are cleaned up automatically on QObject destruction.
|
|
|
|
*
|
|
|
|
* @arg id the id of the animation as returned by customAnimation
|
|
|
|
*/
|
2008-04-24 23:26:36 +02:00
|
|
|
Q_INVOKABLE void stopCustomAnimation(int id);
|
2007-10-12 09:25:24 +02:00
|
|
|
|
2008-04-25 00:30:53 +02:00
|
|
|
Q_INVOKABLE int animateElement(QGraphicsItem *obj, Animation);
|
2008-04-24 23:26:36 +02:00
|
|
|
Q_INVOKABLE void stopElementAnimation(int id);
|
|
|
|
Q_INVOKABLE void setInitialPixmap(int id, const QPixmap &pixmap);
|
|
|
|
Q_INVOKABLE QPixmap currentPixmap(int id);
|
2007-06-19 23:56:03 +02:00
|
|
|
|
2008-04-14 20:04:34 +02:00
|
|
|
/**
|
|
|
|
* Can be used to query if there are other animations happening. This way
|
|
|
|
* heavy operations can be delayed until all animations are finished.
|
|
|
|
* @return true if there are animations going on.
|
|
|
|
* @since 4.1
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE bool isAnimating() const;
|
|
|
|
|
2007-06-08 07:24:19 +02:00
|
|
|
Q_SIGNALS:
|
2008-04-25 01:21:17 +02:00
|
|
|
void animationFinished(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim);
|
2008-04-24 22:16:40 +02:00
|
|
|
void movementFinished(QGraphicsItem *item);
|
2008-04-24 23:26:36 +02:00
|
|
|
void elementAnimationFinished(int id);
|
|
|
|
void customAnimationFinished(int id);
|
2007-06-08 07:24:19 +02:00
|
|
|
|
2007-06-25 08:01:34 +02:00
|
|
|
protected:
|
|
|
|
void timerEvent(QTimerEvent *event);
|
2007-06-08 07:24:19 +02:00
|
|
|
|
|
|
|
protected Q_SLOTS:
|
2008-02-14 18:09:00 +01:00
|
|
|
void animatedItemDestroyed(QObject*);
|
|
|
|
void movingItemDestroyed(QObject*);
|
|
|
|
void animatedElementDestroyed(QObject*);
|
2007-10-12 09:25:24 +02:00
|
|
|
void customAnimReceiverDestroyed(QObject*);
|
2007-06-08 07:24:19 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
|
|
|
|
class Private;
|
|
|
|
Private * const d;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|