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