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