Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickanimation_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKANIMATION_H
6#define QQUICKANIMATION_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qquickstate_p.h"
20#include <QtGui/qvector3d.h>
21
22#include <qqmlpropertyvaluesource.h>
23#include <qqml.h>
24#include <qqmlscriptstring.h>
25
26#include <QtCore/qvariant.h>
27#include <QtCore/qeasingcurve.h>
28#include "private/qabstractanimationjob_p.h"
29#include <QtGui/qcolor.h>
30
31QT_BEGIN_NAMESPACE
32
33class QQuickAbstractAnimationPrivate;
34class QQuickAnimationGroup;
35class Q_QUICK_EXPORT QQuickAbstractAnimation : public QObject, public QQmlPropertyValueSource, public QQmlParserStatus
36{
37 Q_OBJECT
38 Q_DECLARE_PRIVATE(QQuickAbstractAnimation)
39
40 Q_INTERFACES(QQmlParserStatus)
41 Q_INTERFACES(QQmlPropertyValueSource)
42 Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
43 Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
44 Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged)
45 Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopCountChanged)
46 Q_CLASSINFO("DefaultMethod", "start()")
47
48 QML_NAMED_ELEMENT(Animation)
49 QML_ADDED_IN_VERSION(2, 0)
50 QML_UNCREATABLE("Animation is an abstract class")
51
52public:
53 enum ThreadingModel {
54 GuiThread,
55 RenderThread,
56 AnyThread
57 };
58
59 QQuickAbstractAnimation(QObject *parent=nullptr);
60 ~QQuickAbstractAnimation() override;
61
62 enum Loops { Infinite = -2 };
63 Q_ENUM(Loops)
64
65 bool isRunning() const;
66 void setRunning(bool);
67 bool isPaused() const;
68 void setPaused(bool);
69 bool alwaysRunToEnd() const;
70 void setAlwaysRunToEnd(bool);
71
72 int loops() const;
73 void setLoops(int);
74 int duration() const;
75
76 int currentTime();
77 void setCurrentTime(int);
78
79 QQuickAnimationGroup *group() const;
80 void setGroup(QQuickAnimationGroup *, int index = -1);
81
82 void setDefaultTarget(const QQmlProperty &);
83 void setDisableUserControl();
84 void setEnableUserControl();
85 bool userControlDisabled() const;
86 void classBegin() override;
87 void componentComplete() override;
88
89 virtual ThreadingModel threadingModel() const;
90
91Q_SIGNALS:
92 void started();
93 void stopped();
94 void runningChanged(bool);
95 void pausedChanged(bool);
96 void alwaysRunToEndChanged(bool);
97 void loopCountChanged(int);
98 Q_REVISION(2, 12) void finished();
99
100public Q_SLOTS:
101 void restart();
102 void start();
103 void pause();
104 void resume();
105 void stop();
106 void complete();
107
108protected:
109 QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent);
110 QAbstractAnimationJob* initInstance(QAbstractAnimationJob *animation);
111
112public:
113 enum TransitionDirection { Forward, Backward };
114 virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
115 QQmlProperties &modified,
116 TransitionDirection direction,
117 QObject *defaultTarget = nullptr);
118 QAbstractAnimationJob* qtAnimation();
119
120private:
121 void setTarget(const QQmlProperty &) override;
122 void notifyRunningChanged(bool running);
123 friend class QQuickBehavior;
124 friend class QQuickBehaviorPrivate;
125 friend class QQuickAnimationGroup;
126};
127
129class Q_QUICK_EXPORT QQuickPauseAnimation : public QQuickAbstractAnimation
130{
131 Q_OBJECT
132 Q_DECLARE_PRIVATE(QQuickPauseAnimation)
133
134 Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
135 QML_NAMED_ELEMENT(PauseAnimation)
136 QML_ADDED_IN_VERSION(2, 0)
137
138public:
139 QQuickPauseAnimation(QObject *parent=nullptr);
140 ~QQuickPauseAnimation() override;
141
142 int duration() const;
143 void setDuration(int);
144
145Q_SIGNALS:
146 void durationChanged(int);
147
148protected:
149 QAbstractAnimationJob* transition(QQuickStateActions &actions,
150 QQmlProperties &modified,
151 TransitionDirection direction,
152 QObject *defaultTarget = nullptr) override;
153};
154
156class Q_QUICK_EXPORT QQuickScriptAction : public QQuickAbstractAnimation
157{
158 Q_OBJECT
159 Q_DECLARE_PRIVATE(QQuickScriptAction)
160
161 Q_PROPERTY(QQmlScriptString script READ script WRITE setScript)
162 Q_PROPERTY(QString scriptName READ stateChangeScriptName WRITE setStateChangeScriptName)
163 QML_NAMED_ELEMENT(ScriptAction)
164 QML_ADDED_IN_VERSION(2, 0)
165
166public:
167 QQuickScriptAction(QObject *parent=nullptr);
168 ~QQuickScriptAction() override;
169
170 QQmlScriptString script() const;
171 void setScript(const QQmlScriptString &);
172
173 QString stateChangeScriptName() const;
174 void setStateChangeScriptName(const QString &);
175
176protected:
177 QAbstractAnimationJob* transition(QQuickStateActions &actions,
178 QQmlProperties &modified,
179 TransitionDirection direction,
180 QObject *defaultTarget = nullptr) override;
181};
182
184class Q_QUICK_EXPORT QQuickPropertyAction : public QQuickAbstractAnimation
185{
186 Q_OBJECT
187 Q_DECLARE_PRIVATE(QQuickPropertyAction)
188
189 Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
190 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
191 Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
192 Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
193 Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
194 Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
195 QML_NAMED_ELEMENT(PropertyAction)
196 QML_ADDED_IN_VERSION(2, 0)
197
198public:
199 QQuickPropertyAction(QObject *parent=nullptr);
200 ~QQuickPropertyAction() override;
201
202 QObject *target() const;
203 void setTargetObject(QObject *);
204
205 QString property() const;
206 void setProperty(const QString &);
207
208 QString properties() const;
209 void setProperties(const QString &);
210
211 QQmlListProperty<QObject> targets();
212 QQmlListProperty<QObject> exclude();
213
214 QVariant value() const;
215 void setValue(const QVariant &);
216
217Q_SIGNALS:
218 void valueChanged(const QVariant &);
219 void propertiesChanged(const QString &);
220 void targetChanged();
221 void propertyChanged();
222
223protected:
224 QAbstractAnimationJob* transition(QQuickStateActions &actions,
225 QQmlProperties &modified,
226 TransitionDirection direction,
227 QObject *defaultTarget = nullptr) override;
228};
229
230class QQuickPropertyAnimationPrivate;
231class Q_QUICK_EXPORT QQuickPropertyAnimation : public QQuickAbstractAnimation
232{
233 Q_OBJECT
234 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
235
236 Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
237 Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged)
238 Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged)
239 Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
240 Q_PROPERTY(QObject *target READ target WRITE setTargetObject NOTIFY targetChanged)
241 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
242 Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged)
243 Q_PROPERTY(QQmlListProperty<QObject> targets READ targets)
244 Q_PROPERTY(QQmlListProperty<QObject> exclude READ exclude)
245 QML_NAMED_ELEMENT(PropertyAnimation)
246 QML_ADDED_IN_VERSION(2, 0)
247
248public:
249 QQuickPropertyAnimation(QObject *parent=nullptr);
250 ~QQuickPropertyAnimation() override;
251
252 virtual int duration() const;
253 virtual void setDuration(int);
254
255 QVariant from() const;
256 void setFrom(const QVariant &);
257
258 QVariant to() const;
259 void setTo(const QVariant &);
260
261 QEasingCurve easing() const;
262 void setEasing(const QEasingCurve &);
263
264 QObject *target() const;
265 void setTargetObject(QObject *);
266
267 QString property() const;
268 void setProperty(const QString &);
269
270 QString properties() const;
271 void setProperties(const QString &);
272
273 QQmlListProperty<QObject> targets();
274 QQmlListProperty<QObject> exclude();
275
276protected:
277 QQuickStateActions createTransitionActions(QQuickStateActions &actions,
278 QQmlProperties &modified,
279 QObject *defaultTarget = nullptr);
280
281 QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
282 QAbstractAnimationJob* transition(QQuickStateActions &actions,
283 QQmlProperties &modified,
284 TransitionDirection direction,
285 QObject *defaultTarget = nullptr) override;
286Q_SIGNALS:
287 void durationChanged(int);
288 void fromChanged();
289 void toChanged();
290 void easingChanged(const QEasingCurve &);
291 void propertiesChanged(const QString &);
292 void targetChanged();
293 void propertyChanged();
294};
295
296class Q_QUICK_EXPORT QQuickColorAnimation : public QQuickPropertyAnimation
297{
298 Q_OBJECT
299 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
300 Q_PROPERTY(QColor from READ from WRITE setFrom)
301 Q_PROPERTY(QColor to READ to WRITE setTo)
302 QML_NAMED_ELEMENT(ColorAnimation)
303 QML_ADDED_IN_VERSION(2, 0)
304
305public:
306 QQuickColorAnimation(QObject *parent=nullptr);
307 ~QQuickColorAnimation() override;
308
309 QColor from() const;
310 void setFrom(const QColor &);
311
312 QColor to() const;
313 void setTo(const QColor &);
314};
315
316class Q_QUICK_EXPORT QQuickNumberAnimation : public QQuickPropertyAnimation
317{
318 Q_OBJECT
319 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
320
321 Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
322 Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
323 QML_NAMED_ELEMENT(NumberAnimation)
324 QML_ADDED_IN_VERSION(2, 0)
325
326public:
327 QQuickNumberAnimation(QObject *parent=nullptr);
328 ~QQuickNumberAnimation() override;
329
330 qreal from() const;
331 void setFrom(qreal);
332
333 qreal to() const;
334 void setTo(qreal);
335
336protected:
337 QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
338
339private:
340 void init();
341};
342
343class Q_QUICK_EXPORT QQuickVector3dAnimation : public QQuickPropertyAnimation
344{
345 Q_OBJECT
346 Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
347
348 Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged)
349 Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged)
350 QML_NAMED_ELEMENT(Vector3dAnimation)
351 QML_ADDED_IN_VERSION(2, 0)
352
353public:
354 QQuickVector3dAnimation(QObject *parent=nullptr);
355 ~QQuickVector3dAnimation() override;
356
357 QVector3D from() const;
358 void setFrom(QVector3D);
359
360 QVector3D to() const;
361 void setTo(QVector3D);
362};
363
365class Q_QUICK_EXPORT QQuickRotationAnimation : public QQuickPropertyAnimation
366{
367 Q_OBJECT
368 Q_DECLARE_PRIVATE(QQuickRotationAnimation)
369
370 Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
371 Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
372 Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
373 QML_NAMED_ELEMENT(RotationAnimation)
374 QML_ADDED_IN_VERSION(2, 0)
375
376public:
377 QQuickRotationAnimation(QObject *parent=nullptr);
378 ~QQuickRotationAnimation() override;
379
380 qreal from() const;
381 void setFrom(qreal);
382
383 qreal to() const;
384 void setTo(qreal);
385
386 enum RotationDirection { Numerical, Shortest, Clockwise, Counterclockwise };
387 Q_ENUM(RotationDirection)
388 RotationDirection direction() const;
389 void setDirection(RotationDirection direction);
390
391Q_SIGNALS:
392 void directionChanged();
393};
394
396class Q_QUICK_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
404public:
405 QQuickAnimationGroup(QObject *parent);
406 ~QQuickAnimationGroup() override;
407
408 QQmlListProperty<QQuickAbstractAnimation> animations();
409 friend class QQuickAbstractAnimation;
410
411protected:
412 QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent);
413};
414
415class Q_QUICK_EXPORT QQuickSequentialAnimation : public QQuickAnimationGroup
416{
417 Q_OBJECT
418 Q_DECLARE_PRIVATE(QQuickAnimationGroup)
419 QML_NAMED_ELEMENT(SequentialAnimation)
420 QML_ADDED_IN_VERSION(2, 0)
421
422public:
423 QQuickSequentialAnimation(QObject *parent=nullptr);
424 ~QQuickSequentialAnimation() override;
425
426protected:
427 ThreadingModel threadingModel() const override;
428 QAbstractAnimationJob* transition(QQuickStateActions &actions,
429 QQmlProperties &modified,
430 TransitionDirection direction,
431 QObject *defaultTarget = nullptr) override;
432};
433
434class Q_QUICK_EXPORT QQuickParallelAnimation : public QQuickAnimationGroup
435{
436 Q_OBJECT
437 Q_DECLARE_PRIVATE(QQuickAnimationGroup)
438 QML_NAMED_ELEMENT(ParallelAnimation)
439 QML_ADDED_IN_VERSION(2, 0)
440
441public:
442 QQuickParallelAnimation(QObject *parent=nullptr);
443 ~QQuickParallelAnimation() override;
444
445protected:
446 ThreadingModel threadingModel() const override;
447 QAbstractAnimationJob* transition(QQuickStateActions &actions,
448 QQmlProperties &modified,
449 TransitionDirection direction,
450 QObject *defaultTarget = nullptr) override;
451};
452
453
454QT_END_NAMESPACE
455
456#endif // QQUICKANIMATION_H
The QQmlScriptString class encapsulates a script and its context.
void animationCurrentLoopChanged(QAbstractAnimationJob *job) override
QAbstractAnimationAction * createAction()
void debugAction(QDebug d, int indentLevel) const
QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress)
QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress)
\qmltype RotationAnimation \nativetype QQuickRotationAnimation \inqmlmodule QtQuick\inherits Property...
QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress)