2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
* 2007 Alexis Ménard <darktears31@gmail.com>
|
|
|
|
*
|
|
|
|
* 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_ANIMATOR_H
|
|
|
|
#define PLASMA_ANIMATOR_H
|
|
|
|
|
|
|
|
#include <QtGui/QImage>
|
|
|
|
#include <QtCore/QObject>
|
2009-12-21 19:36:39 +01:00
|
|
|
#include <QtCore/QAbstractAnimation>
|
2010-04-23 22:55:46 +02:00
|
|
|
#include <QtCore/QEasingCurve>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
class QGraphicsItem;
|
2009-10-20 00:10:25 +02:00
|
|
|
class QGraphicsWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
class QTimeLine;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-10-21 03:51:31 +02:00
|
|
|
class AnimatorPrivate;
|
2009-12-03 20:30:02 +01:00
|
|
|
class Animation;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Animator plasma/animator.h <Plasma/Animator>
|
|
|
|
*
|
|
|
|
* @short A system for applying effects to Plasma elements
|
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT Animator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS(Animation)
|
|
|
|
Q_ENUMS(CurveShape)
|
|
|
|
Q_ENUMS(Movement)
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-10-17 01:32:08 +02:00
|
|
|
enum Animation {
|
2008-11-04 00:08:39 +01:00
|
|
|
AppearAnimation = 0, /*<< Animate the appearance of an element */
|
|
|
|
DisappearAnimation, /*<< Animate the disappearance of an element */
|
2009-10-20 21:19:11 +02:00
|
|
|
ActivateAnimation, /*<< When something is activated or launched,
|
2009-10-21 03:51:31 +02:00
|
|
|
such as an app icon being clicked */
|
|
|
|
FadeAnimation, /*<< Can be used for both fade in and out */
|
|
|
|
GrowAnimation, /*<< Grow animated object geometry */
|
|
|
|
PulseAnimation, /*<< Pulse animated object (opacity/geometry/scale) */
|
|
|
|
RotationAnimation, /*<< Rotate an animated object */
|
2009-12-05 20:54:27 +01:00
|
|
|
RotationStackedAnimation, /*<< for flipping one object with another */
|
|
|
|
SlideAnimation, /*<< Move the position of animated object */
|
2009-12-08 10:22:51 +01:00
|
|
|
GeometryAnimation, /*<< Geometry animation*/
|
2010-01-21 08:23:18 +01:00
|
|
|
ZoomAnimation, /*<<Zoom animation */
|
2010-04-19 17:09:36 +02:00
|
|
|
PixmapTransitionAnimation, /*<< Transition between two pixmaps*/
|
2010-04-30 01:52:12 +02:00
|
|
|
WaterAnimation /*<< Water animation using ripple effect */,
|
|
|
|
LastAnimation = 1024
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
2009-10-17 01:32:08 +02:00
|
|
|
enum CurveShape {
|
2008-11-04 00:08:39 +01:00
|
|
|
EaseInCurve = 0,
|
|
|
|
EaseOutCurve,
|
|
|
|
EaseInOutCurve,
|
2010-04-23 22:55:46 +02:00
|
|
|
LinearCurve,
|
|
|
|
PendularCurve
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
2009-10-17 01:32:08 +02:00
|
|
|
enum Movement {
|
2008-11-04 00:08:39 +01:00
|
|
|
SlideInMovement = 0,
|
|
|
|
SlideOutMovement,
|
|
|
|
FastSlideInMovement,
|
|
|
|
FastSlideOutMovement
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Singleton accessor
|
|
|
|
**/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
static KDE_DEPRECATED Animator *self();
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-10-20 21:54:22 +02:00
|
|
|
/**
|
|
|
|
* Factory to build new animation objects. To control their behavior,
|
|
|
|
* check \ref AbstractAnimation properties.
|
2010-04-28 19:41:16 +02:00
|
|
|
* @since 4.4
|
2009-10-20 21:54:22 +02:00
|
|
|
**/
|
2009-12-03 20:30:02 +01:00
|
|
|
static Plasma::Animation *create(Animator::Animation type, QObject *parent = 0);
|
2009-10-20 21:54:22 +02:00
|
|
|
|
2010-04-28 19:41:16 +02:00
|
|
|
/**
|
|
|
|
* Factory to build new animation objects from Javascript files. To control their behavior,
|
|
|
|
* check \ref AbstractAnimation properties.
|
|
|
|
* @since 4.5
|
|
|
|
**/
|
2010-04-28 19:45:24 +02:00
|
|
|
static Plasma::Animation *create(const QString &animationName, QObject *parent = 0);
|
2010-04-26 23:30:55 +02:00
|
|
|
|
2010-04-23 22:55:46 +02:00
|
|
|
/**
|
|
|
|
* Factory to build new custom easing curves.
|
2010-04-28 19:41:16 +02:00
|
|
|
* @since 4.5
|
2010-04-23 22:55:46 +02:00
|
|
|
*/
|
2010-04-24 00:36:17 +02:00
|
|
|
static QEasingCurve create(Animator::CurveShape type);
|
2010-04-23 22:55:46 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
|
|
|
* Starts a standard animation on a QGraphicsItem.
|
|
|
|
*
|
|
|
|
* @arg item the item to animate in some fashion
|
|
|
|
* @arg anim the type of animation to perform
|
|
|
|
* @return the id of the animation
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
**/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE int animateItem(QGraphicsItem *item,Animation anim);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops an item animation before the animation is complete.
|
|
|
|
* Note that it is not necessary to call
|
|
|
|
* this on normal completion of the animation.
|
|
|
|
*
|
|
|
|
* @arg id the id of the animation as returned by animateItem
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void stopItemAnimation(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a standard animation on a QGraphicsItem.
|
|
|
|
*
|
|
|
|
* @arg item the item to animate in some fashion
|
|
|
|
* @arg anim the type of animation to perform
|
|
|
|
* @return the id of the animation
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
**/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE int moveItem(QGraphicsItem *item, Movement movement, const QPoint &destination);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops an item movement before the animation is complete.
|
|
|
|
* Note that it is not necessary to call
|
|
|
|
* this on normal completion of the animation.
|
|
|
|
*
|
|
|
|
* @arg id the id of the animation as returned by moveItem
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void stopItemMovement(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01: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
|
|
|
|
* @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.
|
|
|
|
* It has an optional integer paramenter that takes an
|
|
|
|
* integer that reapresents the animation id, useful if
|
|
|
|
* you want to manage multiple animations with a sigle slot
|
|
|
|
*
|
|
|
|
* @return an id that can be used to identify this animation.
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE int customAnimation(int frames, int duration,
|
|
|
|
Animator::CurveShape curve, QObject *receiver, const char *method);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01: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
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void stopCustomAnimation(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE int animateElement(QGraphicsItem *obj, Animation);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void stopElementAnimation(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE void setInitialPixmap(int id, const QPixmap &pixmap);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE QPixmap currentPixmap(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01: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
|
2009-10-15 21:36:38 +02:00
|
|
|
* @deprecated use new Animator API with Qt Kinetic
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2009-10-15 21:36:38 +02:00
|
|
|
KDE_DEPRECATED Q_INVOKABLE bool isAnimating() const;
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-10-20 00:10:25 +02:00
|
|
|
/**
|
|
|
|
* Register a widget as a scrolling widget.
|
2010-05-07 14:32:35 +02:00
|
|
|
* This function is deprecated:
|
|
|
|
* use a ScrollWidget, with setWidget() as your widget instead.
|
2009-10-20 00:10:25 +02:00
|
|
|
*
|
|
|
|
* @param widget the widget that offers a scrolling behaviour
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2010-05-07 14:32:35 +02:00
|
|
|
KDE_DEPRECATED void registerScrollingManager(QGraphicsWidget *widget);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2009-10-20 00:10:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* unregister the scrolling manager of a certain widget
|
2010-05-07 14:32:35 +02:00
|
|
|
* This function is deprecated: use ScrollWidget instead.
|
2009-10-20 00:10:25 +02:00
|
|
|
*
|
|
|
|
* @param widget the widget we don't want no longer animated
|
|
|
|
* @since 4.4
|
|
|
|
*/
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2010-05-07 14:32:35 +02:00
|
|
|
KDE_DEPRECATED void unregisterScrollingManager(QGraphicsWidget *widget);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2010-02-22 12:21:30 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void animationFinished(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
|
|
|
void movementFinished(QGraphicsItem *item);
|
|
|
|
void elementAnimationFinished(int id);
|
|
|
|
void customAnimationFinished(int id);
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2010-05-07 14:32:35 +02:00
|
|
|
KDE_DEPRECATED void scrollStateChanged(QGraphicsWidget *widget, QAbstractAnimation::State newState,
|
2009-12-21 19:36:39 +01:00
|
|
|
QAbstractAnimation::State oldState);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2008-11-04 00:08:39 +01:00
|
|
|
protected:
|
|
|
|
void timerEvent(QTimerEvent *event);
|
2010-11-04 09:06:43 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
private:
|
2010-11-04 09:06:43 +01:00
|
|
|
#ifndef KDE_NO_DEPRECATED
|
2008-11-04 00:08:39 +01:00
|
|
|
friend class AnimatorSingleton;
|
|
|
|
explicit Animator(QObject * parent = 0);
|
|
|
|
~Animator();
|
|
|
|
|
|
|
|
Q_PRIVATE_SLOT(d, void animatedItemDestroyed(QObject*))
|
|
|
|
Q_PRIVATE_SLOT(d, void movingItemDestroyed(QObject*))
|
|
|
|
Q_PRIVATE_SLOT(d, void animatedElementDestroyed(QObject*))
|
|
|
|
Q_PRIVATE_SLOT(d, void customAnimReceiverDestroyed(QObject*))
|
2009-12-21 19:36:39 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void scrollStateChanged(QAbstractAnimation::State,
|
|
|
|
QAbstractAnimation::State))
|
2010-11-04 09:06:43 +01:00
|
|
|
#else
|
|
|
|
Animator();
|
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-12-21 19:36:39 +01:00
|
|
|
friend class AnimatorPrivate;
|
2009-10-21 03:51:31 +02:00
|
|
|
AnimatorPrivate * const d;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|