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
83 QML_NAMED_ELEMENT(Animation)
84 QML_UNCREATABLE("Animation is an abstract class")
85
86public:
87 enum ThreadingModel {
88 GuiThread,
89 RenderThread,
90 AnyThread
91 };
92
93 QQuickAbstractAnimation(QObject *parent=nullptr);
94 ~QQuickAbstractAnimation() override;
95
96 enum Loops { Infinite = -2 };
97 Q_ENUM(Loops)
98
99 bool isRunning() const;
100 void setRunning(bool);
101 bool isPaused() const;
102 void setPaused(bool);
103 bool alwaysRunToEnd() const;
104 void setAlwaysRunToEnd(bool);
105
106 int loops() const;
107 void setLoops(int);
108 int duration() const;
109
110 int currentTime();
111 void setCurrentTime(int);
112
113 QQuickAnimationGroup *group() const;
114 void setGroup(QQuickAnimationGroup *, int index = -1);
115
116 void setDefaultTarget(const QQmlProperty &);
117 void setDisableUserControl();
118 void setEnableUserControl();
119 bool userControlDisabled() const;
120 void classBegin() override;
121 void componentComplete() override;
122
123 virtual ThreadingModel threadingModel() const;
124
125Q_SIGNALS:
126 void started();
127 void stopped();
128 void runningChanged(bool);
129 void pausedChanged(bool);
130 void alwaysRunToEndChanged(bool);
131 void loopCountChanged(int);
132 Q_REVISION(12) void finished();
133
134public Q_SLOTS:
135 void restart();
136 void start();
137 void pause();
138 void resume();
139 void stop();
140 void complete();
141
142protected:
143 QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent);
144 QAbstractAnimationJob* initInstance(QAbstractAnimationJob *animation);
145
146public:
147 enum TransitionDirection { Forward, Backward };
148 virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
149 QQmlProperties &modified,
150 TransitionDirection direction,
151 QObject *defaultTarget = nullptr);
152 QAbstractAnimationJob* qtAnimation();
153
154private Q_SLOTS:
155 void componentFinalized();
156private:
157 void setTarget(const QQmlProperty &) override;
158 void notifyRunningChanged(bool running);
159 friend class QQuickBehavior;
160 friend class QQuickBehaviorPrivate;
161 friend class QQuickAnimationGroup;
162};
163
164class QQuickPauseAnimationPrivate;
165class Q_QUICK_PRIVATE_EXPORT QQuickPauseAnimation : public QQuickAbstractAnimation
166{
167 Q_OBJECT
168 Q_DECLARE_PRIVATE(QQuickPauseAnimation)
169
170 Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
171 QML_NAMED_ELEMENT(PauseAnimation)
172
173public:
174 QQuickPauseAnimation(QObject *parent=nullptr);
175 ~QQuickPauseAnimation() override;
176
177 int duration() const;
178 void setDuration(int);
179
180Q_SIGNALS:
181 void durationChanged(int);
182
183protected:
184 QAbstractAnimationJob* transition(QQuickStateActions &actions,
185 QQmlProperties &modified,
186 TransitionDirection direction,
187 QObject *defaultTarget = nullptr) override;
188};
189
190class QQuickScriptActionPrivate;
191class QQuickScriptAction : public QQuickAbstractAnimation
192{
193 Q_OBJECT
194 Q_DECLARE_PRIVATE(QQuickScriptAction)
195
196 Q_PROPERTY(QQmlScriptString script READ script WRITE setScript)
197 Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
198 QML_NAMED_ELEMENT(ScriptAction)
199
200public:
201 QQuickScriptAction(QObject *parent=nullptr);
202 ~QQuickScriptAction() override;
203
204 QQmlScriptString script() const;
205 void setScript(const QQmlScriptString &);
206
207 QString stateChangeScriptName() const;
208 void setStateChangeScriptName(const QString &);
209
210protected:
211 QAbstractAnimationJob* transition(QQuickStateActions &actions,
212 QQmlProperties &modified,
213 TransitionDirection direction,
214 QObject *defaultTarget = nullptr) override;
215};
216
217class QQuickPropertyActionPrivate;
218class QQuickPropertyAction : public QQuickAbstractAnimation
219{
220 Q_OBJECT
221 Q_DECLARE_PRIVATE(QQuickPropertyAction)
222
223 Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
224 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
225 Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
226 Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
227 Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
228 Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
229 QML_NAMED_ELEMENT(PropertyAction)
230
231public:
232 QQuickPropertyAction(QObject *parent=nullptr);
233 ~QQuickPropertyAction() override;
234
235 QObject *target() const;
236 void setTargetObject(QObject *);
237
238 QString property() const;
239 void setProperty(const QString &);
240
241 QString properties() const;
242 void setProperties(const QString &);
243
244 QQmlListProperty<QObject> targets();
245 QQmlListProperty<QObject> exclude();
246
247 QVariant value() const;
248 void setValue(const QVariant &);
249
250Q_SIGNALS:
251 void valueChanged(const QVariant &);
252 void propertiesChanged(const QString &);
253 void targetChanged();
254 void propertyChanged();
255
256protected:
257 QAbstractAnimationJob* transition(QQuickStateActions &actions,
258 QQmlProperties &modified,
259 TransitionDirection direction,
260 QObject *defaultTarget = nullptr) override;
261};
262
263class QQuickPropertyAnimationPrivate;
264class Q_QUICK_PRIVATE_EXPORT QQuickPropertyAnimation : public QQuickAbstractAnimation
265{
266 Q_OBJECT
267 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
268
269 Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
270 Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged)
271 Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged)
272 Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
273 Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
274 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
275 Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
276 Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
277 Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
278 QML_NAMED_ELEMENT(PropertyAnimation)
279
280public:
281 QQuickPropertyAnimation(QObject *parent=nullptr);
282 ~QQuickPropertyAnimation() override;
283
284 virtual int duration() const;
285 virtual void setDuration(int);
286
287 QVariant from() const;
288 void setFrom(const QVariant &);
289
290 QVariant to() const;
291 void setTo(const QVariant &);
292
293 QEasingCurve easing() const;
294 void setEasing(const QEasingCurve &);
295
296 QObject *target() const;
297 void setTargetObject(QObject *);
298
299 QString property() const;
300 void setProperty(const QString &);
301
302 QString properties() const;
303 void setProperties(const QString &);
304
305 QQmlListProperty<QObject> targets();
306 QQmlListProperty<QObject> exclude();
307
308protected:
309 QQuickStateActions createTransitionActions(QQuickStateActions &actions,
310 QQmlProperties &modified,
311 QObject *defaultTarget = nullptr);
312
313 QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
314 QAbstractAnimationJob* transition(QQuickStateActions &actions,
315 QQmlProperties &modified,
316 TransitionDirection direction,
317 QObject *defaultTarget = nullptr) override;
318Q_SIGNALS:
319 void durationChanged(int);
320 void fromChanged();
321 void toChanged();
322 void easingChanged(const QEasingCurve &);
323 void propertiesChanged(const QString &);
324 void targetChanged();
325 void propertyChanged();
326};
327
328class Q_QUICK_PRIVATE_EXPORT QQuickColorAnimation : public QQuickPropertyAnimation
329{
330 Q_OBJECT
331 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
332 Q_PROPERTY(QColor from READ from WRITE setFrom)
333 Q_PROPERTY(QColor to READ to WRITE setTo)
334 QML_NAMED_ELEMENT(ColorAnimation)
335
336public:
337 QQuickColorAnimation(QObject *parent=nullptr);
338 ~QQuickColorAnimation() override;
339
340 QColor from() const;
341 void setFrom(const QColor &);
342
343 QColor to() const;
344 void setTo(const QColor &);
345};
346
347class Q_QUICK_PRIVATE_EXPORT QQuickNumberAnimation : public QQuickPropertyAnimation
348{
349 Q_OBJECT
350 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
351
352 Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
353 Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
354 QML_NAMED_ELEMENT(NumberAnimation)
355
356public:
357 QQuickNumberAnimation(QObject *parent=nullptr);
358 ~QQuickNumberAnimation() override;
359
360 qreal from() const;
361 void setFrom(qreal);
362
363 qreal to() const;
364 void setTo(qreal);
365
366protected:
367 QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
368
369private:
370 void init();
371};
372
373class Q_QUICK_PRIVATE_EXPORT QQuickVector3dAnimation : public QQuickPropertyAnimation
374{
375 Q_OBJECT
376 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
377
378 Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged)
379 Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged)
380 QML_NAMED_ELEMENT(Vector3dAnimation)
381
382public:
383 QQuickVector3dAnimation(QObject *parent=nullptr);
384 ~QQuickVector3dAnimation() override;
385
386 QVector3D from() const;
387 void setFrom(QVector3D);
388
389 QVector3D to() const;
390 void setTo(QVector3D);
391};
392
393class QQuickRotationAnimationPrivate;
394class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimation : public QQuickPropertyAnimation
395{
396 Q_OBJECT
397 Q_DECLARE_PRIVATE(QQuickRotationAnimation)
398
399 Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
400 Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
401 Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
402 QML_NAMED_ELEMENT(RotationAnimation)
403
404public:
405 QQuickRotationAnimation(QObject *parent=nullptr);
406 ~QQuickRotationAnimation() override;
407
408 qreal from() const;
409 void setFrom(qreal);
410
411 qreal to() const;
412 void setTo(qreal);
413
414 enum RotationDirection { Numerical, Shortest, Clockwise, Counterclockwise };
415 Q_ENUM(RotationDirection)
416 RotationDirection direction() const;
417 void setDirection(RotationDirection direction);
418
419Q_SIGNALS:
420 void directionChanged();
421};
422
423class QQuickAnimationGroupPrivate;
424class Q_QUICK_PRIVATE_EXPORT QQuickAnimationGroup : public QQuickAbstractAnimation
425{
426 Q_OBJECT
427 Q_DECLARE_PRIVATE(QQuickAnimationGroup)
428
429 Q_CLASSINFO("DefaultProperty", "animations")
430 Q_PROPERTY(QQmlListProperty<QQuickAbstractAnimation> animations READ animations)
431
432public:
433 QQuickAnimationGroup(QObject *parent);
434 ~QQuickAnimationGroup() override;
435
436 QQmlListProperty<QQuickAbstractAnimation> animations();
437 friend class QQuickAbstractAnimation;
438
439protected:
440 QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent);
441};
442
443class QQuickSequentialAnimation : public QQuickAnimationGroup
444{
445 Q_OBJECT
446 Q_DECLARE_PRIVATE(QQuickAnimationGroup)
447 QML_NAMED_ELEMENT(SequentialAnimation)
448
449public:
450 QQuickSequentialAnimation(QObject *parent=nullptr);
451 ~QQuickSequentialAnimation() override;
452
453protected:
454 ThreadingModel threadingModel() const override;
455 QAbstractAnimationJob* transition(QQuickStateActions &actions,
456 QQmlProperties &modified,
457 TransitionDirection direction,
458 QObject *defaultTarget = nullptr) override;
459};
460
461class Q_QUICK_PRIVATE_EXPORT QQuickParallelAnimation : public QQuickAnimationGroup
462{
463 Q_OBJECT
464 Q_DECLARE_PRIVATE(QQuickAnimationGroup)
465 QML_NAMED_ELEMENT(ParallelAnimation)
466
467public:
468 QQuickParallelAnimation(QObject *parent=nullptr);
469 ~QQuickParallelAnimation() override;
470
471protected:
472 ThreadingModel threadingModel() const override;
473 QAbstractAnimationJob* transition(QQuickStateActions &actions,
474 QQmlProperties &modified,
475 TransitionDirection direction,
476 QObject *defaultTarget = nullptr) override;
477};
478
479
480QT_END_NAMESPACE
481
482QML_DECLARE_TYPE(QQuickAbstractAnimation)
483QML_DECLARE_TYPE(QQuickPauseAnimation)
484QML_DECLARE_TYPE(QQuickScriptAction)
485QML_DECLARE_TYPE(QQuickPropertyAction)
486QML_DECLARE_TYPE(QQuickPropertyAnimation)
487QML_DECLARE_TYPE(QQuickColorAnimation)
488QML_DECLARE_TYPE(QQuickNumberAnimation)
489QML_DECLARE_TYPE(QQuickSequentialAnimation)
490QML_DECLARE_TYPE(QQuickParallelAnimation)
491QML_DECLARE_TYPE(QQuickVector3dAnimation)
492QML_DECLARE_TYPE(QQuickRotationAnimation)
493
494#endif // QQUICKANIMATION_H
495

source code of qtdeclarative/src/quick/util/qquickanimation_p.h