Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | class QTimeLinePrivate : public QObjectPrivate | - |
6 | { | - |
7 | inline QTimeLine* q_func() { return static_cast<QTimeLine *>(q_ptr); } inline const QTimeLine* q_func() const { return static_cast<const QTimeLine *>(q_ptr); } friend class QTimeLine; | - |
8 | public: | - |
9 | inline QTimeLinePrivate() | - |
10 | : startTime(0), duration(1000), startFrame(0), endFrame(0), | - |
11 | updateInterval(1000 / 25), | - |
12 | totalLoopCount(1), currentLoopCount(0), currentTime(0), timerId(0), | - |
13 | direction(QTimeLine::Forward), easingCurve(QEasingCurve::InOutSine), | - |
14 | state(QTimeLine::NotRunning) | - |
15 | { } executed: } Execution Count:27 | 27 |
16 | | - |
17 | int startTime; | - |
18 | int duration; | - |
19 | int startFrame; | - |
20 | int endFrame; | - |
21 | int updateInterval; | - |
22 | int totalLoopCount; | - |
23 | int currentLoopCount; | - |
24 | | - |
25 | int currentTime; | - |
26 | int timerId; | - |
27 | QElapsedTimer timer; | - |
28 | | - |
29 | QTimeLine::Direction direction; | - |
30 | QEasingCurve easingCurve; | - |
31 | QTimeLine::State state; | - |
32 | inline void setState(QTimeLine::State newState) | - |
33 | { | - |
34 | QTimeLine * const q = q_func(); | - |
35 | if (newState != state) evaluated: newState != state yes Evaluation Count:80 | yes Evaluation Count:2 |
| 2-80 |
36 | q->stateChanged(state = newState, QTimeLine::QPrivateSignal()); executed: q->stateChanged(state = newState, QTimeLine::QPrivateSignal()); Execution Count:80 | 80 |
37 | } executed: } Execution Count:82 | 82 |
38 | | - |
39 | void setCurrentTime(int msecs); | - |
40 | }; | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | void QTimeLinePrivate::setCurrentTime(int msecs) | - |
46 | { | - |
47 | QTimeLine * const q = q_func(); | - |
48 | | - |
49 | qreal lastValue = q->currentValue(); | - |
50 | int lastFrame = q->currentFrame(); | - |
51 | | - |
52 | | - |
53 | int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs; evaluated: (direction == QTimeLine::Backward) yes Evaluation Count:325 | yes Evaluation Count:1114 |
| 325-1114 |
54 | int loopCount = elapsed / duration; | - |
55 | | - |
56 | bool looping = (loopCount != currentLoopCount); | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | if (looping) evaluated: looping yes Evaluation Count:38 | yes Evaluation Count:1401 |
| 38-1401 |
63 | currentLoopCount = loopCount; executed: currentLoopCount = loopCount; Execution Count:38 | 38 |
64 | | - |
65 | | - |
66 | currentTime = elapsed % duration; | - |
67 | if (direction == QTimeLine::Backward) evaluated: direction == QTimeLine::Backward yes Evaluation Count:325 | yes Evaluation Count:1114 |
| 325-1114 |
68 | currentTime = duration - currentTime; executed: currentTime = duration - currentTime; Execution Count:325 | 325 |
69 | | - |
70 | | - |
71 | bool finished = false; | - |
72 | if (totalLoopCount && currentLoopCount >= totalLoopCount) { evaluated: totalLoopCount yes Evaluation Count:1403 | yes Evaluation Count:36 |
evaluated: currentLoopCount >= totalLoopCount yes Evaluation Count:22 | yes Evaluation Count:1381 |
| 22-1403 |
73 | finished = true; | - |
74 | currentTime = (direction == QTimeLine::Backward) ? 0 : duration; evaluated: (direction == QTimeLine::Backward) yes Evaluation Count:3 | yes Evaluation Count:19 |
| 3-19 |
75 | currentLoopCount = totalLoopCount - 1; | - |
76 | } executed: } Execution Count:22 | 22 |
77 | | - |
78 | int currentFrame = q->frameForTime(currentTime); | - |
79 | | - |
80 | | - |
81 | | - |
82 | if (!qFuzzyCompare(lastValue, q->currentValue())) evaluated: !qFuzzyCompare(lastValue, q->currentValue()) yes Evaluation Count:1411 | yes Evaluation Count:28 |
| 28-1411 |
83 | q->valueChanged(q->currentValue(), QTimeLine::QPrivateSignal()); executed: q->valueChanged(q->currentValue(), QTimeLine::QPrivateSignal()); Execution Count:1411 | 1411 |
84 | if (lastFrame != currentFrame) { evaluated: lastFrame != currentFrame yes Evaluation Count:203 | yes Evaluation Count:1236 |
| 203-1236 |
85 | const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame); evaluated: direction == QTimeLine::Forward yes Evaluation Count:177 | yes Evaluation Count:26 |
| 26-177 |
86 | if (looping && !finished && transitionframe != currentFrame) { evaluated: looping yes Evaluation Count:33 | yes Evaluation Count:170 |
evaluated: !finished yes Evaluation Count:16 | yes Evaluation Count:17 |
partially evaluated: transitionframe != currentFrame yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-170 |
87 | | - |
88 | | - |
89 | | - |
90 | q->frameChanged(transitionframe, QTimeLine::QPrivateSignal()); | - |
91 | } executed: } Execution Count:16 | 16 |
92 | q->frameChanged(currentFrame, QTimeLine::QPrivateSignal()); | - |
93 | } executed: } Execution Count:203 | 203 |
94 | if (finished && state == QTimeLine::Running) { evaluated: finished yes Evaluation Count:22 | yes Evaluation Count:1417 |
partially evaluated: state == QTimeLine::Running yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-1417 |
95 | q->stop(); | - |
96 | q->finished(QTimeLine::QPrivateSignal()); | - |
97 | } executed: } Execution Count:22 | 22 |
98 | } executed: } Execution Count:1439 | 1439 |
99 | QTimeLine::QTimeLine(int duration, QObject *parent) | - |
100 | : QObject(*new QTimeLinePrivate, parent) | - |
101 | { | - |
102 | setDuration(duration); | - |
103 | } executed: } Execution Count:27 | 27 |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | QTimeLine::~QTimeLine() | - |
109 | { | - |
110 | QTimeLinePrivate * const d = d_func(); | - |
111 | | - |
112 | if (d->state == Running) evaluated: d->state == Running yes Evaluation Count:6 | yes Evaluation Count:21 |
| 6-21 |
113 | stop(); executed: stop(); Execution Count:6 | 6 |
114 | } executed: } Execution Count:27 | 27 |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
121 | QTimeLine::State QTimeLine::state() const | - |
122 | { | - |
123 | const QTimeLinePrivate * const d = d_func(); | - |
124 | return d->state; executed: return d->state; Execution Count:38 | 38 |
125 | } | - |
126 | int QTimeLine::loopCount() const | - |
127 | { | - |
128 | const QTimeLinePrivate * const d = d_func(); | - |
129 | return d->totalLoopCount; executed: return d->totalLoopCount; Execution Count:4 | 4 |
130 | } | - |
131 | void QTimeLine::setLoopCount(int count) | - |
132 | { | - |
133 | QTimeLinePrivate * const d = d_func(); | - |
134 | d->totalLoopCount = count; | - |
135 | } executed: } Execution Count:2 | 2 |
136 | QTimeLine::Direction QTimeLine::direction() const | - |
137 | { | - |
138 | const QTimeLinePrivate * const d = d_func(); | - |
139 | return d->direction; executed: return d->direction; Execution Count:6 | 6 |
140 | } | - |
141 | void QTimeLine::setDirection(Direction direction) | - |
142 | { | - |
143 | QTimeLinePrivate * const d = d_func(); | - |
144 | d->direction = direction; | - |
145 | d->startTime = d->currentTime; | - |
146 | d->timer.start(); | - |
147 | } executed: } Execution Count:38 | 38 |
148 | int QTimeLine::duration() const | - |
149 | { | - |
150 | const QTimeLinePrivate * const d = d_func(); | - |
151 | return d->duration; executed: return d->duration; Execution Count:42 | 42 |
152 | } | - |
153 | void QTimeLine::setDuration(int duration) | - |
154 | { | - |
155 | QTimeLinePrivate * const d = d_func(); | - |
156 | if (duration <= 0) { partially evaluated: duration <= 0 no Evaluation Count:0 | yes Evaluation Count:31 |
| 0-31 |
157 | QMessageLogger("tools/qtimeline.cpp", 401, __PRETTY_FUNCTION__).warning("QTimeLine::setDuration: cannot set duration <= 0"); | - |
158 | return; | 0 |
159 | } | - |
160 | d->duration = duration; | - |
161 | } executed: } Execution Count:31 | 31 |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | int QTimeLine::startFrame() const | - |
170 | { | - |
171 | const QTimeLinePrivate * const d = d_func(); | - |
172 | return d->startFrame; executed: return d->startFrame; Execution Count:7 | 7 |
173 | } | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | void QTimeLine::setStartFrame(int frame) | - |
182 | { | - |
183 | QTimeLinePrivate * const d = d_func(); | - |
184 | d->startFrame = frame; | - |
185 | } executed: } Execution Count:2 | 2 |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | int QTimeLine::endFrame() const | - |
194 | { | - |
195 | const QTimeLinePrivate * const d = d_func(); | - |
196 | return d->endFrame; executed: return d->endFrame; Execution Count:7 | 7 |
197 | } | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | void QTimeLine::setEndFrame(int frame) | - |
206 | { | - |
207 | QTimeLinePrivate * const d = d_func(); | - |
208 | d->endFrame = frame; | - |
209 | } executed: } Execution Count:2 | 2 |
210 | void QTimeLine::setFrameRange(int startFrame, int endFrame) | - |
211 | { | - |
212 | QTimeLinePrivate * const d = d_func(); | - |
213 | d->startFrame = startFrame; | - |
214 | d->endFrame = endFrame; | - |
215 | } executed: } Execution Count:22 | 22 |
216 | int QTimeLine::updateInterval() const | - |
217 | { | - |
218 | const QTimeLinePrivate * const d = d_func(); | - |
219 | return d->updateInterval; executed: return d->updateInterval; Execution Count:2 | 2 |
220 | } | - |
221 | void QTimeLine::setUpdateInterval(int interval) | - |
222 | { | - |
223 | QTimeLinePrivate * const d = d_func(); | - |
224 | d->updateInterval = interval; | - |
225 | } executed: } Execution Count:5 | 5 |
226 | QTimeLine::CurveShape QTimeLine::curveShape() const | - |
227 | { | - |
228 | const QTimeLinePrivate * const d = d_func(); | - |
229 | switch (d->easingCurve.type()) { | - |
230 | default: | - |
231 | case QEasingCurve::InOutSine: | - |
232 | return EaseInOutCurve; executed: return EaseInOutCurve; Execution Count:1 | 1 |
233 | case QEasingCurve::InCurve: | - |
234 | return EaseInCurve; never executed: return EaseInCurve; | 0 |
235 | case QEasingCurve::OutCurve: | - |
236 | return EaseOutCurve; never executed: return EaseOutCurve; | 0 |
237 | case QEasingCurve::Linear: | - |
238 | return LinearCurve; executed: return LinearCurve; Execution Count:1 | 1 |
239 | case QEasingCurve::SineCurve: | - |
240 | return SineCurve; never executed: return SineCurve; | 0 |
241 | case QEasingCurve::CosineCurve: | - |
242 | return CosineCurve; never executed: return CosineCurve; | 0 |
243 | } | - |
244 | return EaseInOutCurve; never executed: return EaseInOutCurve; | 0 |
245 | } | - |
246 | | - |
247 | void QTimeLine::setCurveShape(CurveShape shape) | - |
248 | { | - |
249 | switch (shape) { | - |
250 | default: | - |
251 | case EaseInOutCurve: | - |
252 | setEasingCurve(QEasingCurve(QEasingCurve::InOutSine)); | - |
253 | break; executed: break; Execution Count:1 | 1 |
254 | case EaseInCurve: | - |
255 | setEasingCurve(QEasingCurve(QEasingCurve::InCurve)); | - |
256 | break; | 0 |
257 | case EaseOutCurve: | - |
258 | setEasingCurve(QEasingCurve(QEasingCurve::OutCurve)); | - |
259 | break; | 0 |
260 | case LinearCurve: | - |
261 | setEasingCurve(QEasingCurve(QEasingCurve::Linear)); | - |
262 | break; executed: break; Execution Count:6 | 6 |
263 | case SineCurve: | - |
264 | setEasingCurve(QEasingCurve(QEasingCurve::SineCurve)); | - |
265 | break; executed: break; Execution Count:2 | 2 |
266 | case CosineCurve: | - |
267 | setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve)); | - |
268 | break; executed: break; Execution Count:1 | 1 |
269 | } | - |
270 | } executed: } Execution Count:10 | 10 |
271 | QEasingCurve QTimeLine::easingCurve() const | - |
272 | { | - |
273 | const QTimeLinePrivate * const d = d_func(); | - |
274 | return d->easingCurve; never executed: return d->easingCurve; | 0 |
275 | } | - |
276 | | - |
277 | void QTimeLine::setEasingCurve(const QEasingCurve& curve) | - |
278 | { | - |
279 | QTimeLinePrivate * const d = d_func(); | - |
280 | d->easingCurve = curve; | - |
281 | } executed: } Execution Count:10 | 10 |
282 | int QTimeLine::currentTime() const | - |
283 | { | - |
284 | const QTimeLinePrivate * const d = d_func(); | - |
285 | return d->currentTime; executed: return d->currentTime; Execution Count:22 | 22 |
286 | } | - |
287 | void QTimeLine::setCurrentTime(int msec) | - |
288 | { | - |
289 | QTimeLinePrivate * const d = d_func(); | - |
290 | d->startTime = 0; | - |
291 | d->currentLoopCount = 0; | - |
292 | d->timer.restart(); | - |
293 | d->setCurrentTime(msec); | - |
294 | } executed: } Execution Count:11 | 11 |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | int QTimeLine::currentFrame() const | - |
302 | { | - |
303 | const QTimeLinePrivate * const d = d_func(); | - |
304 | return frameForTime(d->currentTime); executed: return frameForTime(d->currentTime); Execution Count:1470 | 1470 |
305 | } | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | | - |
312 | qreal QTimeLine::currentValue() const | - |
313 | { | - |
314 | const QTimeLinePrivate * const d = d_func(); | - |
315 | return valueForTime(d->currentTime); executed: return valueForTime(d->currentTime); Execution Count:4297 | 4297 |
316 | } | - |
317 | int QTimeLine::frameForTime(int msec) const | - |
318 | { | - |
319 | const QTimeLinePrivate * const d = d_func(); | - |
320 | if (d->direction == Forward) evaluated: d->direction == Forward yes Evaluation Count:2249 | yes Evaluation Count:660 |
| 660-2249 |
321 | return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec)); executed: return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec)); Execution Count:2249 | 2249 |
322 | return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec)); executed: return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec)); Execution Count:660 | 660 |
323 | } | - |
324 | qreal QTimeLine::valueForTime(int msec) const | - |
325 | { | - |
326 | const QTimeLinePrivate * const d = d_func(); | - |
327 | msec = qMin(qMax(msec, 0), d->duration); | - |
328 | | - |
329 | qreal value = msec / qreal(d->duration); | - |
330 | return d->easingCurve.valueForProgress(value); executed: return d->easingCurve.valueForProgress(value); Execution Count:7219 | 7219 |
331 | } | - |
332 | void QTimeLine::start() | - |
333 | { | - |
334 | QTimeLinePrivate * const d = d_func(); | - |
335 | if (d->timerId) { partially evaluated: d->timerId no Evaluation Count:0 | yes Evaluation Count:37 |
| 0-37 |
336 | QMessageLogger("tools/qtimeline.cpp", 675, __PRETTY_FUNCTION__).warning("QTimeLine::start: already running"); | - |
337 | return; | 0 |
338 | } | - |
339 | int curTime = 0; | - |
340 | if (d->direction == Backward) evaluated: d->direction == Backward yes Evaluation Count:5 | yes Evaluation Count:32 |
| 5-32 |
341 | curTime = d->duration; executed: curTime = d->duration; Execution Count:5 | 5 |
342 | d->timerId = startTimer(d->updateInterval); | - |
343 | d->startTime = curTime; | - |
344 | d->currentLoopCount = 0; | - |
345 | d->timer.start(); | - |
346 | d->setState(Running); | - |
347 | d->setCurrentTime(curTime); | - |
348 | } executed: } Execution Count:37 | 37 |
349 | void QTimeLine::resume() | - |
350 | { | - |
351 | QTimeLinePrivate * const d = d_func(); | - |
352 | if (d->timerId) { partially evaluated: d->timerId no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
353 | QMessageLogger("tools/qtimeline.cpp", 703, __PRETTY_FUNCTION__).warning("QTimeLine::resume: already running"); | - |
354 | return; | 0 |
355 | } | - |
356 | d->timerId = startTimer(d->updateInterval); | - |
357 | d->startTime = d->currentTime; | - |
358 | d->timer.start(); | - |
359 | d->setState(Running); | - |
360 | } executed: } Execution Count:3 | 3 |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | void QTimeLine::stop() | - |
368 | { | - |
369 | QTimeLinePrivate * const d = d_func(); | - |
370 | if (d->timerId) evaluated: d->timerId yes Evaluation Count:40 | yes Evaluation Count:2 |
| 2-40 |
371 | killTimer(d->timerId); executed: killTimer(d->timerId); Execution Count:40 | 40 |
372 | d->setState(NotRunning); | - |
373 | d->timerId = 0; | - |
374 | } executed: } Execution Count:42 | 42 |
375 | void QTimeLine::setPaused(bool paused) | - |
376 | { | - |
377 | QTimeLinePrivate * const d = d_func(); | - |
378 | if (d->state == NotRunning) { never evaluated: d->state == NotRunning | 0 |
379 | QMessageLogger("tools/qtimeline.cpp", 738, __PRETTY_FUNCTION__).warning("QTimeLine::setPaused: Not running"); | - |
380 | return; | 0 |
381 | } | - |
382 | if (paused && d->state != Paused) { never evaluated: d->state != Paused | 0 |
383 | d->startTime = d->currentTime; | - |
384 | killTimer(d->timerId); | - |
385 | d->timerId = 0; | - |
386 | d->setState(Paused); | - |
387 | } else if (!paused && d->state == Paused) { never evaluated: d->state == Paused | 0 |
388 | d->timerId = startTimer(d->updateInterval); | - |
389 | d->setState(Running); | - |
390 | } | 0 |
391 | } | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | void QTimeLine::toggleDirection() | - |
400 | { | - |
401 | QTimeLinePrivate * const d = d_func(); | - |
402 | setDirection(d->direction == Forward ? Backward : Forward); | - |
403 | } executed: } Execution Count:2 | 2 |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | void QTimeLine::timerEvent(QTimerEvent *event) | - |
409 | { | - |
410 | QTimeLinePrivate * const d = d_func(); | - |
411 | if (event->timerId() != d->timerId) { partially evaluated: event->timerId() != d->timerId no Evaluation Count:0 | yes Evaluation Count:1391 |
| 0-1391 |
412 | event->ignore(); | - |
413 | return; | 0 |
414 | } | - |
415 | event->accept(); | - |
416 | | - |
417 | if (d->direction == Forward) { evaluated: d->direction == Forward yes Evaluation Count:1075 | yes Evaluation Count:316 |
| 316-1075 |
418 | d->setCurrentTime(d->startTime + d->timer.elapsed()); | - |
419 | } else { executed: } Execution Count:1075 | 1075 |
420 | d->setCurrentTime(d->startTime - d->timer.elapsed()); | - |
421 | } executed: } Execution Count:316 | 316 |
422 | } | - |
423 | | - |
424 | | - |
425 | | - |
| | |