styles/qstyleanimation.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
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 QtGui 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 "qstyleanimation_p.h" -
43#include <qcoreapplication.h> -
44#include <qwidget.h> -
45#include <qevent.h> -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(), -
50 _delay(0), _duration(-1), _startTime(QTime::currentTime()) -
51{ -
52 if (target) {
partially evaluated: target
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
53 moveToThread(target->thread());
executed (the execution status of this line is deduced): moveToThread(target->thread());
-
54 setParent(target);
executed (the execution status of this line is deduced): setParent(target);
-
55 }
executed: }
Execution Count:2
2
56}
executed: }
Execution Count:2
2
57 -
58QStyleAnimation::~QStyleAnimation() -
59{ -
60} -
61 -
62QObject *QStyleAnimation::target() const -
63{ -
64 return parent();
executed: return parent();
Execution Count:51
51
65} -
66 -
67int QStyleAnimation::duration() const -
68{ -
69 return _duration;
executed: return _duration;
Execution Count:33
33
70} -
71 -
72void QStyleAnimation::setDuration(int duration) -
73{ -
74 _duration = duration;
never executed (the execution status of this line is deduced): _duration = duration;
-
75}
never executed: }
0
76 -
77int QStyleAnimation::delay() const -
78{ -
79 return _delay;
never executed: return _delay;
0
80} -
81 -
82void QStyleAnimation::setDelay(int delay) -
83{ -
84 _delay = delay;
never executed (the execution status of this line is deduced): _delay = delay;
-
85}
never executed: }
0
86 -
87QTime QStyleAnimation::startTime() const -
88{ -
89 return _startTime;
never executed: return _startTime;
0
90} -
91 -
92void QStyleAnimation::setStartTime(const QTime &time) -
93{ -
94 _startTime = time;
never executed (the execution status of this line is deduced): _startTime = time;
-
95}
never executed: }
0
96 -
97void QStyleAnimation::updateTarget() -
98{ -
99 QEvent event(QEvent::StyleAnimationUpdate);
executed (the execution status of this line is deduced): QEvent event(QEvent::StyleAnimationUpdate);
-
100 QCoreApplication::sendEvent(target(), &event);
executed (the execution status of this line is deduced): QCoreApplication::sendEvent(target(), &event);
-
101}
executed: }
Execution Count:15
15
102 -
103bool QStyleAnimation::isUpdateNeeded() const -
104{ -
105 return currentTime() > _delay;
executed: return currentTime() > _delay;
Execution Count:32
32
106} -
107 -
108void QStyleAnimation::updateCurrentTime(int) -
109{ -
110 if (QObject *tgt = target()) {
partially evaluated: QObject *tgt = target()
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
111 if (tgt->isWidgetType()) {
partially evaluated: tgt->isWidgetType()
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
112 QWidget *widget = static_cast<QWidget *>(tgt);
executed (the execution status of this line is deduced): QWidget *widget = static_cast<QWidget *>(tgt);
-
113 if (!widget->isVisible() || widget->window()->isMinimized())
partially evaluated: !widget->isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
partially evaluated: widget->window()->isMinimized()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
0-32
114 stop();
never executed: stop();
0
115 }
executed: }
Execution Count:32
32
116 -
117 if (isUpdateNeeded())
evaluated: isUpdateNeeded()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:17
15-17
118 updateTarget();
executed: updateTarget();
Execution Count:15
15
119 }
executed: }
Execution Count:32
32
120}
executed: }
Execution Count:32
32
121 -
122QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : -
123 QStyleAnimation(target), _speed(speed), _step(-1) -
124{ -
125}
executed: }
Execution Count:2
2
126 -
127int QProgressStyleAnimation::animationStep() const -
128{ -
129 return currentTime() / (1000.0 / _speed);
executed: return currentTime() / (1000.0 / _speed);
Execution Count:45
45
130} -
131 -
132int QProgressStyleAnimation::progressStep(int width) const -
133{ -
134 int step = animationStep();
never executed (the execution status of this line is deduced): int step = animationStep();
-
135 int progress = (step * width / _speed) % width;
never executed (the execution status of this line is deduced): int progress = (step * width / _speed) % width;
-
136 if (((step * width / _speed) % (2 * width)) >= width)
never evaluated: ((step * width / _speed) % (2 * width)) >= width
0
137 progress = width - progress;
never executed: progress = width - progress;
0
138 return progress;
never executed: return progress;
0
139} -
140 -
141int QProgressStyleAnimation::speed() const -
142{ -
143 return _speed;
never executed: return _speed;
0
144} -
145 -
146void QProgressStyleAnimation::setSpeed(int speed) -
147{ -
148 _speed = speed;
never executed (the execution status of this line is deduced): _speed = speed;
-
149}
never executed: }
0
150 -
151bool QProgressStyleAnimation::isUpdateNeeded() const -
152{ -
153 if (QStyleAnimation::isUpdateNeeded()) {
evaluated: QStyleAnimation::isUpdateNeeded()
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:2
2-30
154 int current = animationStep();
executed (the execution status of this line is deduced): int current = animationStep();
-
155 if (_step == -1 || _step != current)
evaluated: _step == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:29
evaluated: _step != current
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:15
1-29
156 { -
157 _step = current;
executed (the execution status of this line is deduced): _step = current;
-
158 return true;
executed: return true;
Execution Count:15
15
159 } -
160 }
executed: }
Execution Count:15
15
161 return false;
executed: return false;
Execution Count:17
17
162} -
163 -
164QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : -
165 QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) -
166{ -
167 setDuration(250);
never executed (the execution status of this line is deduced): setDuration(250);
-
168}
never executed: }
0
169 -
170qreal QNumberStyleAnimation::startValue() const -
171{ -
172 return _start;
never executed: return _start;
0
173} -
174 -
175void QNumberStyleAnimation::setStartValue(qreal value) -
176{ -
177 _start = value;
never executed (the execution status of this line is deduced): _start = value;
-
178}
never executed: }
0
179 -
180qreal QNumberStyleAnimation::endValue() const -
181{ -
182 return _end;
never executed: return _end;
0
183} -
184 -
185void QNumberStyleAnimation::setEndValue(qreal value) -
186{ -
187 _end = value;
never executed (the execution status of this line is deduced): _end = value;
-
188}
never executed: }
0
189 -
190qreal QNumberStyleAnimation::currentValue() const -
191{ -
192 qreal step = qreal(currentTime() - delay()) / (duration() - delay());
never executed (the execution status of this line is deduced): qreal step = qreal(currentTime() - delay()) / (duration() - delay());
-
193 return _start + qMax(qreal(0), step) * (_end - _start);
never executed: return _start + qMax(qreal(0), step) * (_end - _start);
0
194} -
195 -
196bool QNumberStyleAnimation::isUpdateNeeded() const -
197{ -
198 if (QStyleAnimation::isUpdateNeeded()) {
never evaluated: QStyleAnimation::isUpdateNeeded()
0
199 qreal current = currentValue();
never executed (the execution status of this line is deduced): qreal current = currentValue();
-
200 if (!qFuzzyCompare(_prev, current))
never evaluated: !qFuzzyCompare(_prev, current)
0
201 { -
202 _prev = current;
never executed (the execution status of this line is deduced): _prev = current;
-
203 return true;
never executed: return true;
0
204 } -
205 }
never executed: }
0
206 return false;
never executed: return false;
0
207} -
208 -
209QBlendStyleAnimation::QBlendStyleAnimation(Type type, QObject *target) : -
210 QStyleAnimation(target), _type(type) -
211{ -
212 setDuration(250);
never executed (the execution status of this line is deduced): setDuration(250);
-
213}
never executed: }
0
214 -
215QImage QBlendStyleAnimation::startImage() const -
216{ -
217 return _start;
never executed: return _start;
0
218} -
219 -
220void QBlendStyleAnimation::setStartImage(const QImage& image) -
221{ -
222 _start = image;
never executed (the execution status of this line is deduced): _start = image;
-
223}
never executed: }
0
224 -
225QImage QBlendStyleAnimation::endImage() const -
226{ -
227 return _end;
never executed: return _end;
0
228} -
229 -
230void QBlendStyleAnimation::setEndImage(const QImage& image) -
231{ -
232 _end = image;
never executed (the execution status of this line is deduced): _end = image;
-
233}
never executed: }
0
234 -
235QImage QBlendStyleAnimation::currentImage() const -
236{ -
237 return _current;
never executed: return _current;
0
238} -
239 -
240/*! \internal -
241 -
242 A helper function to blend two images. -
243 -
244 The result consists of ((alpha)*startImage) + ((1-alpha)*endImage) -
245 -
246*/ -
247static QImage blendedImage(const QImage &start, const QImage &end, float alpha) -
248{ -
249 if (start.isNull() || end.isNull())
never evaluated: start.isNull()
never evaluated: end.isNull()
0
250 return QImage();
never executed: return QImage();
0
251 -
252 QImage blended;
never executed (the execution status of this line is deduced): QImage blended;
-
253 const int a = qRound(alpha*256);
never executed (the execution status of this line is deduced): const int a = qRound(alpha*256);
-
254 const int ia = 256 - a;
never executed (the execution status of this line is deduced): const int ia = 256 - a;
-
255 const int sw = start.width();
never executed (the execution status of this line is deduced): const int sw = start.width();
-
256 const int sh = start.height();
never executed (the execution status of this line is deduced): const int sh = start.height();
-
257 const int bpl = start.bytesPerLine();
never executed (the execution status of this line is deduced): const int bpl = start.bytesPerLine();
-
258 switch (start.depth()) { -
259 case 32: -
260 { -
261 blended = QImage(sw, sh, start.format());
never executed (the execution status of this line is deduced): blended = QImage(sw, sh, start.format());
-
262 uchar *mixed_data = blended.bits();
never executed (the execution status of this line is deduced): uchar *mixed_data = blended.bits();
-
263 const uchar *back_data = start.bits();
never executed (the execution status of this line is deduced): const uchar *back_data = start.bits();
-
264 const uchar *front_data = end.bits();
never executed (the execution status of this line is deduced): const uchar *front_data = end.bits();
-
265 for (int sy = 0; sy < sh; sy++) {
never evaluated: sy < sh
0
266 quint32* mixed = (quint32*)mixed_data;
never executed (the execution status of this line is deduced): quint32* mixed = (quint32*)mixed_data;
-
267 const quint32* back = (const quint32*)back_data;
never executed (the execution status of this line is deduced): const quint32* back = (const quint32*)back_data;
-
268 const quint32* front = (const quint32*)front_data;
never executed (the execution status of this line is deduced): const quint32* front = (const quint32*)front_data;
-
269 for (int sx = 0; sx < sw; sx++) {
never evaluated: sx < sw
0
270 quint32 bp = back[sx];
never executed (the execution status of this line is deduced): quint32 bp = back[sx];
-
271 quint32 fp = front[sx];
never executed (the execution status of this line is deduced): quint32 fp = front[sx];
-
272 mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8,
never executed (the execution status of this line is deduced): mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8,
-
273 (qGreen(bp)*ia + qGreen(fp)*a)>>8,
never executed (the execution status of this line is deduced): (qGreen(bp)*ia + qGreen(fp)*a)>>8,
-
274 (qBlue(bp)*ia + qBlue(fp)*a)>>8,
never executed (the execution status of this line is deduced): (qBlue(bp)*ia + qBlue(fp)*a)>>8,
-
275 (qAlpha(bp)*ia + qAlpha(fp)*a)>>8);
never executed (the execution status of this line is deduced): (qAlpha(bp)*ia + qAlpha(fp)*a)>>8);
-
276 }
never executed: }
0
277 mixed_data += bpl;
never executed (the execution status of this line is deduced): mixed_data += bpl;
-
278 back_data += bpl;
never executed (the execution status of this line is deduced): back_data += bpl;
-
279 front_data += bpl;
never executed (the execution status of this line is deduced): front_data += bpl;
-
280 }
never executed: }
0
281 } -
282 default: -
283 break;
never executed: break;
0
284 } -
285 return blended;
never executed: return blended;
0
286} -
287 -
288void QBlendStyleAnimation::updateCurrentTime(int time) -
289{ -
290 QStyleAnimation::updateCurrentTime(time);
never executed (the execution status of this line is deduced): QStyleAnimation::updateCurrentTime(time);
-
291 -
292 float alpha = 1.0;
never executed (the execution status of this line is deduced): float alpha = 1.0;
-
293 if (duration() > 0) {
never evaluated: duration() > 0
0
294 if (_type == Pulse) {
never evaluated: _type == Pulse
0
295 time = time % duration() * 2;
never executed (the execution status of this line is deduced): time = time % duration() * 2;
-
296 if (time > duration())
never evaluated: time > duration()
0
297 time = duration() * 2 - time;
never executed: time = duration() * 2 - time;
0
298 }
never executed: }
0
299 -
300 alpha = time / static_cast<float>(duration());
never executed (the execution status of this line is deduced): alpha = time / static_cast<float>(duration());
-
301 -
302 if (_type == Transition && time > duration()) {
never evaluated: _type == Transition
never evaluated: time > duration()
0
303 alpha = 1.0;
never executed (the execution status of this line is deduced): alpha = 1.0;
-
304 stop();
never executed (the execution status of this line is deduced): stop();
-
305 }
never executed: }
0
306 } else if (time > 0) {
never executed: }
never evaluated: time > 0
0
307 stop();
never executed (the execution status of this line is deduced): stop();
-
308 }
never executed: }
0
309 -
310 _current = blendedImage(_start, _end, alpha);
never executed (the execution status of this line is deduced): _current = blendedImage(_start, _end, alpha);
-
311}
never executed: }
0
312 -
313QT_END_NAMESPACE -
314 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial