styles/qstyleanimation.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(), -
5 _delay(0), _duration(-1), _startTime(QTime::currentTime()) -
6{ -
7 if (target) {
partially evaluated: target
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
8 moveToThread(target->thread()); -
9 setParent(target); -
10 }
executed: }
Execution Count:2
2
11}
executed: }
Execution Count:2
2
12 -
13QStyleAnimation::~QStyleAnimation() -
14{ -
15} -
16 -
17QObject *QStyleAnimation::target() const -
18{ -
19 return parent();
executed: return parent();
Execution Count:51
51
20} -
21 -
22int QStyleAnimation::duration() const -
23{ -
24 return _duration;
executed: return _duration;
Execution Count:33
33
25} -
26 -
27void QStyleAnimation::setDuration(int duration) -
28{ -
29 _duration = duration; -
30}
never executed: }
0
31 -
32int QStyleAnimation::delay() const -
33{ -
34 return _delay;
never executed: return _delay;
0
35} -
36 -
37void QStyleAnimation::setDelay(int delay) -
38{ -
39 _delay = delay; -
40}
never executed: }
0
41 -
42QTime QStyleAnimation::startTime() const -
43{ -
44 return _startTime;
never executed: return _startTime;
0
45} -
46 -
47void QStyleAnimation::setStartTime(const QTime &time) -
48{ -
49 _startTime = time; -
50}
never executed: }
0
51 -
52void QStyleAnimation::updateTarget() -
53{ -
54 QEvent event(QEvent::StyleAnimationUpdate); -
55 QCoreApplication::sendEvent(target(), &event); -
56}
executed: }
Execution Count:15
15
57 -
58bool QStyleAnimation::isUpdateNeeded() const -
59{ -
60 return currentTime() > _delay;
executed: return currentTime() > _delay;
Execution Count:32
32
61} -
62 -
63void QStyleAnimation::updateCurrentTime(int) -
64{ -
65 if (QObject *tgt = target()) {
partially evaluated: QObject *tgt = target()
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
66 if (tgt->isWidgetType()) {
partially evaluated: tgt->isWidgetType()
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
67 QWidget *widget = static_cast<QWidget *>(tgt); -
68 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
69 stop();
never executed: stop();
0
70 }
executed: }
Execution Count:32
32
71 -
72 if (isUpdateNeeded())
evaluated: isUpdateNeeded()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:17
15-17
73 updateTarget();
executed: updateTarget();
Execution Count:15
15
74 }
executed: }
Execution Count:32
32
75}
executed: }
Execution Count:32
32
76 -
77QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : -
78 QStyleAnimation(target), _speed(speed), _step(-1) -
79{ -
80}
executed: }
Execution Count:2
2
81 -
82int QProgressStyleAnimation::animationStep() const -
83{ -
84 return currentTime() / (1000.0 / _speed);
executed: return currentTime() / (1000.0 / _speed);
Execution Count:45
45
85} -
86 -
87int QProgressStyleAnimation::progressStep(int width) const -
88{ -
89 int step = animationStep(); -
90 int progress = (step * width / _speed) % width; -
91 if (((step * width / _speed) % (2 * width)) >= width)
never evaluated: ((step * width / _speed) % (2 * width)) >= width
0
92 progress = width - progress;
never executed: progress = width - progress;
0
93 return progress;
never executed: return progress;
0
94} -
95 -
96int QProgressStyleAnimation::speed() const -
97{ -
98 return _speed;
never executed: return _speed;
0
99} -
100 -
101void QProgressStyleAnimation::setSpeed(int speed) -
102{ -
103 _speed = speed; -
104}
never executed: }
0
105 -
106bool QProgressStyleAnimation::isUpdateNeeded() const -
107{ -
108 if (QStyleAnimation::isUpdateNeeded()) {
evaluated: QStyleAnimation::isUpdateNeeded()
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:2
2-30
109 int current = animationStep(); -
110 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
111 { -
112 _step = current; -
113 return true;
executed: return true;
Execution Count:15
15
114 } -
115 }
executed: }
Execution Count:15
15
116 return false;
executed: return false;
Execution Count:17
17
117} -
118 -
119QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : -
120 QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) -
121{ -
122 setDuration(250); -
123}
never executed: }
0
124 -
125qreal QNumberStyleAnimation::startValue() const -
126{ -
127 return _start;
never executed: return _start;
0
128} -
129 -
130void QNumberStyleAnimation::setStartValue(qreal value) -
131{ -
132 _start = value; -
133}
never executed: }
0
134 -
135qreal QNumberStyleAnimation::endValue() const -
136{ -
137 return _end;
never executed: return _end;
0
138} -
139 -
140void QNumberStyleAnimation::setEndValue(qreal value) -
141{ -
142 _end = value; -
143}
never executed: }
0
144 -
145qreal QNumberStyleAnimation::currentValue() const -
146{ -
147 qreal step = qreal(currentTime() - delay()) / (duration() - delay()); -
148 return _start + qMax(qreal(0), step) * (_end - _start);
never executed: return _start + qMax(qreal(0), step) * (_end - _start);
0
149} -
150 -
151bool QNumberStyleAnimation::isUpdateNeeded() const -
152{ -
153 if (QStyleAnimation::isUpdateNeeded()) {
never evaluated: QStyleAnimation::isUpdateNeeded()
0
154 qreal current = currentValue(); -
155 if (!qFuzzyCompare(_prev, current))
never evaluated: !qFuzzyCompare(_prev, current)
0
156 { -
157 _prev = current; -
158 return true;
never executed: return true;
0
159 } -
160 }
never executed: }
0
161 return false;
never executed: return false;
0
162} -
163 -
164QBlendStyleAnimation::QBlendStyleAnimation(Type type, QObject *target) : -
165 QStyleAnimation(target), _type(type) -
166{ -
167 setDuration(250); -
168}
never executed: }
0
169 -
170QImage QBlendStyleAnimation::startImage() const -
171{ -
172 return _start;
never executed: return _start;
0
173} -
174 -
175void QBlendStyleAnimation::setStartImage(const QImage& image) -
176{ -
177 _start = image; -
178}
never executed: }
0
179 -
180QImage QBlendStyleAnimation::endImage() const -
181{ -
182 return _end;
never executed: return _end;
0
183} -
184 -
185void QBlendStyleAnimation::setEndImage(const QImage& image) -
186{ -
187 _end = image; -
188}
never executed: }
0
189 -
190QImage QBlendStyleAnimation::currentImage() const -
191{ -
192 return _current;
never executed: return _current;
0
193} -
194static QImage blendedImage(const QImage &start, const QImage &end, float alpha) -
195{ -
196 if (start.isNull() || end.isNull())
never evaluated: start.isNull()
never evaluated: end.isNull()
0
197 return QImage();
never executed: return QImage();
0
198 -
199 QImage blended; -
200 const int a = qRound(alpha*256); -
201 const int ia = 256 - a; -
202 const int sw = start.width(); -
203 const int sh = start.height(); -
204 const int bpl = start.bytesPerLine(); -
205 switch (start.depth()) { -
206 case 32: -
207 { -
208 blended = QImage(sw, sh, start.format()); -
209 uchar *mixed_data = blended.bits(); -
210 const uchar *back_data = start.bits(); -
211 const uchar *front_data = end.bits(); -
212 for (int sy = 0; sy < sh; sy++) {
never evaluated: sy < sh
0
213 quint32* mixed = (quint32*)mixed_data; -
214 const quint32* back = (const quint32*)back_data; -
215 const quint32* front = (const quint32*)front_data; -
216 for (int sx = 0; sx < sw; sx++) {
never evaluated: sx < sw
0
217 quint32 bp = back[sx]; -
218 quint32 fp = front[sx]; -
219 mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8, -
220 (qGreen(bp)*ia + qGreen(fp)*a)>>8, -
221 (qBlue(bp)*ia + qBlue(fp)*a)>>8, -
222 (qAlpha(bp)*ia + qAlpha(fp)*a)>>8); -
223 }
never executed: }
0
224 mixed_data += bpl; -
225 back_data += bpl; -
226 front_data += bpl; -
227 }
never executed: }
0
228 } -
229 default: -
230 break;
never executed: break;
0
231 } -
232 return blended;
never executed: return blended;
0
233} -
234 -
235void QBlendStyleAnimation::updateCurrentTime(int time) -
236{ -
237 QStyleAnimation::updateCurrentTime(time); -
238 -
239 float alpha = 1.0; -
240 if (duration() > 0) {
never evaluated: duration() > 0
0
241 if (_type == Pulse) {
never evaluated: _type == Pulse
0
242 time = time % duration() * 2; -
243 if (time > duration())
never evaluated: time > duration()
0
244 time = duration() * 2 - time;
never executed: time = duration() * 2 - time;
0
245 }
never executed: }
0
246 -
247 alpha = time / static_cast<float>(duration()); -
248 -
249 if (_type == Transition && time > duration()) {
never evaluated: _type == Transition
never evaluated: time > duration()
0
250 alpha = 1.0; -
251 stop(); -
252 }
never executed: }
0
253 } else if (time > 0) {
never executed: }
never evaluated: time > 0
0
254 stop(); -
255 }
never executed: }
0
256 -
257 _current = blendedImage(_start, _end, alpha); -
258}
never executed: }
0
259 -
260 -
261 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial