5a5131999f226753174609f5e31cb6c21005d8e0
[profile/ivi/qtdeclarative.git] / src / quick / util / qquickanimation_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKANIMATION_H
43 #define QQUICKANIMATION_H
44
45 #include "qquickstate_p.h"
46 #include <QtGui/qvector3d.h>
47
48 #include <qqmlpropertyvaluesource.h>
49 #include <qqml.h>
50 #include <qqmlscriptstring.h>
51
52 #include <QtCore/qvariant.h>
53 #include <QtCore/qeasingcurve.h>
54 #include "private/qabstractanimationjob_p.h"
55 #include <QtGui/qcolor.h>
56
57 QT_BEGIN_HEADER
58
59 QT_BEGIN_NAMESPACE
60
61 class QQuickAbstractAnimationPrivate;
62 class QQuickAnimationGroup;
63 class Q_QUICK_PRIVATE_EXPORT QQuickAbstractAnimation : public QObject, public QQmlPropertyValueSource, public QQmlParserStatus
64 {
65     Q_OBJECT
66     Q_DECLARE_PRIVATE(QQuickAbstractAnimation)
67
68     Q_INTERFACES(QQmlParserStatus)
69     Q_INTERFACES(QQmlPropertyValueSource)
70     Q_ENUMS(Loops)
71     Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
72     Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
73     Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged)
74     Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopCountChanged)
75     Q_CLASSINFO("DefaultMethod", "start()")
76
77 public:
78     QQuickAbstractAnimation(QObject *parent=0);
79     virtual ~QQuickAbstractAnimation();
80
81     enum Loops { Infinite = -2 };
82
83     bool isRunning() const;
84     void setRunning(bool);
85     bool isPaused() const;
86     void setPaused(bool);
87     bool alwaysRunToEnd() const;
88     void setAlwaysRunToEnd(bool);
89
90     int loops() const;
91     void setLoops(int);
92     int duration() const;
93
94     int currentTime();
95     void setCurrentTime(int);
96
97     QQuickAnimationGroup *group() const;
98     void setGroup(QQuickAnimationGroup *);
99
100     void setDefaultTarget(const QQmlProperty &);
101     void setDisableUserControl();
102     void setEnableUserControl();
103     bool userControlDisabled() const;
104     void classBegin();
105     void componentComplete();
106
107 Q_SIGNALS:
108     void started();
109     void completed();
110     void runningChanged(bool);
111     void pausedChanged(bool);
112     void alwaysRunToEndChanged(bool);
113     void loopCountChanged(int);
114
115 public Q_SLOTS:
116     void restart();
117     void start();
118     void pause();
119     void resume();
120     void stop();
121     void complete();
122
123 protected:
124     QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent);
125     QAbstractAnimationJob* initInstance(QAbstractAnimationJob *animation);
126
127 public:
128     enum TransitionDirection { Forward, Backward };
129     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
130                             QQmlProperties &modified,
131                             TransitionDirection direction,
132                             QObject *defaultTarget = 0);
133     QAbstractAnimationJob* qtAnimation();
134
135 private Q_SLOTS:
136     void componentFinalized();
137 private:
138     virtual void setTarget(const QQmlProperty &);
139     void notifyRunningChanged(bool running);
140     friend class QQuickBehavior;
141     friend class QQuickBehaviorPrivate;
142 };
143
144 class QQuickPauseAnimationPrivate;
145 class Q_QUICK_PRIVATE_EXPORT QQuickPauseAnimation : public QQuickAbstractAnimation
146 {
147     Q_OBJECT
148     Q_DECLARE_PRIVATE(QQuickPauseAnimation)
149
150     Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
151
152 public:
153     QQuickPauseAnimation(QObject *parent=0);
154     virtual ~QQuickPauseAnimation();
155
156     int duration() const;
157     void setDuration(int);
158
159 Q_SIGNALS:
160     void durationChanged(int);
161
162 protected:
163     QAbstractAnimationJob* transition(QQuickStateActions &actions,
164                                           QQmlProperties &modified,
165                                           TransitionDirection direction,
166                                           QObject *defaultTarget = 0);
167 };
168
169 class QQuickScriptActionPrivate;
170 class QQuickScriptAction : public QQuickAbstractAnimation
171 {
172     Q_OBJECT
173     Q_DECLARE_PRIVATE(QQuickScriptAction)
174
175     Q_PROPERTY(QQmlScriptString script READ script WRITE setScript)
176     Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
177
178 public:
179     QQuickScriptAction(QObject *parent=0);
180     virtual ~QQuickScriptAction();
181
182     QQmlScriptString script() const;
183     void setScript(const QQmlScriptString &);
184
185     QString stateChangeScriptName() const;
186     void setStateChangeScriptName(const QString &);
187
188 protected:
189     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
190                             QQmlProperties &modified,
191                             TransitionDirection direction,
192                             QObject *defaultTarget = 0);
193 };
194
195 class QQuickPropertyActionPrivate;
196 class QQuickPropertyAction : public QQuickAbstractAnimation
197 {
198     Q_OBJECT
199     Q_DECLARE_PRIVATE(QQuickPropertyAction)
200
201     Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
202     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
203     Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
204     Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
205     Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
206     Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
207
208 public:
209     QQuickPropertyAction(QObject *parent=0);
210     virtual ~QQuickPropertyAction();
211
212     QObject *target() const;
213     void setTargetObject(QObject *);
214
215     QString property() const;
216     void setProperty(const QString &);
217
218     QString properties() const;
219     void setProperties(const QString &);
220
221     QQmlListProperty<QObject> targets();
222     QQmlListProperty<QObject> exclude();
223
224     QVariant value() const;
225     void setValue(const QVariant &);
226
227 Q_SIGNALS:
228     void valueChanged(const QVariant &);
229     void propertiesChanged(const QString &);
230     void targetChanged();
231     void propertyChanged();
232
233 protected:
234     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
235                             QQmlProperties &modified,
236                             TransitionDirection direction,
237                             QObject *defaultTarget = 0);
238 };
239
240 class QQuickPropertyAnimationPrivate;
241 class Q_QUICK_PRIVATE_EXPORT QQuickPropertyAnimation : public QQuickAbstractAnimation
242 {
243     Q_OBJECT
244     Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
245
246     Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
247     Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged)
248     Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged)
249     Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
250     Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
251     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
252     Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
253     Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
254     Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
255
256 public:
257     QQuickPropertyAnimation(QObject *parent=0);
258     virtual ~QQuickPropertyAnimation();
259
260     virtual int duration() const;
261     virtual void setDuration(int);
262
263     QVariant from() const;
264     void setFrom(const QVariant &);
265
266     QVariant to() const;
267     void setTo(const QVariant &);
268
269     QEasingCurve easing() const;
270     void setEasing(const QEasingCurve &);
271
272     QObject *target() const;
273     void setTargetObject(QObject *);
274
275     QString property() const;
276     void setProperty(const QString &);
277
278     QString properties() const;
279     void setProperties(const QString &);
280
281     QQmlListProperty<QObject> targets();
282     QQmlListProperty<QObject> exclude();
283
284 protected:
285     QQuickStateActions createTransitionActions(QQuickStateActions &actions,
286                                                      QQmlProperties &modified,
287                                                      QObject *defaultTarget = 0);
288
289     QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
290     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
291                             QQmlProperties &modified,
292                             TransitionDirection direction,
293                             QObject *defaultTarget = 0);
294 Q_SIGNALS:
295     void durationChanged(int);
296     void fromChanged(QVariant);
297     void toChanged(QVariant);
298     void easingChanged(const QEasingCurve &);
299     void propertiesChanged(const QString &);
300     void targetChanged();
301     void propertyChanged();
302 };
303
304 class Q_QUICK_PRIVATE_EXPORT QQuickColorAnimation : public QQuickPropertyAnimation
305 {
306     Q_OBJECT
307     Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
308     Q_PROPERTY(QColor from READ from WRITE setFrom)
309     Q_PROPERTY(QColor to READ to WRITE setTo)
310
311 public:
312     QQuickColorAnimation(QObject *parent=0);
313     virtual ~QQuickColorAnimation();
314
315     QColor from() const;
316     void setFrom(const QColor &);
317
318     QColor to() const;
319     void setTo(const QColor &);
320 };
321
322 class Q_QUICK_PRIVATE_EXPORT QQuickNumberAnimation : public QQuickPropertyAnimation
323 {
324     Q_OBJECT
325     Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
326
327     Q_PROPERTY(qreal from READ from WRITE setFrom)
328     Q_PROPERTY(qreal to READ to WRITE setTo)
329
330 public:
331     QQuickNumberAnimation(QObject *parent=0);
332     virtual ~QQuickNumberAnimation();
333
334     qreal from() const;
335     void setFrom(qreal);
336
337     qreal to() const;
338     void setTo(qreal);
339
340 protected:
341     QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
342
343 private:
344     void init();
345 };
346
347 class Q_QUICK_PRIVATE_EXPORT QQuickVector3dAnimation : public QQuickPropertyAnimation
348 {
349     Q_OBJECT
350     Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
351
352     Q_PROPERTY(QVector3D from READ from WRITE setFrom)
353     Q_PROPERTY(QVector3D to READ to WRITE setTo)
354
355 public:
356     QQuickVector3dAnimation(QObject *parent=0);
357     virtual ~QQuickVector3dAnimation();
358
359     QVector3D from() const;
360     void setFrom(QVector3D);
361
362     QVector3D to() const;
363     void setTo(QVector3D);
364 };
365
366 class QQuickRotationAnimationPrivate;
367 class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimation : public QQuickPropertyAnimation
368 {
369     Q_OBJECT
370     Q_DECLARE_PRIVATE(QQuickRotationAnimation)
371     Q_ENUMS(RotationDirection)
372
373     Q_PROPERTY(qreal from READ from WRITE setFrom)
374     Q_PROPERTY(qreal to READ to WRITE setTo)
375     Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
376
377 public:
378     QQuickRotationAnimation(QObject *parent=0);
379     virtual ~QQuickRotationAnimation();
380
381     qreal from() const;
382     void setFrom(qreal);
383
384     qreal to() const;
385     void setTo(qreal);
386
387     enum RotationDirection { Numerical, Shortest, Clockwise, Counterclockwise };
388     RotationDirection direction() const;
389     void setDirection(RotationDirection direction);
390
391 Q_SIGNALS:
392     void directionChanged();
393 };
394
395 class QQuickAnimationGroupPrivate;
396 class Q_QUICK_PRIVATE_EXPORT QQuickAnimationGroup : public QQuickAbstractAnimation
397 {
398     Q_OBJECT
399     Q_DECLARE_PRIVATE(QQuickAnimationGroup)
400
401     Q_CLASSINFO("DefaultProperty", "animations")
402     Q_PROPERTY(QQmlListProperty<QQuickAbstractAnimation> animations READ animations)
403
404 public:
405     QQuickAnimationGroup(QObject *parent);
406     virtual ~QQuickAnimationGroup();
407
408     QQmlListProperty<QQuickAbstractAnimation> animations();
409     friend class QQuickAbstractAnimation;
410
411 protected:
412     QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent);
413 };
414
415 class QQuickSequentialAnimation : public QQuickAnimationGroup
416 {
417     Q_OBJECT
418     Q_DECLARE_PRIVATE(QQuickAnimationGroup)
419
420 public:
421     QQuickSequentialAnimation(QObject *parent=0);
422     virtual ~QQuickSequentialAnimation();
423
424 protected:
425     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
426                             QQmlProperties &modified,
427                             TransitionDirection direction,
428                             QObject *defaultTarget = 0);
429 };
430
431 class Q_QUICK_PRIVATE_EXPORT QQuickParallelAnimation : public QQuickAnimationGroup
432 {
433     Q_OBJECT
434     Q_DECLARE_PRIVATE(QQuickAnimationGroup)
435
436 public:
437     QQuickParallelAnimation(QObject *parent=0);
438     virtual ~QQuickParallelAnimation();
439
440 protected:
441     virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
442                             QQmlProperties &modified,
443                             TransitionDirection direction,
444                             QObject *defaultTarget = 0);
445 };
446
447
448 QT_END_NAMESPACE
449
450 QML_DECLARE_TYPE(QQuickAbstractAnimation)
451 QML_DECLARE_TYPE(QQuickPauseAnimation)
452 QML_DECLARE_TYPE(QQuickScriptAction)
453 QML_DECLARE_TYPE(QQuickPropertyAction)
454 QML_DECLARE_TYPE(QQuickPropertyAnimation)
455 QML_DECLARE_TYPE(QQuickColorAnimation)
456 QML_DECLARE_TYPE(QQuickNumberAnimation)
457 QML_DECLARE_TYPE(QQuickSequentialAnimation)
458 QML_DECLARE_TYPE(QQuickParallelAnimation)
459 QML_DECLARE_TYPE(QQuickVector3dAnimation)
460 QML_DECLARE_TYPE(QQuickRotationAnimation)
461
462 QT_END_HEADER
463
464 #endif // QQUICKANIMATION_H