Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickanimationcontroller.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | class QQuickAnimationControllerPrivate : public QObjectPrivate, QAnimationJobChangeListener | - | ||||||||||||
6 | { | - | ||||||||||||
7 | inline QQuickAnimationController* q_func() { return static_cast<QQuickAnimationController *>(q_ptr); } inline const QQuickAnimationController* q_func() const { return static_cast<const QQuickAnimationController *>(q_ptr); } friend class QQuickAnimationController; | - | ||||||||||||
8 | public: | - | ||||||||||||
9 | QQuickAnimationControllerPrivate() | - | ||||||||||||
10 | : progress(0.0), animation(nullptr), animationInstance(nullptr), finalized(false) {} executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
11 | void animationFinished(QAbstractAnimationJob *job) override; | - | ||||||||||||
12 | void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime) override; | - | ||||||||||||
13 | - | |||||||||||||
14 | - | |||||||||||||
15 | qreal progress; | - | ||||||||||||
16 | QQuickAbstractAnimation *animation; | - | ||||||||||||
17 | QAbstractAnimationJob *animationInstance; | - | ||||||||||||
18 | bool finalized:1; | - | ||||||||||||
19 | - | |||||||||||||
20 | }; | - | ||||||||||||
21 | - | |||||||||||||
22 | void QQuickAnimationControllerPrivate::animationFinished(QAbstractAnimationJob *job) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | QQuickAnimationController * const q = q_func(); | - | ||||||||||||
25 | ((animationInstance && animationInstance == job) ? static_cast<void>(0) : qt_assert("animationInstance && animationInstance == job", __FILE__, 67)); | - | ||||||||||||
26 | (void)job;; | - | ||||||||||||
27 | - | |||||||||||||
28 | animationInstance->removeAnimationChangeListener(this, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime); | - | ||||||||||||
29 | - | |||||||||||||
30 | if (animationInstance->direction() == QAbstractAnimationJob::Forward
| 0 | ||||||||||||
31 | progress = 1; | - | ||||||||||||
32 | q->progressChanged(); | - | ||||||||||||
33 | } never executed: else if (animationInstance->direction() == QAbstractAnimationJob::Backwardend of block
| 0 | ||||||||||||
34 | progress = 0; | - | ||||||||||||
35 | q->progressChanged(); | - | ||||||||||||
36 | } never executed: end of block | 0 | ||||||||||||
37 | - | |||||||||||||
38 | } never executed: end of block | 0 | ||||||||||||
39 | - | |||||||||||||
40 | void QQuickAnimationControllerPrivate::animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime) | - | ||||||||||||
41 | { | - | ||||||||||||
42 | QQuickAnimationController * const q = q_func(); | - | ||||||||||||
43 | ((animationInstance && animationInstance == job) ? static_cast<void>(0) : qt_assert("animationInstance && animationInstance == job", __FILE__, 85)); | - | ||||||||||||
44 | (void)job;; | - | ||||||||||||
45 | const qreal newProgress = currentTime * 1.0 / animationInstance->duration(); | - | ||||||||||||
46 | if (progress != newProgress
| 0 | ||||||||||||
47 | progress = newProgress; | - | ||||||||||||
48 | q->progressChanged(); | - | ||||||||||||
49 | } never executed: end of block | 0 | ||||||||||||
50 | } never executed: end of block | 0 | ||||||||||||
51 | QQuickAnimationController::QQuickAnimationController(QObject *parent) | - | ||||||||||||
52 | : QObject(*(new QQuickAnimationControllerPrivate), parent) | - | ||||||||||||
53 | { | - | ||||||||||||
54 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
55 | - | |||||||||||||
56 | QQuickAnimationController::~QQuickAnimationController() | - | ||||||||||||
57 | { | - | ||||||||||||
58 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
59 | delete d->animationInstance; | - | ||||||||||||
60 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
61 | qreal QQuickAnimationController::progress() const | - | ||||||||||||
62 | { | - | ||||||||||||
63 | const QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
64 | return never executed: d->progress;return d->progress; never executed: return d->progress; | 0 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | void QQuickAnimationController::setProgress(qreal progress) | - | ||||||||||||
68 | { | - | ||||||||||||
69 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
70 | progress = qBound(qreal(0), progress, qreal(1)); | - | ||||||||||||
71 | - | |||||||||||||
72 | if (progress != d->progress
| 6-106 | ||||||||||||
73 | d->progress = progress; | - | ||||||||||||
74 | updateProgress(); | - | ||||||||||||
75 | progressChanged(); | - | ||||||||||||
76 | } executed 106 times by 1 test: end of block Executed by:
| 106 | ||||||||||||
77 | } executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||
78 | QQuickAbstractAnimation *QQuickAnimationController::animation() const | - | ||||||||||||
79 | { | - | ||||||||||||
80 | const QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
81 | return never executed: d->animation;return d->animation; never executed: return d->animation; | 0 | ||||||||||||
82 | } | - | ||||||||||||
83 | - | |||||||||||||
84 | void QQuickAnimationController::classBegin() | - | ||||||||||||
85 | { | - | ||||||||||||
86 | QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this)); | - | ||||||||||||
87 | engPriv->registerFinalizeCallback(this, this->metaObject()->indexOfSlot("componentFinalized()")); | - | ||||||||||||
88 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
89 | - | |||||||||||||
90 | - | |||||||||||||
91 | void QQuickAnimationController::setAnimation(QQuickAbstractAnimation *animation) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
94 | - | |||||||||||||
95 | if (animation != d->animation
| 0-10 | ||||||||||||
96 | if (animation
| 0-10 | ||||||||||||
97 | if (animation->userControlDisabled()
| 0-10 | ||||||||||||
98 | qmlWarning(this) << "QQuickAnimationController::setAnimation: the animation is controlled by others, can't be used in AnimationController."; | - | ||||||||||||
99 | return; never executed: return; | 0 | ||||||||||||
100 | } | - | ||||||||||||
101 | animation->setDisableUserControl(); | - | ||||||||||||
102 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
103 | - | |||||||||||||
104 | if (d->animation
| 0-10 | ||||||||||||
105 | d->animation->setEnableUserControl(); never executed: d->animation->setEnableUserControl(); | 0 | ||||||||||||
106 | - | |||||||||||||
107 | d->animation = animation; | - | ||||||||||||
108 | reload(); | - | ||||||||||||
109 | animationChanged(); | - | ||||||||||||
110 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
111 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | - | |||||||||||||
119 | void QQuickAnimationController::reload() | - | ||||||||||||
120 | { | - | ||||||||||||
121 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
122 | if (!d->finalized
| 10 | ||||||||||||
123 | return; executed 10 times by 1 test: return; Executed by:
| 10 | ||||||||||||
124 | - | |||||||||||||
125 | if (!d->animation
| 0-10 | ||||||||||||
126 | d->animationInstance = nullptr; | - | ||||||||||||
127 | } never executed: else {end of block | 0 | ||||||||||||
128 | QQuickStateActions actions; | - | ||||||||||||
129 | QQmlProperties properties; | - | ||||||||||||
130 | QAbstractAnimationJob *oldInstance = d->animationInstance; | - | ||||||||||||
131 | d->animationInstance = d->animation->transition(actions, properties, QQuickAbstractAnimation::Forward); | - | ||||||||||||
132 | if (oldInstance
| 0-10 | ||||||||||||
133 | delete oldInstance; never executed: delete oldInstance; | 0 | ||||||||||||
134 | if (d->animationInstance
| 0-10 | ||||||||||||
135 | d->animationInstance->setLoopCount(1); | - | ||||||||||||
136 | d->animationInstance->setDisableUserControl(); | - | ||||||||||||
137 | d->animationInstance->start(); | - | ||||||||||||
138 | d->animationInstance->pause(); | - | ||||||||||||
139 | updateProgress(); | - | ||||||||||||
140 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
141 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
142 | } | - | ||||||||||||
143 | - | |||||||||||||
144 | void QQuickAnimationController::updateProgress() | - | ||||||||||||
145 | { | - | ||||||||||||
146 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
147 | if (!d->animationInstance
| 4-112 | ||||||||||||
148 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||
149 | - | |||||||||||||
150 | d->animationInstance->setDisableUserControl(); | - | ||||||||||||
151 | d->animationInstance->start(); | - | ||||||||||||
152 | QQmlAnimationTimer::instance()->unregisterAnimation(d->animationInstance); | - | ||||||||||||
153 | d->animationInstance->setCurrentTime(d->progress * d->animationInstance->duration()); | - | ||||||||||||
154 | } executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||
155 | - | |||||||||||||
156 | void QQuickAnimationController::componentFinalized() | - | ||||||||||||
157 | { | - | ||||||||||||
158 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
159 | d->finalized = true; | - | ||||||||||||
160 | reload(); | - | ||||||||||||
161 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
162 | void QQuickAnimationController::completeToBeginning() | - | ||||||||||||
163 | { | - | ||||||||||||
164 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
165 | if (!d->animationInstance
| 0 | ||||||||||||
166 | return; never executed: return; | 0 | ||||||||||||
167 | - | |||||||||||||
168 | if (d->progress == 0
| 0 | ||||||||||||
169 | return; never executed: return; | 0 | ||||||||||||
170 | - | |||||||||||||
171 | d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime); | - | ||||||||||||
172 | d->animationInstance->setDirection(QAbstractAnimationJob::Backward); | - | ||||||||||||
173 | - | |||||||||||||
174 | - | |||||||||||||
175 | d->animationInstance->setDisableUserControl(); | - | ||||||||||||
176 | d->animationInstance->setEnableUserControl(); | - | ||||||||||||
177 | d->animationInstance->start(); | - | ||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||
179 | void QQuickAnimationController::completeToEnd() | - | ||||||||||||
180 | { | - | ||||||||||||
181 | QQuickAnimationControllerPrivate * const d = d_func(); | - | ||||||||||||
182 | if (!d->animationInstance
| 0 | ||||||||||||
183 | return; never executed: return; | 0 | ||||||||||||
184 | - | |||||||||||||
185 | if (d->progress == 1
| 0 | ||||||||||||
186 | return; never executed: return; | 0 | ||||||||||||
187 | - | |||||||||||||
188 | d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime); | - | ||||||||||||
189 | d->animationInstance->setDirection(QAbstractAnimationJob::Forward); | - | ||||||||||||
190 | - | |||||||||||||
191 | - | |||||||||||||
192 | d->animationInstance->setDisableUserControl(); | - | ||||||||||||
193 | d->animationInstance->setEnableUserControl(); | - | ||||||||||||
194 | d->animationInstance->start(); | - | ||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||
196 | - | |||||||||||||
197 | - | |||||||||||||
198 | - | |||||||||||||
199 | - | |||||||||||||
200 | - | |||||||||||||
201 | - | |||||||||||||
Switch to Source code | Preprocessed file |