Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qtimeline.h" | - |
41 | | - |
42 | #include <private/qobject_p.h> | - |
43 | #include <QtCore/qcoreevent.h> | - |
44 | #include <QtCore/qmath.h> | - |
45 | #include <QtCore/qelapsedtimer.h> | - |
46 | | - |
47 | QT_BEGIN_NAMESPACE | - |
48 | | - |
49 | class QTimeLinePrivate : public QObjectPrivate | - |
50 | { | - |
51 | Q_DECLARE_PUBLIC(QTimeLine) | - |
52 | public: | - |
53 | inline QTimeLinePrivate() | - |
54 | : easingCurve(QEasingCurve::InOutSine), | - |
55 | startTime(0), duration(1000), startFrame(0), endFrame(0), | - |
56 | updateInterval(1000 / 25), | - |
57 | totalLoopCount(1), currentLoopCount(0), currentTime(0), timerId(0), | - |
58 | direction(QTimeLine::Forward), | - |
59 | state(QTimeLine::NotRunning) | - |
60 | { } | - |
61 | | - |
62 | QElapsedTimer timer; | - |
63 | QEasingCurve easingCurve; | - |
64 | | - |
65 | int startTime; | - |
66 | int duration; | - |
67 | int startFrame; | - |
68 | int endFrame; | - |
69 | int updateInterval; | - |
70 | int totalLoopCount; | - |
71 | int currentLoopCount; | - |
72 | | - |
73 | int currentTime; | - |
74 | int timerId; | - |
75 | | - |
76 | QTimeLine::Direction direction; | - |
77 | QTimeLine::State state; | - |
78 | inline void setState(QTimeLine::State newState) | - |
79 | { | - |
80 | Q_Q(QTimeLine); | - |
81 | if (newState != state) | - |
82 | emit q->stateChanged(state = newState, QTimeLine::QPrivateSignal()); | - |
83 | } | - |
84 | | - |
85 | void setCurrentTime(int msecs); | - |
86 | }; | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | void QTimeLinePrivate::setCurrentTime(int msecs) | - |
92 | { | - |
93 | Q_Q(QTimeLine); | - |
94 | | - |
95 | qreal lastValue = q->currentValue(); | - |
96 | int lastFrame = q->currentFrame(); | - |
97 | | - |
98 | | - |
99 | int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs;TRUE | evaluated 281 times by 1 test | FALSE | evaluated 1160 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
|
| 281-1160 |
100 | int loopCount = elapsed / duration; | - |
101 | | - |
102 | bool looping = (loopCount != currentLoopCount); | - |
103 | #ifdef QTIMELINE_DEBUG | - |
104 | qDebug() << "QTimeLinePrivate::setCurrentTime:" << msecs << duration << "with loopCount" << loopCount | - |
105 | << "currentLoopCount" << currentLoopCount | - |
106 | << "looping" << looping; | - |
107 | #endif | - |
108 | if (looping)TRUE | 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 |
109 | currentLoopCount = loopCount;executed 35 times by 2 tests: currentLoopCount = loopCount; Executed by:- tst_QGraphicsLayout
- tst_QTimeLine
| 35 |
110 | | - |
111 | | - |
112 | currentTime = elapsed % duration; | - |
113 | if (direction == QTimeLine::Backward)TRUE | evaluated 281 times by 1 test | FALSE | evaluated 1160 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
|
| 281-1160 |
114 | currentTime = duration - currentTime;executed 281 times by 1 test: currentTime = duration - currentTime; | 281 |
115 | | - |
116 | | - |
117 | bool finished = false; | - |
118 | if (totalLoopCount && currentLoopCount >= totalLoopCount) {TRUE | evaluated 1406 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
| FALSE | evaluated 35 times by 1 test |
TRUE | 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 |
119 | finished = true; | - |
120 | currentTime = (direction == QTimeLine::Backward) ? 0 : duration;TRUE | evaluated 1 time by 1 test | FALSE | evaluated 19 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
|
| 1-19 |
121 | currentLoopCount = totalLoopCount - 1; | - |
122 | }executed 20 times by 2 tests: end of block Executed by:- tst_QGraphicsLayout
- tst_QTimeLine
| 20 |
123 | | - |
124 | int currentFrame = q->frameForTime(currentTime); | - |
125 | #ifdef QTIMELINE_DEBUG | - |
126 | qDebug() << "QTimeLinePrivate::setCurrentTime: frameForTime" << currentTime << currentFrame; | - |
127 | #endif | - |
128 | 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 |
129 | emit 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 |
130 | if (lastFrame != currentFrame) {TRUE | evaluated 314 times by 1 test | FALSE | evaluated 1127 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
|
| 314-1127 |
131 | const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame);TRUE | evaluated 290 times by 1 test | FALSE | evaluated 24 times by 1 test |
| 24-290 |
132 | if (looping && !finished && transitionframe != currentFrame) {TRUE | evaluated 31 times by 1 test | FALSE | evaluated 283 times by 1 test |
TRUE | evaluated 15 times by 1 test | FALSE | evaluated 16 times by 1 test |
TRUE | evaluated 15 times by 1 test | FALSE | never evaluated |
| 0-283 |
133 | #ifdef QTIMELINE_DEBUG | - |
134 | qDebug() << ("QTimeLinePrivate::setCurrentTime: transitionframe";); | - |
135 | #endif | - |
136 | emit q->frameChanged(transitionframe, QTimeLine::QPrivateSignal()); | - |
137 | }executed 15 times by 1 test: end of block | 15 |
138 | #ifdef QTIMELINE_DEBUG | - |
139 | else { | - |
140 | QByteArray reason; | - |
141 | if (!looping) | - |
142 | reason += " not looping"; | - |
143 | if (finished) { | - |
144 | if (!reason.isEmpty()) | - |
145 | reason += " and"; | - |
146 | reason += " finished"; | - |
147 | } | - |
148 | if (transitionframe == currentFrame) { | - |
149 | if (!reason.isEmpty()) | - |
150 | reason += " and"; | - |
151 | reason += " transitionframe is equal to currentFrame: " + QByteArray::number(currentFrame); | - |
152 | } | - |
153 | qDebug("QTimeLinePrivate::setCurrentTime: not transitionframe because %s", reason.constData()); | - |
154 | } | - |
155 | #endif | - |
156 | emit q->frameChanged(currentFrame, QTimeLine::QPrivateSignal()); | - |
157 | }executed 314 times by 1 test: end of block | 314 |
158 | if (finished && state == QTimeLine::Running) {TRUE | evaluated 20 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
| FALSE | evaluated 1421 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
|
TRUE | evaluated 20 times by 2 testsEvaluated by:- tst_QGraphicsLayout
- tst_QTimeLine
| FALSE | never evaluated |
| 0-1421 |
159 | q->stop(); | - |
160 | emit q->finished(QTimeLine::QPrivateSignal()); | - |
161 | }executed 20 times by 2 tests: end of block Executed by:- tst_QGraphicsLayout
- tst_QTimeLine
| 20 |
162 | }executed 1441 times by 2 tests: end of block Executed by:- tst_QGraphicsLayout
- tst_QTimeLine
| 1441 |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | | - |
248 | | - |
249 | | - |
250 | | - |
251 | | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | QTimeLine::QTimeLine(int duration, QObject *parent) | - |
310 | : QObject(*new QTimeLinePrivate, parent) | - |
311 | { | - |
312 | setDuration(duration); | - |
313 | } | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | QTimeLine::~QTimeLine() | - |
319 | { | - |
320 | Q_D(QTimeLine); | - |
321 | | - |
322 | if (d->state == Running) | - |
323 | stop(); | - |
324 | } | - |
325 | | - |
326 | | - |
327 | | - |
328 | | - |
329 | | - |
330 | | - |
331 | QTimeLine::State QTimeLine::state() const | - |
332 | { | - |
333 | Q_D(const QTimeLine); | - |
334 | return d->state; | - |
335 | } | - |
336 | | - |
337 | | - |
338 | | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | int QTimeLine::loopCount() const | - |
346 | { | - |
347 | Q_D(const QTimeLine); | - |
348 | return d->totalLoopCount; | - |
349 | } | - |
350 | void QTimeLine::setLoopCount(int count) | - |
351 | { | - |
352 | Q_D(QTimeLine); | - |
353 | d->totalLoopCount = count; | - |
354 | } | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | QTimeLine::Direction QTimeLine::direction() const | - |
368 | { | - |
369 | Q_D(const QTimeLine); | - |
370 | return d->direction; | - |
371 | } | - |
372 | void QTimeLine::setDirection(Direction direction) | - |
373 | { | - |
374 | Q_D(QTimeLine); | - |
375 | d->direction = direction; | - |
376 | d->startTime = d->currentTime; | - |
377 | d->timer.start(); | - |
378 | } | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | | - |
386 | | - |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | int QTimeLine::duration() const | - |
393 | { | - |
394 | Q_D(const QTimeLine); | - |
395 | return d->duration; | - |
396 | } | - |
397 | void QTimeLine::setDuration(int duration) | - |
398 | { | - |
399 | Q_D(QTimeLine); | - |
400 | if (duration <= 0) { | - |
401 | qWarning("QTimeLine::setDuration: cannot set duration <= 0"); | - |
402 | return; | - |
403 | } | - |
404 | d->duration = duration; | - |
405 | } | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | int QTimeLine::startFrame() const | - |
414 | { | - |
415 | Q_D(const QTimeLine); | - |
416 | return d->startFrame; | - |
417 | } | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
424 | | - |
425 | void QTimeLine::setStartFrame(int frame) | - |
426 | { | - |
427 | Q_D(QTimeLine); | - |
428 | d->startFrame = frame; | - |
429 | } | - |
430 | | - |
431 | | - |
432 | | - |
433 | | - |
434 | | - |
435 | | - |
436 | | - |
437 | int QTimeLine::endFrame() const | - |
438 | { | - |
439 | Q_D(const QTimeLine); | - |
440 | return d->endFrame; | - |
441 | } | - |
442 | | - |
443 | | - |
444 | | - |
445 | | - |
446 | | - |
447 | | - |
448 | | - |
449 | void QTimeLine::setEndFrame(int frame) | - |
450 | { | - |
451 | Q_D(QTimeLine); | - |
452 | d->endFrame = frame; | - |
453 | } | - |
454 | | - |
455 | | - |
456 | | - |
457 | | - |
458 | | - |
459 | | - |
460 | | - |
461 | | - |
462 | | - |
463 | | - |
464 | | - |
465 | | - |
466 | void QTimeLine::setFrameRange(int startFrame, int endFrame) | - |
467 | { | - |
468 | Q_D(QTimeLine); | - |
469 | d->startFrame = startFrame; | - |
470 | d->endFrame = endFrame; | - |
471 | } | - |
472 | | - |
473 | | - |
474 | | - |
475 | | - |
476 | | - |
477 | | - |
478 | | - |
479 | | - |
480 | | - |
481 | | - |
482 | | - |
483 | | - |
484 | int QTimeLine::updateInterval() const | - |
485 | { | - |
486 | Q_D(const QTimeLine); | - |
487 | return d->updateInterval; | - |
488 | } | - |
489 | void QTimeLine::setUpdateInterval(int interval) | - |
490 | { | - |
491 | Q_D(QTimeLine); | - |
492 | d->updateInterval = interval; | - |
493 | } | - |
494 | | - |
495 | | - |
496 | | - |
497 | | - |
498 | | - |
499 | | - |
500 | | - |
501 | | - |
502 | | - |
503 | | - |
504 | | - |
505 | | - |
506 | | - |
507 | | - |
508 | QTimeLine::CurveShape QTimeLine::curveShape() const | - |
509 | { | - |
510 | Q_D(const QTimeLine); | - |
511 | switch (d->easingCurve.type()) { | - |
512 | default: | - |
513 | case QEasingCurve::InOutSine: | - |
514 | return EaseInOutCurve; | - |
515 | case QEasingCurve::InCurve: | - |
516 | return EaseInCurve; | - |
517 | case QEasingCurve::OutCurve: | - |
518 | return EaseOutCurve; | - |
519 | case QEasingCurve::Linear: | - |
520 | return LinearCurve; | - |
521 | case QEasingCurve::SineCurve: | - |
522 | return SineCurve; | - |
523 | case QEasingCurve::CosineCurve: | - |
524 | return CosineCurve; | - |
525 | } | - |
526 | return EaseInOutCurve; dead code: return EaseInOutCurve; | - |
527 | } | - |
528 | | - |
529 | void QTimeLine::setCurveShape(CurveShape shape) | - |
530 | { | - |
531 | switch (shape) { | - |
532 | default: | - |
533 | case EaseInOutCurve: | - |
534 | setEasingCurve(QEasingCurve(QEasingCurve::InOutSine)); | - |
535 | break; | - |
536 | case EaseInCurve: | - |
537 | setEasingCurve(QEasingCurve(QEasingCurve::InCurve)); | - |
538 | break; | - |
539 | case EaseOutCurve: | - |
540 | setEasingCurve(QEasingCurve(QEasingCurve::OutCurve)); | - |
541 | break; | - |
542 | case LinearCurve: | - |
543 | setEasingCurve(QEasingCurve(QEasingCurve::Linear)); | - |
544 | break; | - |
545 | case SineCurve: | - |
546 | setEasingCurve(QEasingCurve(QEasingCurve::SineCurve)); | - |
547 | break; | - |
548 | case CosineCurve: | - |
549 | setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve)); | - |
550 | break; | - |
551 | } | - |
552 | } | - |
553 | | - |
554 | | - |
555 | | - |
556 | | - |
557 | | - |
558 | | - |
559 | | - |
560 | | - |
561 | | - |
562 | | - |
563 | | - |
564 | | - |
565 | QEasingCurve QTimeLine::easingCurve() const | - |
566 | { | - |
567 | Q_D(const QTimeLine); | - |
568 | return d->easingCurve; | - |
569 | } | - |
570 | | - |
571 | void QTimeLine::setEasingCurve(const QEasingCurve& curve) | - |
572 | { | - |
573 | Q_D(QTimeLine); | - |
574 | d->easingCurve = curve; | - |
575 | } | - |
576 | | - |
577 | | - |
578 | | - |
579 | | - |
580 | | - |
581 | | - |
582 | | - |
583 | | - |
584 | | - |
585 | | - |
586 | | - |
587 | | - |
588 | int QTimeLine::currentTime() const | - |
589 | { | - |
590 | Q_D(const QTimeLine); | - |
591 | return d->currentTime; | - |
592 | } | - |
593 | void QTimeLine::setCurrentTime(int msec) | - |
594 | { | - |
595 | Q_D(QTimeLine); | - |
596 | d->startTime = 0; | - |
597 | d->currentLoopCount = 0; | - |
598 | d->timer.restart(); | - |
599 | d->setCurrentTime(msec); | - |
600 | } | - |
601 | | - |
602 | | - |
603 | | - |
604 | | - |
605 | | - |
606 | | - |
607 | int QTimeLine::currentFrame() const | - |
608 | { | - |
609 | Q_D(const QTimeLine); | - |
610 | return frameForTime(d->currentTime); | - |
611 | } | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | | - |
617 | | - |
618 | qreal QTimeLine::currentValue() const | - |
619 | { | - |
620 | Q_D(const QTimeLine); | - |
621 | return valueForTime(d->currentTime); | - |
622 | } | - |
623 | | - |
624 | | - |
625 | | - |
626 | | - |
627 | | - |
628 | | - |
629 | | - |
630 | | - |
631 | int QTimeLine::frameForTime(int msec) const | - |
632 | { | - |
633 | Q_D(const QTimeLine); | - |
634 | if (d->direction == Forward) | - |
635 | return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec)); | - |
636 | return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec)); | - |
637 | } | - |
638 | | - |
639 | | - |
640 | | - |
641 | | - |
642 | | - |
643 | | - |
644 | | - |
645 | | - |
646 | | - |
647 | | - |
648 | | - |
649 | qreal QTimeLine::valueForTime(int msec) const | - |
650 | { | - |
651 | Q_D(const QTimeLine); | - |
652 | msec = qMin(qMax(msec, 0), d->duration); | - |
653 | | - |
654 | qreal value = msec / qreal(d->duration); | - |
655 | return d->easingCurve.valueForProgress(value); | - |
656 | } | - |
657 | | - |
658 | | - |
659 | | - |
660 | | - |
661 | | - |
662 | | - |
663 | | - |
664 | | - |
665 | | - |
666 | | - |
667 | | - |
668 | | - |
669 | | - |
670 | | - |
671 | void QTimeLine::start() | - |
672 | { | - |
673 | Q_D(QTimeLine); | - |
674 | if (d->timerId) { | - |
675 | qWarning("QTimeLine::start: already running"); | - |
676 | return; | - |
677 | } | - |
678 | int curTime = 0; | - |
679 | if (d->direction == Backward) | - |
680 | curTime = d->duration; | - |
681 | d->timerId = startTimer(d->updateInterval); | - |
682 | d->startTime = curTime; | - |
683 | d->currentLoopCount = 0; | - |
684 | d->timer.start(); | - |
685 | d->setState(Running); | - |
686 | d->setCurrentTime(curTime); | - |
687 | } | - |
688 | | - |
689 | | - |
690 | | - |
691 | | - |
692 | | - |
693 | | - |
694 | | - |
695 | | - |
696 | | - |
697 | | - |
698 | | - |
699 | void QTimeLine::resume() | - |
700 | { | - |
701 | Q_D(QTimeLine); | - |
702 | if (d->timerId) { | - |
703 | qWarning("QTimeLine::resume: already running"); | - |
704 | return; | - |
705 | } | - |
706 | d->timerId = startTimer(d->updateInterval); | - |
707 | d->startTime = d->currentTime; | - |
708 | d->timer.start(); | - |
709 | d->setState(Running); | - |
710 | } | - |
711 | | - |
712 | | - |
713 | | - |
714 | | - |
715 | | - |
716 | | - |
717 | void QTimeLine::stop() | - |
718 | { | - |
719 | Q_D(QTimeLine); | - |
720 | if (d->timerId) | - |
721 | killTimer(d->timerId); | - |
722 | d->setState(NotRunning); | - |
723 | d->timerId = 0; | - |
724 | } | - |
725 | | - |
726 | | - |
727 | | - |
728 | | - |
729 | | - |
730 | | - |
731 | | - |
732 | | - |
733 | | - |
734 | void QTimeLine::setPaused(bool paused) | - |
735 | { | - |
736 | Q_D(QTimeLine); | - |
737 | if (d->state == NotRunning) { | - |
738 | qWarning("QTimeLine::setPaused: Not running"); | - |
739 | return; | - |
740 | } | - |
741 | if (paused && d->state != Paused) { | - |
742 | d->startTime = d->currentTime; | - |
743 | killTimer(d->timerId); | - |
744 | d->timerId = 0; | - |
745 | d->setState(Paused); | - |
746 | } else if (!paused && d->state == Paused) { | - |
747 | | - |
748 | d->timerId = startTimer(d->updateInterval); | - |
749 | d->startTime = d->currentTime; | - |
750 | d->timer.start(); | - |
751 | d->setState(Running); | - |
752 | } | - |
753 | } | - |
754 | | - |
755 | | - |
756 | | - |
757 | | - |
758 | | - |
759 | | - |
760 | | - |
761 | void QTimeLine::toggleDirection() | - |
762 | { | - |
763 | Q_D(QTimeLine); | - |
764 | setDirection(d->direction == Forward ? Backward : Forward); | - |
765 | } | - |
766 | | - |
767 | | - |
768 | | - |
769 | | - |
770 | void QTimeLine::timerEvent(QTimerEvent *event) | - |
771 | { | - |
772 | Q_D(QTimeLine); | - |
773 | if (event->timerId() != d->timerId) { | - |
774 | event->ignore(); | - |
775 | return; | - |
776 | } | - |
777 | event->accept(); | - |
778 | | - |
779 | if (d->direction == Forward) { | - |
780 | d->setCurrentTime(d->startTime + d->timer.elapsed()); | - |
781 | } else { | - |
782 | d->setCurrentTime(d->startTime - d->timer.elapsed()); | - |
783 | } | - |
784 | } | - |
785 | | - |
786 | QT_END_NAMESPACE | - |
| | |