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