Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qtimeline.h" | - |
43 | | - |
44 | #include <private/qobject_p.h> | - |
45 | #include <QtCore/qcoreevent.h> | - |
46 | #include <QtCore/qmath.h> | - |
47 | #include <QtCore/qelapsedtimer.h> | - |
48 | | - |
49 | QT_BEGIN_NAMESPACE | - |
50 | | - |
51 | class QTimeLinePrivate : public QObjectPrivate | - |
52 | { | - |
53 | Q_DECLARE_PUBLIC(QTimeLine) | - |
54 | public: | - |
55 | inline QTimeLinePrivate() | - |
56 | : startTime(0), duration(1000), startFrame(0), endFrame(0), | - |
57 | updateInterval(1000 / 25), | - |
58 | totalLoopCount(1), currentLoopCount(0), currentTime(0), timerId(0), | - |
59 | direction(QTimeLine::Forward), easingCurve(QEasingCurve::InOutSine), | - |
60 | state(QTimeLine::NotRunning) | - |
61 | { } executed: } Execution Count:27 | 27 |
62 | | - |
63 | int startTime; | - |
64 | int duration; | - |
65 | int startFrame; | - |
66 | int endFrame; | - |
67 | int updateInterval; | - |
68 | int totalLoopCount; | - |
69 | int currentLoopCount; | - |
70 | | - |
71 | int currentTime; | - |
72 | int timerId; | - |
73 | QElapsedTimer timer; | - |
74 | | - |
75 | QTimeLine::Direction direction; | - |
76 | QEasingCurve easingCurve; | - |
77 | QTimeLine::State state; | - |
78 | inline void setState(QTimeLine::State newState) | - |
79 | { | - |
80 | Q_Q(QTimeLine); executed (the execution status of this line is deduced): QTimeLine * const q = q_func(); | - |
81 | if (newState != state) evaluated: newState != state yes Evaluation Count:80 | yes Evaluation Count:2 |
| 2-80 |
82 | emit q->stateChanged(state = newState, QTimeLine::QPrivateSignal()); executed: q->stateChanged(state = newState, QTimeLine::QPrivateSignal()); Execution Count:80 | 80 |
83 | } executed: } Execution Count:82 | 82 |
84 | | - |
85 | void setCurrentTime(int msecs); | - |
86 | }; | - |
87 | | - |
88 | /*! | - |
89 | \internal | - |
90 | */ | - |
91 | void QTimeLinePrivate::setCurrentTime(int msecs) | - |
92 | { | - |
93 | Q_Q(QTimeLine); executed (the execution status of this line is deduced): QTimeLine * const q = q_func(); | - |
94 | | - |
95 | qreal lastValue = q->currentValue(); executed (the execution status of this line is deduced): qreal lastValue = q->currentValue(); | - |
96 | int lastFrame = q->currentFrame(); executed (the execution status of this line is deduced): int lastFrame = q->currentFrame(); | - |
97 | | - |
98 | // Determine if we are looping. | - |
99 | int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs; evaluated: (direction == QTimeLine::Backward) yes Evaluation Count:325 | yes Evaluation Count:1114 |
| 325-1114 |
100 | int loopCount = elapsed / duration; executed (the execution status of this line is deduced): int loopCount = elapsed / duration; | - |
101 | | - |
102 | bool looping = (loopCount != currentLoopCount); executed (the execution status of this line is deduced): 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) evaluated: looping yes Evaluation Count:38 | yes Evaluation Count:1401 |
| 38-1401 |
109 | currentLoopCount = loopCount; executed: currentLoopCount = loopCount; Execution Count:38 | 38 |
110 | | - |
111 | // Normalize msecs to be between 0 and duration, inclusive. | - |
112 | currentTime = elapsed % duration; executed (the execution status of this line is deduced): currentTime = elapsed % duration; | - |
113 | if (direction == QTimeLine::Backward) evaluated: direction == QTimeLine::Backward yes Evaluation Count:325 | yes Evaluation Count:1114 |
| 325-1114 |
114 | currentTime = duration - currentTime; executed: currentTime = duration - currentTime; Execution Count:325 | 325 |
115 | | - |
116 | // Check if we have reached the end of loopcount. | - |
117 | bool finished = false; executed (the execution status of this line is deduced): bool finished = false; | - |
118 | if (totalLoopCount && currentLoopCount >= totalLoopCount) { evaluated: totalLoopCount yes Evaluation Count:1403 | yes Evaluation Count:36 |
evaluated: currentLoopCount >= totalLoopCount yes Evaluation Count:22 | yes Evaluation Count:1381 |
| 22-1403 |
119 | finished = true; executed (the execution status of this line is deduced): finished = true; | - |
120 | currentTime = (direction == QTimeLine::Backward) ? 0 : duration; evaluated: (direction == QTimeLine::Backward) yes Evaluation Count:3 | yes Evaluation Count:19 |
| 3-19 |
121 | currentLoopCount = totalLoopCount - 1; executed (the execution status of this line is deduced): currentLoopCount = totalLoopCount - 1; | - |
122 | } executed: } Execution Count:22 | 22 |
123 | | - |
124 | int currentFrame = q->frameForTime(currentTime); executed (the execution status of this line is deduced): int currentFrame = q->frameForTime(currentTime); | - |
125 | #ifdef QTIMELINE_DEBUG | - |
126 | qDebug() << "QTimeLinePrivate::setCurrentTime: frameForTime" << currentTime << currentFrame; | - |
127 | #endif | - |
128 | if (!qFuzzyCompare(lastValue, q->currentValue())) evaluated: !qFuzzyCompare(lastValue, q->currentValue()) yes Evaluation Count:1411 | yes Evaluation Count:28 |
| 28-1411 |
129 | emit q->valueChanged(q->currentValue(), QTimeLine::QPrivateSignal()); executed: q->valueChanged(q->currentValue(), QTimeLine::QPrivateSignal()); Execution Count:1411 | 1411 |
130 | if (lastFrame != currentFrame) { evaluated: lastFrame != currentFrame yes Evaluation Count:203 | yes Evaluation Count:1236 |
| 203-1236 |
131 | const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame); evaluated: direction == QTimeLine::Forward yes Evaluation Count:177 | yes Evaluation Count:26 |
| 26-177 |
132 | if (looping && !finished && transitionframe != currentFrame) { evaluated: looping yes Evaluation Count:33 | yes Evaluation Count:170 |
evaluated: !finished yes Evaluation Count:16 | yes Evaluation Count:17 |
partially evaluated: transitionframe != currentFrame yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-170 |
133 | #ifdef QTIMELINE_DEBUG | - |
134 | qDebug() << "QTimeLinePrivate::setCurrentTime: transitionframe"; | - |
135 | #endif | - |
136 | emit q->frameChanged(transitionframe, QTimeLine::QPrivateSignal()); executed (the execution status of this line is deduced): q->frameChanged(transitionframe, QTimeLine::QPrivateSignal()); | - |
137 | } executed: } Execution Count:16 | 16 |
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()); executed (the execution status of this line is deduced): q->frameChanged(currentFrame, QTimeLine::QPrivateSignal()); | - |
157 | } executed: } Execution Count:203 | 203 |
158 | if (finished && state == QTimeLine::Running) { evaluated: finished yes Evaluation Count:22 | yes Evaluation Count:1417 |
partially evaluated: state == QTimeLine::Running yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-1417 |
159 | q->stop(); executed (the execution status of this line is deduced): q->stop(); | - |
160 | emit q->finished(QTimeLine::QPrivateSignal()); executed (the execution status of this line is deduced): q->finished(QTimeLine::QPrivateSignal()); | - |
161 | } executed: } Execution Count:22 | 22 |
162 | } executed: } Execution Count:1439 | 1439 |
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 (e.g., setValue() in | - |
177 | 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 | */ | - |
309 | QTimeLine::QTimeLine(int duration, QObject *parent) | - |
310 | : QObject(*new QTimeLinePrivate, parent) | - |
311 | { | - |
312 | setDuration(duration); executed (the execution status of this line is deduced): setDuration(duration); | - |
313 | } executed: } Execution Count:27 | 27 |
314 | | - |
315 | /*! | - |
316 | Destroys the timeline. | - |
317 | */ | - |
318 | QTimeLine::~QTimeLine() | - |
319 | { | - |
320 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
321 | | - |
322 | if (d->state == Running) evaluated: d->state == Running yes Evaluation Count:6 | yes Evaluation Count:21 |
| 6-21 |
323 | stop(); executed: stop(); Execution Count:6 | 6 |
324 | } executed: } Execution Count:27 | 27 |
325 | | - |
326 | /*! | - |
327 | Returns the state of the timeline. | - |
328 | | - |
329 | \sa start(), setPaused(), stop() | - |
330 | */ | - |
331 | QTimeLine::State QTimeLine::state() const | - |
332 | { | - |
333 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
334 | return d->state; executed: return d->state; Execution Count:38 | 38 |
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 | */ | - |
345 | int QTimeLine::loopCount() const | - |
346 | { | - |
347 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
348 | return d->totalLoopCount; executed: return d->totalLoopCount; Execution Count:4 | 4 |
349 | } | - |
350 | void QTimeLine::setLoopCount(int count) | - |
351 | { | - |
352 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
353 | d->totalLoopCount = count; executed (the execution status of this line is deduced): d->totalLoopCount = count; | - |
354 | } executed: } Execution Count:2 | 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 | */ | - |
367 | QTimeLine::Direction QTimeLine::direction() const | - |
368 | { | - |
369 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
370 | return d->direction; executed: return d->direction; Execution Count:6 | 6 |
371 | } | - |
372 | void QTimeLine::setDirection(Direction direction) | - |
373 | { | - |
374 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
375 | d->direction = direction; executed (the execution status of this line is deduced): d->direction = direction; | - |
376 | d->startTime = d->currentTime; executed (the execution status of this line is deduced): d->startTime = d->currentTime; | - |
377 | d->timer.start(); executed (the execution status of this line is deduced): d->timer.start(); | - |
378 | } executed: } Execution Count:38 | 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 | */ | - |
392 | int QTimeLine::duration() const | - |
393 | { | - |
394 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
395 | return d->duration; executed: return d->duration; Execution Count:42 | 42 |
396 | } | - |
397 | void QTimeLine::setDuration(int duration) | - |
398 | { | - |
399 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
400 | if (duration <= 0) { partially evaluated: duration <= 0 no Evaluation Count:0 | yes Evaluation Count:31 |
| 0-31 |
401 | qWarning("QTimeLine::setDuration: cannot set duration <= 0"); never executed (the execution status of this line is deduced): QMessageLogger("tools/qtimeline.cpp", 401, __PRETTY_FUNCTION__).warning("QTimeLine::setDuration: cannot set duration <= 0"); | - |
402 | return; | 0 |
403 | } | - |
404 | d->duration = duration; executed (the execution status of this line is deduced): d->duration = duration; | - |
405 | } executed: } Execution Count:31 | 31 |
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 | */ | - |
413 | int QTimeLine::startFrame() const | - |
414 | { | - |
415 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
416 | return d->startFrame; executed: return d->startFrame; Execution Count:7 | 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 | */ | - |
425 | void QTimeLine::setStartFrame(int frame) | - |
426 | { | - |
427 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
428 | d->startFrame = frame; executed (the execution status of this line is deduced): d->startFrame = frame; | - |
429 | } executed: } Execution Count:2 | 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 | */ | - |
437 | int QTimeLine::endFrame() const | - |
438 | { | - |
439 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
440 | return d->endFrame; executed: return d->endFrame; Execution Count:7 | 7 |
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 | */ | - |
449 | void QTimeLine::setEndFrame(int frame) | - |
450 | { | - |
451 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
452 | d->endFrame = frame; executed (the execution status of this line is deduced): d->endFrame = frame; | - |
453 | } executed: } Execution Count:2 | 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 | */ | - |
466 | void QTimeLine::setFrameRange(int startFrame, int endFrame) | - |
467 | { | - |
468 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
469 | d->startFrame = startFrame; executed (the execution status of this line is deduced): d->startFrame = startFrame; | - |
470 | d->endFrame = endFrame; executed (the execution status of this line is deduced): d->endFrame = endFrame; | - |
471 | } executed: } Execution Count:22 | 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 | */ | - |
484 | int QTimeLine::updateInterval() const | - |
485 | { | - |
486 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
487 | return d->updateInterval; executed: return d->updateInterval; Execution Count:2 | 2 |
488 | } | - |
489 | void QTimeLine::setUpdateInterval(int interval) | - |
490 | { | - |
491 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
492 | d->updateInterval = interval; executed (the execution status of this line is deduced): d->updateInterval = interval; | - |
493 | } executed: } Execution Count:5 | 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 | */ | - |
508 | QTimeLine::CurveShape QTimeLine::curveShape() const | - |
509 | { | - |
510 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
511 | switch (d->easingCurve.type()) { | - |
512 | default: | - |
513 | case QEasingCurve::InOutSine: | - |
514 | return EaseInOutCurve; executed: return EaseInOutCurve; Execution Count:1 | 1 |
515 | case QEasingCurve::InCurve: | - |
516 | return EaseInCurve; never executed: return EaseInCurve; | 0 |
517 | case QEasingCurve::OutCurve: | - |
518 | return EaseOutCurve; never executed: return EaseOutCurve; | 0 |
519 | case QEasingCurve::Linear: | - |
520 | return LinearCurve; executed: return LinearCurve; Execution Count:1 | 1 |
521 | case QEasingCurve::SineCurve: | - |
522 | return SineCurve; never executed: return SineCurve; | 0 |
523 | case QEasingCurve::CosineCurve: | - |
524 | return CosineCurve; never executed: return CosineCurve; | 0 |
525 | } | - |
526 | return EaseInOutCurve; never executed: return EaseInOutCurve; | 0 |
527 | } | - |
528 | | - |
529 | void QTimeLine::setCurveShape(CurveShape shape) | - |
530 | { | - |
531 | switch (shape) { | - |
532 | default: | - |
533 | case EaseInOutCurve: | - |
534 | setEasingCurve(QEasingCurve(QEasingCurve::InOutSine)); executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::InOutSine)); | - |
535 | break; executed: break; Execution Count:1 | 1 |
536 | case EaseInCurve: | - |
537 | setEasingCurve(QEasingCurve(QEasingCurve::InCurve)); never executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::InCurve)); | - |
538 | break; | 0 |
539 | case EaseOutCurve: | - |
540 | setEasingCurve(QEasingCurve(QEasingCurve::OutCurve)); never executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::OutCurve)); | - |
541 | break; | 0 |
542 | case LinearCurve: | - |
543 | setEasingCurve(QEasingCurve(QEasingCurve::Linear)); executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::Linear)); | - |
544 | break; executed: break; Execution Count:6 | 6 |
545 | case SineCurve: | - |
546 | setEasingCurve(QEasingCurve(QEasingCurve::SineCurve)); executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::SineCurve)); | - |
547 | break; executed: break; Execution Count:2 | 2 |
548 | case CosineCurve: | - |
549 | setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve)); executed (the execution status of this line is deduced): setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve)); | - |
550 | break; executed: break; Execution Count:1 | 1 |
551 | } | - |
552 | } executed: } Execution Count:10 | 10 |
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 | | - |
565 | QEasingCurve QTimeLine::easingCurve() const | - |
566 | { | - |
567 | Q_D(const QTimeLine); never executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
568 | return d->easingCurve; never executed: return d->easingCurve; | 0 |
569 | } | - |
570 | | - |
571 | void QTimeLine::setEasingCurve(const QEasingCurve& curve) | - |
572 | { | - |
573 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
574 | d->easingCurve = curve; executed (the execution status of this line is deduced): d->easingCurve = curve; | - |
575 | } executed: } Execution Count:10 | 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 | */ | - |
588 | int QTimeLine::currentTime() const | - |
589 | { | - |
590 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
591 | return d->currentTime; executed: return d->currentTime; Execution Count:22 | 22 |
592 | } | - |
593 | void QTimeLine::setCurrentTime(int msec) | - |
594 | { | - |
595 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
596 | d->startTime = 0; executed (the execution status of this line is deduced): d->startTime = 0; | - |
597 | d->currentLoopCount = 0; executed (the execution status of this line is deduced): d->currentLoopCount = 0; | - |
598 | d->timer.restart(); executed (the execution status of this line is deduced): d->timer.restart(); | - |
599 | d->setCurrentTime(msec); executed (the execution status of this line is deduced): d->setCurrentTime(msec); | - |
600 | } executed: } Execution Count:11 | 11 |
601 | | - |
602 | /*! | - |
603 | Returns the frame corresponding to the current time. | - |
604 | | - |
605 | \sa currentTime(), frameForTime(), setFrameRange() | - |
606 | */ | - |
607 | int QTimeLine::currentFrame() const | - |
608 | { | - |
609 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
610 | return frameForTime(d->currentTime); executed: return frameForTime(d->currentTime); Execution Count:1470 | 1470 |
611 | } | - |
612 | | - |
613 | /*! | - |
614 | Returns the value corresponding to the current time. | - |
615 | | - |
616 | \sa valueForTime(), currentFrame() | - |
617 | */ | - |
618 | qreal QTimeLine::currentValue() const | - |
619 | { | - |
620 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
621 | return valueForTime(d->currentTime); executed: return valueForTime(d->currentTime); Execution Count:4297 | 4297 |
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 | */ | - |
631 | int QTimeLine::frameForTime(int msec) const | - |
632 | { | - |
633 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
634 | if (d->direction == Forward) evaluated: d->direction == Forward yes Evaluation Count:2249 | yes Evaluation Count:660 |
| 660-2249 |
635 | return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec)); executed: return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec)); Execution Count:2249 | 2249 |
636 | return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec)); executed: return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec)); Execution Count:660 | 660 |
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 | */ | - |
649 | qreal QTimeLine::valueForTime(int msec) const | - |
650 | { | - |
651 | Q_D(const QTimeLine); executed (the execution status of this line is deduced): const QTimeLinePrivate * const d = d_func(); | - |
652 | msec = qMin(qMax(msec, 0), d->duration); executed (the execution status of this line is deduced): msec = qMin(qMax(msec, 0), d->duration); | - |
653 | | - |
654 | qreal value = msec / qreal(d->duration); executed (the execution status of this line is deduced): qreal value = msec / qreal(d->duration); | - |
655 | return d->easingCurve.valueForProgress(value); executed: return d->easingCurve.valueForProgress(value); Execution Count:7219 | 7219 |
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 | */ | - |
671 | void QTimeLine::start() | - |
672 | { | - |
673 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
674 | if (d->timerId) { partially evaluated: d->timerId no Evaluation Count:0 | yes Evaluation Count:37 |
| 0-37 |
675 | qWarning("QTimeLine::start: already running"); never executed (the execution status of this line is deduced): QMessageLogger("tools/qtimeline.cpp", 675, __PRETTY_FUNCTION__).warning("QTimeLine::start: already running"); | - |
676 | return; | 0 |
677 | } | - |
678 | int curTime = 0; executed (the execution status of this line is deduced): int curTime = 0; | - |
679 | if (d->direction == Backward) evaluated: d->direction == Backward yes Evaluation Count:5 | yes Evaluation Count:32 |
| 5-32 |
680 | curTime = d->duration; executed: curTime = d->duration; Execution Count:5 | 5 |
681 | d->timerId = startTimer(d->updateInterval); executed (the execution status of this line is deduced): d->timerId = startTimer(d->updateInterval); | - |
682 | d->startTime = curTime; executed (the execution status of this line is deduced): d->startTime = curTime; | - |
683 | d->currentLoopCount = 0; executed (the execution status of this line is deduced): d->currentLoopCount = 0; | - |
684 | d->timer.start(); executed (the execution status of this line is deduced): d->timer.start(); | - |
685 | d->setState(Running); executed (the execution status of this line is deduced): d->setState(Running); | - |
686 | d->setCurrentTime(curTime); executed (the execution status of this line is deduced): d->setCurrentTime(curTime); | - |
687 | } executed: } Execution Count:37 | 37 |
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 | */ | - |
699 | void QTimeLine::resume() | - |
700 | { | - |
701 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
702 | if (d->timerId) { partially evaluated: d->timerId no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
703 | qWarning("QTimeLine::resume: already running"); never executed (the execution status of this line is deduced): QMessageLogger("tools/qtimeline.cpp", 703, __PRETTY_FUNCTION__).warning("QTimeLine::resume: already running"); | - |
704 | return; | 0 |
705 | } | - |
706 | d->timerId = startTimer(d->updateInterval); executed (the execution status of this line is deduced): d->timerId = startTimer(d->updateInterval); | - |
707 | d->startTime = d->currentTime; executed (the execution status of this line is deduced): d->startTime = d->currentTime; | - |
708 | d->timer.start(); executed (the execution status of this line is deduced): d->timer.start(); | - |
709 | d->setState(Running); executed (the execution status of this line is deduced): d->setState(Running); | - |
710 | } executed: } Execution Count:3 | 3 |
711 | | - |
712 | /*! | - |
713 | Stops the timeline, causing QTimeLine to enter NotRunning state. | - |
714 | | - |
715 | \sa start() | - |
716 | */ | - |
717 | void QTimeLine::stop() | - |
718 | { | - |
719 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
720 | if (d->timerId) evaluated: d->timerId yes Evaluation Count:40 | yes Evaluation Count:2 |
| 2-40 |
721 | killTimer(d->timerId); executed: killTimer(d->timerId); Execution Count:40 | 40 |
722 | d->setState(NotRunning); executed (the execution status of this line is deduced): d->setState(NotRunning); | - |
723 | d->timerId = 0; executed (the execution status of this line is deduced): d->timerId = 0; | - |
724 | } executed: } Execution Count:42 | 42 |
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 | */ | - |
734 | void QTimeLine::setPaused(bool paused) | - |
735 | { | - |
736 | Q_D(QTimeLine); never executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
737 | if (d->state == NotRunning) { never evaluated: d->state == NotRunning | 0 |
738 | qWarning("QTimeLine::setPaused: Not running"); never executed (the execution status of this line is deduced): QMessageLogger("tools/qtimeline.cpp", 738, __PRETTY_FUNCTION__).warning("QTimeLine::setPaused: Not running"); | - |
739 | return; | 0 |
740 | } | - |
741 | if (paused && d->state != Paused) { never evaluated: paused never evaluated: d->state != Paused | 0 |
742 | d->startTime = d->currentTime; never executed (the execution status of this line is deduced): d->startTime = d->currentTime; | - |
743 | killTimer(d->timerId); never executed (the execution status of this line is deduced): killTimer(d->timerId); | - |
744 | d->timerId = 0; never executed (the execution status of this line is deduced): d->timerId = 0; | - |
745 | d->setState(Paused); never executed (the execution status of this line is deduced): d->setState(Paused); | - |
746 | } else if (!paused && d->state == Paused) { never executed: } never evaluated: !paused never evaluated: d->state == Paused | 0 |
747 | d->timerId = startTimer(d->updateInterval); never executed (the execution status of this line is deduced): d->timerId = startTimer(d->updateInterval); | - |
748 | d->setState(Running); never executed (the execution status of this line is deduced): d->setState(Running); | - |
749 | } | 0 |
750 | } | - |
751 | | - |
752 | /*! | - |
753 | Toggles the direction of the timeline. If the direction was Forward, it | - |
754 | becomes Backward, and vice verca. | - |
755 | | - |
756 | \sa setDirection() | - |
757 | */ | - |
758 | void QTimeLine::toggleDirection() | - |
759 | { | - |
760 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
761 | setDirection(d->direction == Forward ? Backward : Forward); executed (the execution status of this line is deduced): setDirection(d->direction == Forward ? Backward : Forward); | - |
762 | } executed: } Execution Count:2 | 2 |
763 | | - |
764 | /*! | - |
765 | \reimp | - |
766 | */ | - |
767 | void QTimeLine::timerEvent(QTimerEvent *event) | - |
768 | { | - |
769 | Q_D(QTimeLine); executed (the execution status of this line is deduced): QTimeLinePrivate * const d = d_func(); | - |
770 | if (event->timerId() != d->timerId) { partially evaluated: event->timerId() != d->timerId no Evaluation Count:0 | yes Evaluation Count:1391 |
| 0-1391 |
771 | event->ignore(); never executed (the execution status of this line is deduced): event->ignore(); | - |
772 | return; | 0 |
773 | } | - |
774 | event->accept(); executed (the execution status of this line is deduced): event->accept(); | - |
775 | | - |
776 | if (d->direction == Forward) { evaluated: d->direction == Forward yes Evaluation Count:1075 | yes Evaluation Count:316 |
| 316-1075 |
777 | d->setCurrentTime(d->startTime + d->timer.elapsed()); executed (the execution status of this line is deduced): d->setCurrentTime(d->startTime + d->timer.elapsed()); | - |
778 | } else { executed: } Execution Count:1075 | 1075 |
779 | d->setCurrentTime(d->startTime - d->timer.elapsed()); executed (the execution status of this line is deduced): d->setCurrentTime(d->startTime - d->timer.elapsed()); | - |
780 | } executed: } Execution Count:316 | 316 |
781 | } | - |
782 | | - |
783 | QT_END_NAMESPACE | - |
784 | | - |
| | |