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