OpenCoverage

qtimeline.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qtimeline.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
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-
47QT_BEGIN_NAMESPACE-
48-
49class QTimeLinePrivate : public QObjectPrivate-
50{-
51 Q_DECLARE_PUBLIC(QTimeLine)-
52public:-
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 { }
executed 28 times by 3 tests: end of block
Executed by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
28
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)
newState != stateDescription
TRUEevaluated 84 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEnever evaluated
0-84
82 emit q->stateChanged(state = newState, QTimeLine::QPrivateSignal());
executed 84 times by 2 tests: q->stateChanged(state = newState, QTimeLine::QPrivateSignal());
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
84
83 }
executed 84 times by 2 tests: end of block
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
84
84-
85 void setCurrentTime(int msecs);-
86};-
87-
88/*!-
89 \internal-
90*/-
91void QTimeLinePrivate::setCurrentTime(int msecs)-
92{-
93 Q_Q(QTimeLine);-
94-
95 qreal lastValue = q->currentValue();-
96 int lastFrame = q->currentFrame();-
97-
98 // Determine if we are looping.-
99 int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs;
(direction == ...ine::Backward)Description
TRUEevaluated 281 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 1160 times by 2 tests
Evaluated 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)
loopingDescription
TRUEevaluated 35 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 1406 times by 2 tests
Evaluated 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 // Normalize msecs to be between 0 and duration, inclusive.-
112 currentTime = elapsed % duration;-
113 if (direction == QTimeLine::Backward)
direction == Q...Line::BackwardDescription
TRUEevaluated 281 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 1160 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
281-1160
114 currentTime = duration - currentTime;
executed 281 times by 1 test: currentTime = duration - currentTime;
Executed by:
  • tst_QTimeLine
281
115-
116 // Check if we have reached the end of loopcount.-
117 bool finished = false;-
118 if (totalLoopCount && currentLoopCount >= totalLoopCount) {
totalLoopCountDescription
TRUEevaluated 1406 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 35 times by 1 test
Evaluated by:
  • tst_QTimeLine
currentLoopCou...totalLoopCountDescription
TRUEevaluated 20 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 1386 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
20-1406
119 finished = true;-
120 currentTime = (direction == QTimeLine::Backward) ? 0 : duration;
(direction == ...ine::Backward)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 19 times by 2 tests
Evaluated 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()))
!qFuzzyCompare...urrentValue())Description
TRUEevaluated 1412 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 29 times by 2 tests
Evaluated 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) {
lastFrame != currentFrameDescription
TRUEevaluated 314 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 1127 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
314-1127
131 const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame);
direction == Q...eLine::ForwardDescription
TRUEevaluated 290 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 24 times by 1 test
Evaluated by:
  • tst_QTimeLine
24-290
132 if (looping && !finished && transitionframe != currentFrame) {
loopingDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 283 times by 1 test
Evaluated by:
  • tst_QTimeLine
!finishedDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QTimeLine
transitionfram...= currentFrameDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEnever 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
Executed by:
  • tst_QTimeLine
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
Executed by:
  • tst_QTimeLine
314
158 if (finished && state == QTimeLine::Running) {
finishedDescription
TRUEevaluated 20 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 1421 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
state == QTimeLine::RunningDescription
TRUEevaluated 20 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEnever 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 \class QTimeLine-
166 \inmodule QtCore-
167 \brief The QTimeLine class provides a timeline for controlling animations.-
168 \since 4.2-
169 \ingroup animation-
170-
171 It's most commonly used to animate a GUI control by calling a slot-
172 periodically. You can construct a timeline by passing its duration in-
173 milliseconds to QTimeLine's constructor. The timeline's duration describes-
174 for how long the animation will run. Then you set a suitable frame range-
175 by calling setFrameRange(). Finally connect the frameChanged() signal to a-
176 suitable slot in the widget you wish to animate (for example, \l {QProgressBar::}{setValue()}-
177 in QProgressBar). When you proceed to calling start(), QTimeLine will enter-
178 Running state, and start emitting frameChanged() at regular intervals,-
179 causing your widget's connected property's value to grow from the lower-
180 end to the upper and of your frame range, at a steady rate. You can-
181 specify the update interval by calling setUpdateInterval(). When done,-
182 QTimeLine enters NotRunning state, and emits finished().-
183-
184 Example:-
185-
186 \snippet code/src_corelib_tools_qtimeline.cpp 0-
187-
188 By default the timeline runs once, from the beginning and towards the end,-
189 upon which you must call start() again to restart from the beginning. To-
190 make the timeline loop, you can call setLoopCount(), passing the number of-
191 times the timeline should run before finishing. The direction can also be-
192 changed, causing the timeline to run backward, by calling-
193 setDirection(). You can also pause and unpause the timeline while it's-
194 running by calling setPaused(). For interactive control, the-
195 setCurrentTime() function is provided, which sets the time position of the-
196 time line directly. Although most useful in NotRunning state, (e.g.,-
197 connected to a valueChanged() signal in a QSlider,) this function can be-
198 called at any time.-
199-
200 The frame interface is useful for standard widgets, but QTimeLine can be-
201 used to control any type of animation. The heart of QTimeLine lies in the-
202 valueForTime() function, which generates a \e value between 0 and 1 for a-
203 given time. This value is typically used to describe the steps of an-
204 animation, where 0 is the first step of an animation, and 1 is the last-
205 step. When running, QTimeLine generates values between 0 and 1 by calling-
206 valueForTime() and emitting valueChanged(). By default, valueForTime()-
207 applies an interpolation algorithm to generate these value. You can choose-
208 from a set of predefined timeline algorithms by calling-
209 setCurveShape().-
210-
211 Note that by default, QTimeLine uses the EaseInOut curve shape,-
212 which provides a value that grows slowly, then grows steadily, and-
213 finally grows slowly. For a custom timeline, you can reimplement-
214 valueForTime(), in which case QTimeLine's curveShape property is ignored.-
215-
216 \sa QProgressBar, QProgressDialog-
217*/-
218-
219/*!-
220 \enum QTimeLine::State-
221-
222 This enum describes the state of the timeline.-
223-
224 \value NotRunning The timeline is not running. This is the initial state-
225 of QTimeLine, and the state QTimeLine reenters when finished. The current-
226 time, frame and value remain unchanged until either setCurrentTime() is-
227 called, or the timeline is started by calling start().-
228-
229 \value Paused The timeline is paused (i.e., temporarily-
230 suspended). Calling setPaused(false) will resume timeline activity.-
231-
232 \value Running The timeline is running. While control is in the event-
233 loop, QTimeLine will update its current time at regular intervals,-
234 emitting valueChanged() and frameChanged() when appropriate.-
235-
236 \sa state(), stateChanged()-
237*/-
238-
239/*!-
240 \enum QTimeLine::Direction-
241-
242 This enum describes the direction of the timeline when in \l Running state.-
243-
244 \value Forward The current time of the timeline increases with time (i.e.,-
245 moves from 0 and towards the end / duration).-
246-
247 \value Backward The current time of the timeline decreases with time (i.e.,-
248 moves from the end / duration and towards 0).-
249-
250 \sa setDirection()-
251*/-
252-
253/*!-
254 \enum QTimeLine::CurveShape-
255-
256 This enum describes the default shape of QTimeLine's value curve. The-
257 default, shape is EaseInOutCurve. The curve defines the relation-
258 between the value and the timeline.-
259-
260 \value EaseInCurve The value starts growing slowly, then increases in speed.-
261 \value EaseOutCurve The value starts growing steadily, then ends slowly.-
262 \value EaseInOutCurve The value starts growing slowly, then runs steadily, then grows slowly again.-
263 \value LinearCurve The value grows linearly (e.g., if the duration is 1000 ms,-
264 the value at time 500 ms is 0.5).-
265 \value SineCurve The value grows sinusoidally.-
266 \value CosineCurve The value grows cosinusoidally.-
267-
268 \sa setCurveShape()-
269*/-
270-
271/*!-
272 \fn QTimeLine::valueChanged(qreal value)-
273-
274 QTimeLine emits this signal at regular intervals when in \l Running state,-
275 but only if the current value changes. \a value is the current value. \a value is-
276 a number between 0.0 and 1.0-
277-
278 \sa QTimeLine::setDuration(), QTimeLine::valueForTime(), QTimeLine::updateInterval-
279*/-
280-
281/*!-
282 \fn QTimeLine::frameChanged(int frame)-
283-
284 QTimeLine emits this signal at regular intervals when in \l Running state,-
285 but only if the current frame changes. \a frame is the current frame number.-
286-
287 \sa QTimeLine::setFrameRange(), QTimeLine::updateInterval-
288*/-
289-
290/*!-
291 \fn QTimeLine::stateChanged(QTimeLine::State newState)-
292-
293 This signal is emitted whenever QTimeLine's state changes. The new state-
294 is \a newState.-
295*/-
296-
297/*!-
298 \fn QTimeLine::finished()-
299-
300 This signal is emitted when QTimeLine finishes (i.e., reaches the end of-
301 its time line), and does not loop.-
302*/-
303-
304/*!-
305 Constructs a timeline with a duration of \a duration milliseconds. \a-
306 parent is passed to QObject's constructor. The default duration is 1000-
307 milliseconds.-
308 */-
309QTimeLine::QTimeLine(int duration, QObject *parent)-
310 : QObject(*new QTimeLinePrivate, parent)-
311{-
312 setDuration(duration);-
313}
executed 28 times by 3 tests: end of block
Executed by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
28
314-
315/*!-
316 Destroys the timeline.-
317 */-
318QTimeLine::~QTimeLine()-
319{-
320 Q_D(QTimeLine);-
321-
322 if (d->state == Running)
d->state == RunningDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
6-22
323 stop();
executed 6 times by 1 test: stop();
Executed by:
  • tst_QTimeLine
6
324}
executed 28 times by 3 tests: end of block
Executed by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
28
325-
326/*!-
327 Returns the state of the timeline.-
328-
329 \sa start(), setPaused(), stop()-
330*/-
331QTimeLine::State QTimeLine::state() const-
332{-
333 Q_D(const QTimeLine);-
334 return d->state;
executed 250 times by 1 test: return d->state;
Executed by:
  • tst_QTimeLine
250
335}-
336-
337/*!-
338 \property QTimeLine::loopCount-
339 \brief the number of times the timeline should loop before it's finished.-
340-
341 A loop count of of 0 means that the timeline will loop forever.-
342-
343 By default, this property contains a value of 1.-
344*/-
345int QTimeLine::loopCount() const-
346{-
347 Q_D(const QTimeLine);-
348 return d->totalLoopCount;
executed 4 times by 1 test: return d->totalLoopCount;
Executed by:
  • tst_QTimeLine
4
349}-
350void QTimeLine::setLoopCount(int count)-
351{-
352 Q_D(QTimeLine);-
353 d->totalLoopCount = count;-
354}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
2
355-
356/*!-
357 \property QTimeLine::direction-
358 \brief the direction of the timeline when QTimeLine is in \l Running-
359 state.-
360-
361 This direction indicates whether the time moves from 0 towards the-
362 timeline duration, or from the value of the duration and towards 0 after-
363 start() has been called.-
364-
365 By default, this property is set to \l Forward.-
366*/-
367QTimeLine::Direction QTimeLine::direction() const-
368{-
369 Q_D(const QTimeLine);-
370 return d->direction;
executed 6 times by 1 test: return d->direction;
Executed by:
  • tst_QTimeLine
6
371}-
372void QTimeLine::setDirection(Direction direction)-
373{-
374 Q_D(QTimeLine);-
375 d->direction = direction;-
376 d->startTime = d->currentTime;-
377 d->timer.start();-
378}
executed 38 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
38
379-
380/*!-
381 \property QTimeLine::duration-
382 \brief the total duration of the timeline in milliseconds.-
383-
384 By default, this value is 1000 (i.e., 1 second), but you can change this-
385 by either passing a duration to QTimeLine's constructor, or by calling-
386 setDuration(). The duration must be larger than 0.-
387-
388 \note Changing the duration does not cause the current time to be reset-
389 to zero or the new duration. You also need to call setCurrentTime() with-
390 the desired value.-
391*/-
392int QTimeLine::duration() const-
393{-
394 Q_D(const QTimeLine);-
395 return d->duration;
executed 83 times by 1 test: return d->duration;
Executed by:
  • tst_QTimeLine
83
396}-
397void QTimeLine::setDuration(int duration)-
398{-
399 Q_D(QTimeLine);-
400 if (duration <= 0) {
duration <= 0Description
TRUEnever evaluated
FALSEevaluated 32 times by 3 tests
Evaluated by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
0-32
401 qWarning("QTimeLine::setDuration: cannot set duration <= 0");-
402 return;
never executed: return;
0
403 }-
404 d->duration = duration;-
405}
executed 32 times by 3 tests: end of block
Executed by:
  • tst_QGraphicsItemAnimation
  • tst_QGraphicsLayout
  • tst_QTimeLine
32
406-
407/*!-
408 Returns the start frame, which is the frame corresponding to the start of-
409 the timeline (i.e., the frame for which the current value is 0).-
410-
411 \sa setStartFrame(), setFrameRange()-
412*/-
413int QTimeLine::startFrame() const-
414{-
415 Q_D(const QTimeLine);-
416 return d->startFrame;
executed 7 times by 1 test: return d->startFrame;
Executed by:
  • tst_QTimeLine
7
417}-
418-
419/*!-
420 Sets the start frame, which is the frame corresponding to the start of the-
421 timeline (i.e., the frame for which the current value is 0), to \a frame.-
422-
423 \sa startFrame(), endFrame(), setFrameRange()-
424*/-
425void QTimeLine::setStartFrame(int frame)-
426{-
427 Q_D(QTimeLine);-
428 d->startFrame = frame;-
429}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
2
430-
431/*!-
432 Returns the end frame, which is the frame corresponding to the end of the-
433 timeline (i.e., the frame for which the current value is 1).-
434-
435 \sa setEndFrame(), setFrameRange()-
436*/-
437int QTimeLine::endFrame() const-
438{-
439 Q_D(const QTimeLine);-
440 return d->endFrame;
executed 24 times by 1 test: return d->endFrame;
Executed by:
  • tst_QTimeLine
24
441}-
442-
443/*!-
444 Sets the end frame, which is the frame corresponding to the end of the-
445 timeline (i.e., the frame for which the current value is 1), to \a frame.-
446-
447 \sa endFrame(), startFrame(), setFrameRange()-
448*/-
449void QTimeLine::setEndFrame(int frame)-
450{-
451 Q_D(QTimeLine);-
452 d->endFrame = frame;-
453}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
2
454-
455/*!-
456 Sets the timeline's frame counter to start at \a startFrame, and end and-
457 \a endFrame. For each time value, QTimeLine will find the corresponding-
458 frame when you call currentFrame() or frameForTime() by interpolating,-
459 using the return value of valueForTime().-
460-
461 When in Running state, QTimeLine also emits the frameChanged() signal when-
462 the frame changes.-
463-
464 \sa startFrame(), endFrame(), start(), currentFrame()-
465*/-
466void QTimeLine::setFrameRange(int startFrame, int endFrame)-
467{-
468 Q_D(QTimeLine);-
469 d->startFrame = startFrame;-
470 d->endFrame = endFrame;-
471}
executed 22 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
22
472-
473/*!-
474 \property QTimeLine::updateInterval-
475 \brief the time in milliseconds between each time QTimeLine updates its-
476 current time.-
477-
478 When updating the current time, QTimeLine will emit valueChanged() if the-
479 current value changed, and frameChanged() if the frame changed.-
480-
481 By default, the interval is 40 ms, which corresponds to a rate of 25-
482 updates per second.-
483*/-
484int QTimeLine::updateInterval() const-
485{-
486 Q_D(const QTimeLine);-
487 return d->updateInterval;
executed 2 times by 1 test: return d->updateInterval;
Executed by:
  • tst_QTimeLine
2
488}-
489void QTimeLine::setUpdateInterval(int interval)-
490{-
491 Q_D(QTimeLine);-
492 d->updateInterval = interval;-
493}
executed 5 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
5
494-
495/*!-
496 \property QTimeLine::curveShape-
497 \brief the shape of the timeline curve.-
498-
499 The curve shape describes the relation between the time and value for the-
500 base implementation of valueForTime().-
501-
502 If you have reimplemented valueForTime(), this value is ignored.-
503-
504 By default, this property is set to \l EaseInOutCurve.-
505-
506 \sa valueForTime()-
507*/-
508QTimeLine::CurveShape QTimeLine::curveShape() const-
509{-
510 Q_D(const QTimeLine);-
511 switch (d->easingCurve.type()) {-
512 default:
never executed: default:
0
513 case QEasingCurve::InOutSine:
executed 1 time by 1 test: case QEasingCurve::InOutSine:
Executed by:
  • tst_QTimeLine
1
514 return EaseInOutCurve;
executed 1 time by 1 test: return EaseInOutCurve;
Executed by:
  • tst_QTimeLine
1
515 case QEasingCurve::InCurve:
never executed: case QEasingCurve::InCurve:
0
516 return EaseInCurve;
never executed: return EaseInCurve;
0
517 case QEasingCurve::OutCurve:
never executed: case QEasingCurve::OutCurve:
0
518 return EaseOutCurve;
never executed: return EaseOutCurve;
0
519 case QEasingCurve::Linear:
executed 1 time by 1 test: case QEasingCurve::Linear:
Executed by:
  • tst_QTimeLine
1
520 return LinearCurve;
executed 1 time by 1 test: return LinearCurve;
Executed by:
  • tst_QTimeLine
1
521 case QEasingCurve::SineCurve:
never executed: case QEasingCurve::SineCurve:
0
522 return SineCurve;
never executed: return SineCurve;
0
523 case QEasingCurve::CosineCurve:
never executed: case QEasingCurve::CosineCurve:
0
524 return CosineCurve;
never executed: return CosineCurve;
0
525 }-
526 return EaseInOutCurve;
dead code: return EaseInOutCurve;
-
527}-
528-
529void QTimeLine::setCurveShape(CurveShape shape)-
530{-
531 switch (shape) {-
532 default:
never executed: default:
0
533 case EaseInOutCurve:
executed 1 time by 1 test: case EaseInOutCurve:
Executed by:
  • tst_QTimeLine
1
534 setEasingCurve(QEasingCurve(QEasingCurve::InOutSine));-
535 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QTimeLine
1
536 case EaseInCurve:
never executed: case EaseInCurve:
0
537 setEasingCurve(QEasingCurve(QEasingCurve::InCurve));-
538 break;
never executed: break;
0
539 case EaseOutCurve:
never executed: case EaseOutCurve:
0
540 setEasingCurve(QEasingCurve(QEasingCurve::OutCurve));-
541 break;
never executed: break;
0
542 case LinearCurve:
executed 6 times by 1 test: case LinearCurve:
Executed by:
  • tst_QTimeLine
6
543 setEasingCurve(QEasingCurve(QEasingCurve::Linear));-
544 break;
executed 6 times by 1 test: break;
Executed by:
  • tst_QTimeLine
6
545 case SineCurve:
executed 2 times by 1 test: case SineCurve:
Executed by:
  • tst_QTimeLine
2
546 setEasingCurve(QEasingCurve(QEasingCurve::SineCurve));-
547 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_QTimeLine
2
548 case CosineCurve:
executed 1 time by 1 test: case CosineCurve:
Executed by:
  • tst_QTimeLine
1
549 setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));-
550 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QTimeLine
1
551 }-
552}-
553-
554/*!-
555 \property QTimeLine::easingCurve-
556-
557 \since 4.6-
558-
559 Specifies the easing curve that the timeline will use.-
560 If both easing curve and curveShape are set, the last set property will-
561 override the previous one. (If valueForTime() is reimplemented it will-
562 override both)-
563*/-
564-
565QEasingCurve QTimeLine::easingCurve() const-
566{-
567 Q_D(const QTimeLine);-
568 return d->easingCurve;
never executed: return d->easingCurve;
0
569}-
570-
571void QTimeLine::setEasingCurve(const QEasingCurve& curve)-
572{-
573 Q_D(QTimeLine);-
574 d->easingCurve = curve;-
575}
executed 10 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
10
576-
577/*!-
578 \property QTimeLine::currentTime-
579 \brief the current time of the time line.-
580-
581 When QTimeLine is in Running state, this value is updated continuously as-
582 a function of the duration and direction of the timeline. Otherwise, it is-
583 value that was current when stop() was called last, or the value set by-
584 setCurrentTime().-
585-
586 By default, this property contains a value of 0.-
587*/-
588int QTimeLine::currentTime() const-
589{-
590 Q_D(const QTimeLine);-
591 return d->currentTime;
executed 112 times by 1 test: return d->currentTime;
Executed by:
  • tst_QTimeLine
112
592}-
593void 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}
executed 12 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
12
601-
602/*!-
603 Returns the frame corresponding to the current time.-
604-
605 \sa currentTime(), frameForTime(), setFrameRange()-
606*/-
607int QTimeLine::currentFrame() const-
608{-
609 Q_D(const QTimeLine);-
610 return frameForTime(d->currentTime);
executed 1507 times by 2 tests: return frameForTime(d->currentTime);
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
1507
611}-
612-
613/*!-
614 Returns the value corresponding to the current time.-
615-
616 \sa valueForTime(), currentFrame()-
617*/-
618qreal QTimeLine::currentValue() const-
619{-
620 Q_D(const QTimeLine);-
621 return valueForTime(d->currentTime);
executed 4315 times by 2 tests: return valueForTime(d->currentTime);
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
4315
622}-
623-
624/*!-
625 Returns the frame corresponding to the time \a msec. This value is-
626 calculated using a linear interpolation of the start and end frame, based-
627 on the value returned by valueForTime().-
628-
629 \sa valueForTime(), setFrameRange()-
630*/-
631int QTimeLine::frameForTime(int msec) const-
632{-
633 Q_D(const QTimeLine);-
634 if (d->direction == Forward)
d->direction == ForwardDescription
TRUEevaluated 2370 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 578 times by 1 test
Evaluated by:
  • tst_QTimeLine
578-2370
635 return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec));
executed 2370 times by 2 tests: return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec));
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
2370
636 return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec));
executed 578 times by 1 test: return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec));
Executed by:
  • tst_QTimeLine
578
637}-
638-
639/*!-
640 Returns the timeline value for the time \a msec. The returned value, which-
641 varies depending on the curve shape, is always between 0 and 1. If \a msec-
642 is 0, the default implementation always returns 0.-
643-
644 Reimplement this function to provide a custom curve shape for your-
645 timeline.-
646-
647 \sa CurveShape, frameForTime()-
648*/-
649qreal 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);
executed 7276 times by 2 tests: return d->easingCurve.valueForProgress(value);
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
7276
656}-
657-
658/*!-
659 Starts the timeline. QTimeLine will enter Running state, and once it-
660 enters the event loop, it will update its current time, frame and value at-
661 regular intervals. The default interval is 40 ms (i.e., 25 times per-
662 second). You can change the update interval by calling-
663 setUpdateInterval().-
664-
665 The timeline will start from position 0, or the end if going backward.-
666 If you want to resume a stopped timeline without restarting, you can call-
667 resume() instead.-
668-
669 \sa resume(), updateInterval(), frameChanged(), valueChanged()-
670*/-
671void QTimeLine::start()-
672{-
673 Q_D(QTimeLine);-
674 if (d->timerId) {
d->timerIdDescription
TRUEnever evaluated
FALSEevaluated 38 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
0-38
675 qWarning("QTimeLine::start: already running");-
676 return;
never executed: return;
0
677 }-
678 int curTime = 0;-
679 if (d->direction == Backward)
d->direction == BackwardDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 33 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
5-33
680 curTime = d->duration;
executed 5 times by 1 test: curTime = d->duration;
Executed by:
  • tst_QTimeLine
5
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}
executed 38 times by 2 tests: end of block
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
38
688-
689/*!-
690 Resumes the timeline from the current time. QTimeLine will reenter Running-
691 state, and once it enters the event loop, it will update its current time,-
692 frame and value at regular intervals.-
693-
694 In contrast to start(), this function does not restart the timeline before-
695 it resumes.-
696-
697 \sa start(), updateInterval(), frameChanged(), valueChanged()-
698*/-
699void QTimeLine::resume()-
700{-
701 Q_D(QTimeLine);-
702 if (d->timerId) {
d->timerIdDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QTimeLine
0-3
703 qWarning("QTimeLine::resume: already running");-
704 return;
never executed: return;
0
705 }-
706 d->timerId = startTimer(d->updateInterval);-
707 d->startTime = d->currentTime;-
708 d->timer.start();-
709 d->setState(Running);-
710}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
3
711-
712/*!-
713 Stops the timeline, causing QTimeLine to enter NotRunning state.-
714-
715 \sa start()-
716*/-
717void QTimeLine::stop()-
718{-
719 Q_D(QTimeLine);-
720 if (d->timerId)
d->timerIdDescription
TRUEevaluated 41 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEnever evaluated
0-41
721 killTimer(d->timerId);
executed 41 times by 2 tests: killTimer(d->timerId);
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
41
722 d->setState(NotRunning);-
723 d->timerId = 0;-
724}
executed 41 times by 2 tests: end of block
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
41
725-
726/*!-
727 If \a paused is true, the timeline is paused, causing QTimeLine to enter-
728 Paused state. No updates will be signaled until either start() or-
729 setPaused(false) is called. If \a paused is false, the timeline is resumed-
730 and continues where it left.-
731-
732 \sa state(), start()-
733*/-
734void QTimeLine::setPaused(bool paused)-
735{-
736 Q_D(QTimeLine);-
737 if (d->state == NotRunning) {
d->state == NotRunningDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTimeLine
0-2
738 qWarning("QTimeLine::setPaused: Not running");-
739 return;
never executed: return;
0
740 }-
741 if (paused && d->state != Paused) {
pausedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
d->state != PausedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEnever evaluated
0-1
742 d->startTime = d->currentTime;-
743 killTimer(d->timerId);-
744 d->timerId = 0;-
745 d->setState(Paused);-
746 } else if (!paused && d->state == Paused) {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QTimeLine
!pausedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEnever evaluated
d->state == PausedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTimeLine
FALSEnever evaluated
0-1
747 // Same as resume()-
748 d->timerId = startTimer(d->updateInterval);-
749 d->startTime = d->currentTime;-
750 d->timer.start();-
751 d->setState(Running);-
752 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QTimeLine
1
753}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
2
754-
755/*!-
756 Toggles the direction of the timeline. If the direction was Forward, it-
757 becomes Backward, and vice verca.-
758-
759 \sa setDirection()-
760*/-
761void QTimeLine::toggleDirection()-
762{-
763 Q_D(QTimeLine);-
764 setDirection(d->direction == Forward ? Backward : Forward);-
765}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
2
766-
767/*!-
768 \reimp-
769*/-
770void QTimeLine::timerEvent(QTimerEvent *event)-
771{-
772 Q_D(QTimeLine);-
773 if (event->timerId() != d->timerId) {
event->timerId() != d->timerIdDescription
TRUEnever evaluated
FALSEevaluated 1391 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
0-1391
774 event->ignore();-
775 return;
never executed: return;
0
776 }-
777 event->accept();-
778-
779 if (d->direction == Forward) {
d->direction == ForwardDescription
TRUEevaluated 1119 times by 2 tests
Evaluated by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
FALSEevaluated 272 times by 1 test
Evaluated by:
  • tst_QTimeLine
272-1119
780 d->setCurrentTime(d->startTime + d->timer.elapsed());-
781 } else {
executed 1119 times by 2 tests: end of block
Executed by:
  • tst_QGraphicsLayout
  • tst_QTimeLine
1119
782 d->setCurrentTime(d->startTime - d->timer.elapsed());-
783 }
executed 272 times by 1 test: end of block
Executed by:
  • tst_QTimeLine
272
784}-
785-
786QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9