Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstyleanimation.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 QtWidgets 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 "qstyleanimation_p.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #ifndef QT_NO_ANIMATION | - | ||||||||||||
37 | - | |||||||||||||
38 | #include <qcoreapplication.h> | - | ||||||||||||
39 | #include <qwidget.h> | - | ||||||||||||
40 | #include <qevent.h> | - | ||||||||||||
41 | - | |||||||||||||
42 | QT_BEGIN_NAMESPACE | - | ||||||||||||
43 | - | |||||||||||||
44 | static const qreal ScrollBarFadeOutDuration = 200.0; | - | ||||||||||||
45 | static const qreal ScrollBarFadeOutDelay = 450.0; | - | ||||||||||||
46 | - | |||||||||||||
47 | QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), | - | ||||||||||||
48 | _delay(0), _duration(-1), _startTime(QTime::currentTime()), _fps(ThirtyFps), _skip(0) | - | ||||||||||||
49 | { | - | ||||||||||||
50 | } never executed: end of block | 0 | ||||||||||||
51 | - | |||||||||||||
52 | QStyleAnimation::~QStyleAnimation() | - | ||||||||||||
53 | { | - | ||||||||||||
54 | } | - | ||||||||||||
55 | - | |||||||||||||
56 | QObject *QStyleAnimation::target() const | - | ||||||||||||
57 | { | - | ||||||||||||
58 | return parent(); never executed: return parent(); | 0 | ||||||||||||
59 | } | - | ||||||||||||
60 | - | |||||||||||||
61 | int QStyleAnimation::duration() const | - | ||||||||||||
62 | { | - | ||||||||||||
63 | return _duration; never executed: return _duration; | 0 | ||||||||||||
64 | } | - | ||||||||||||
65 | - | |||||||||||||
66 | void QStyleAnimation::setDuration(int duration) | - | ||||||||||||
67 | { | - | ||||||||||||
68 | _duration = duration; | - | ||||||||||||
69 | } never executed: end of block | 0 | ||||||||||||
70 | - | |||||||||||||
71 | int QStyleAnimation::delay() const | - | ||||||||||||
72 | { | - | ||||||||||||
73 | return _delay; never executed: return _delay; | 0 | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | void QStyleAnimation::setDelay(int delay) | - | ||||||||||||
77 | { | - | ||||||||||||
78 | _delay = delay; | - | ||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||
80 | - | |||||||||||||
81 | QTime QStyleAnimation::startTime() const | - | ||||||||||||
82 | { | - | ||||||||||||
83 | return _startTime; never executed: return _startTime; | 0 | ||||||||||||
84 | } | - | ||||||||||||
85 | - | |||||||||||||
86 | void QStyleAnimation::setStartTime(const QTime &time) | - | ||||||||||||
87 | { | - | ||||||||||||
88 | _startTime = time; | - | ||||||||||||
89 | } never executed: end of block | 0 | ||||||||||||
90 | - | |||||||||||||
91 | QStyleAnimation::FrameRate QStyleAnimation::frameRate() const | - | ||||||||||||
92 | { | - | ||||||||||||
93 | return _fps; never executed: return _fps; | 0 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | void QStyleAnimation::setFrameRate(FrameRate fps) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | _fps = fps; | - | ||||||||||||
99 | } never executed: end of block | 0 | ||||||||||||
100 | - | |||||||||||||
101 | void QStyleAnimation::updateTarget() | - | ||||||||||||
102 | { | - | ||||||||||||
103 | QEvent event(QEvent::StyleAnimationUpdate); | - | ||||||||||||
104 | event.setAccepted(false); | - | ||||||||||||
105 | QCoreApplication::sendEvent(target(), &event); | - | ||||||||||||
106 | if (!event.isAccepted())
| 0 | ||||||||||||
107 | stop(); never executed: stop(); | 0 | ||||||||||||
108 | } never executed: end of block | 0 | ||||||||||||
109 | - | |||||||||||||
110 | void QStyleAnimation::start() | - | ||||||||||||
111 | { | - | ||||||||||||
112 | _skip = 0; | - | ||||||||||||
113 | QAbstractAnimation::start(DeleteWhenStopped); | - | ||||||||||||
114 | } never executed: end of block | 0 | ||||||||||||
115 | - | |||||||||||||
116 | bool QStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | return currentTime() > _delay; never executed: return currentTime() > _delay; | 0 | ||||||||||||
119 | } | - | ||||||||||||
120 | - | |||||||||||||
121 | void QStyleAnimation::updateCurrentTime(int) | - | ||||||||||||
122 | { | - | ||||||||||||
123 | if (++_skip >= _fps) {
| 0 | ||||||||||||
124 | _skip = 0; | - | ||||||||||||
125 | if (target() && isUpdateNeeded())
| 0 | ||||||||||||
126 | updateTarget(); never executed: updateTarget(); | 0 | ||||||||||||
127 | } never executed: end of block | 0 | ||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||
129 | - | |||||||||||||
130 | QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : | - | ||||||||||||
131 | QStyleAnimation(target), _speed(speed), _step(-1) | - | ||||||||||||
132 | { | - | ||||||||||||
133 | } never executed: end of block | 0 | ||||||||||||
134 | - | |||||||||||||
135 | int QProgressStyleAnimation::animationStep() const | - | ||||||||||||
136 | { | - | ||||||||||||
137 | return currentTime() / (1000.0 / _speed); never executed: return currentTime() / (1000.0 / _speed); | 0 | ||||||||||||
138 | } | - | ||||||||||||
139 | - | |||||||||||||
140 | int QProgressStyleAnimation::progressStep(int width) const | - | ||||||||||||
141 | { | - | ||||||||||||
142 | int step = animationStep(); | - | ||||||||||||
143 | int progress = (step * width / _speed) % width; | - | ||||||||||||
144 | if (((step * width / _speed) % (2 * width)) >= width)
| 0 | ||||||||||||
145 | progress = width - progress; never executed: progress = width - progress; | 0 | ||||||||||||
146 | return progress; never executed: return progress; | 0 | ||||||||||||
147 | } | - | ||||||||||||
148 | - | |||||||||||||
149 | int QProgressStyleAnimation::speed() const | - | ||||||||||||
150 | { | - | ||||||||||||
151 | return _speed; never executed: return _speed; | 0 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | void QProgressStyleAnimation::setSpeed(int speed) | - | ||||||||||||
155 | { | - | ||||||||||||
156 | _speed = speed; | - | ||||||||||||
157 | } never executed: end of block | 0 | ||||||||||||
158 | - | |||||||||||||
159 | bool QProgressStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
160 | { | - | ||||||||||||
161 | if (QStyleAnimation::isUpdateNeeded()) {
| 0 | ||||||||||||
162 | int current = animationStep(); | - | ||||||||||||
163 | if (_step == -1 || _step != current)
| 0 | ||||||||||||
164 | { | - | ||||||||||||
165 | _step = current; | - | ||||||||||||
166 | return true; never executed: return true; | 0 | ||||||||||||
167 | } | - | ||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||
169 | return false; never executed: return false; | 0 | ||||||||||||
170 | } | - | ||||||||||||
171 | - | |||||||||||||
172 | QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : | - | ||||||||||||
173 | QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | setDuration(250); | - | ||||||||||||
176 | } never executed: end of block | 0 | ||||||||||||
177 | - | |||||||||||||
178 | qreal QNumberStyleAnimation::startValue() const | - | ||||||||||||
179 | { | - | ||||||||||||
180 | return _start; never executed: return _start; | 0 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | void QNumberStyleAnimation::setStartValue(qreal value) | - | ||||||||||||
184 | { | - | ||||||||||||
185 | _start = value; | - | ||||||||||||
186 | } never executed: end of block | 0 | ||||||||||||
187 | - | |||||||||||||
188 | qreal QNumberStyleAnimation::endValue() const | - | ||||||||||||
189 | { | - | ||||||||||||
190 | return _end; never executed: return _end; | 0 | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | void QNumberStyleAnimation::setEndValue(qreal value) | - | ||||||||||||
194 | { | - | ||||||||||||
195 | _end = value; | - | ||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||
197 | - | |||||||||||||
198 | qreal QNumberStyleAnimation::currentValue() const | - | ||||||||||||
199 | { | - | ||||||||||||
200 | qreal step = qreal(currentTime() - delay()) / (duration() - delay()); | - | ||||||||||||
201 | return _start + qMax(qreal(0), step) * (_end - _start); never executed: return _start + qMax(qreal(0), step) * (_end - _start); | 0 | ||||||||||||
202 | } | - | ||||||||||||
203 | - | |||||||||||||
204 | bool QNumberStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
205 | { | - | ||||||||||||
206 | if (QStyleAnimation::isUpdateNeeded()) {
| 0 | ||||||||||||
207 | qreal current = currentValue(); | - | ||||||||||||
208 | if (!qFuzzyCompare(_prev, current))
| 0 | ||||||||||||
209 | { | - | ||||||||||||
210 | _prev = current; | - | ||||||||||||
211 | return true; never executed: return true; | 0 | ||||||||||||
212 | } | - | ||||||||||||
213 | } never executed: end of block | 0 | ||||||||||||
214 | return false; never executed: return false; | 0 | ||||||||||||
215 | } | - | ||||||||||||
216 | - | |||||||||||||
217 | QBlendStyleAnimation::QBlendStyleAnimation(Type type, QObject *target) : | - | ||||||||||||
218 | QStyleAnimation(target), _type(type) | - | ||||||||||||
219 | { | - | ||||||||||||
220 | setDuration(250); | - | ||||||||||||
221 | } never executed: end of block | 0 | ||||||||||||
222 | - | |||||||||||||
223 | QImage QBlendStyleAnimation::startImage() const | - | ||||||||||||
224 | { | - | ||||||||||||
225 | return _start; never executed: return _start; | 0 | ||||||||||||
226 | } | - | ||||||||||||
227 | - | |||||||||||||
228 | void QBlendStyleAnimation::setStartImage(const QImage& image) | - | ||||||||||||
229 | { | - | ||||||||||||
230 | _start = image; | - | ||||||||||||
231 | } never executed: end of block | 0 | ||||||||||||
232 | - | |||||||||||||
233 | QImage QBlendStyleAnimation::endImage() const | - | ||||||||||||
234 | { | - | ||||||||||||
235 | return _end; never executed: return _end; | 0 | ||||||||||||
236 | } | - | ||||||||||||
237 | - | |||||||||||||
238 | void QBlendStyleAnimation::setEndImage(const QImage& image) | - | ||||||||||||
239 | { | - | ||||||||||||
240 | _end = image; | - | ||||||||||||
241 | } never executed: end of block | 0 | ||||||||||||
242 | - | |||||||||||||
243 | QImage QBlendStyleAnimation::currentImage() const | - | ||||||||||||
244 | { | - | ||||||||||||
245 | return _current; never executed: return _current; | 0 | ||||||||||||
246 | } | - | ||||||||||||
247 | - | |||||||||||||
248 | /*! \internal | - | ||||||||||||
249 | - | |||||||||||||
250 | A helper function to blend two images. | - | ||||||||||||
251 | - | |||||||||||||
252 | The result consists of ((alpha)*startImage) + ((1-alpha)*endImage) | - | ||||||||||||
253 | - | |||||||||||||
254 | */ | - | ||||||||||||
255 | static QImage blendedImage(const QImage &start, const QImage &end, float alpha) | - | ||||||||||||
256 | { | - | ||||||||||||
257 | if (start.isNull() || end.isNull())
| 0 | ||||||||||||
258 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||
259 | - | |||||||||||||
260 | QImage blended; | - | ||||||||||||
261 | const int a = qRound(alpha*256); | - | ||||||||||||
262 | const int ia = 256 - a; | - | ||||||||||||
263 | const int sw = start.width(); | - | ||||||||||||
264 | const int sh = start.height(); | - | ||||||||||||
265 | const int bpl = start.bytesPerLine(); | - | ||||||||||||
266 | switch (start.depth()) { | - | ||||||||||||
267 | case 32: never executed: case 32: | 0 | ||||||||||||
268 | { | - | ||||||||||||
269 | blended = QImage(sw, sh, start.format()); | - | ||||||||||||
270 | blended.setDevicePixelRatio(start.devicePixelRatio()); | - | ||||||||||||
271 | uchar *mixed_data = blended.bits(); | - | ||||||||||||
272 | const uchar *back_data = start.bits(); | - | ||||||||||||
273 | const uchar *front_data = end.bits(); | - | ||||||||||||
274 | for (int sy = 0; sy < sh; sy++) {
| 0 | ||||||||||||
275 | quint32* mixed = (quint32*)mixed_data; | - | ||||||||||||
276 | const quint32* back = (const quint32*)back_data; | - | ||||||||||||
277 | const quint32* front = (const quint32*)front_data; | - | ||||||||||||
278 | for (int sx = 0; sx < sw; sx++) {
| 0 | ||||||||||||
279 | quint32 bp = back[sx]; | - | ||||||||||||
280 | quint32 fp = front[sx]; | - | ||||||||||||
281 | mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8, | - | ||||||||||||
282 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - | ||||||||||||
283 | (qBlue(bp)*ia + qBlue(fp)*a)>>8, | - | ||||||||||||
284 | (qAlpha(bp)*ia + qAlpha(fp)*a)>>8); | - | ||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||
286 | mixed_data += bpl; | - | ||||||||||||
287 | back_data += bpl; | - | ||||||||||||
288 | front_data += bpl; | - | ||||||||||||
289 | } never executed: end of block | 0 | ||||||||||||
290 | } | - | ||||||||||||
291 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||
292 | break; never executed: break; | 0 | ||||||||||||
293 | } | - | ||||||||||||
294 | return blended; never executed: return blended; | 0 | ||||||||||||
295 | } | - | ||||||||||||
296 | - | |||||||||||||
297 | void QBlendStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
298 | { | - | ||||||||||||
299 | QStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
300 | - | |||||||||||||
301 | float alpha = 1.0; | - | ||||||||||||
302 | if (duration() > 0) {
| 0 | ||||||||||||
303 | if (_type == Pulse) {
| 0 | ||||||||||||
304 | time = time % duration() * 2; | - | ||||||||||||
305 | if (time > duration())
| 0 | ||||||||||||
306 | time = duration() * 2 - time; never executed: time = duration() * 2 - time; | 0 | ||||||||||||
307 | } never executed: end of block | 0 | ||||||||||||
308 | - | |||||||||||||
309 | alpha = time / static_cast<float>(duration()); | - | ||||||||||||
310 | - | |||||||||||||
311 | if (_type == Transition && time > duration()) {
| 0 | ||||||||||||
312 | alpha = 1.0; | - | ||||||||||||
313 | stop(); | - | ||||||||||||
314 | } never executed: end of block | 0 | ||||||||||||
315 | } else if (time > 0) { never executed: end of block
| 0 | ||||||||||||
316 | stop(); | - | ||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||
318 | - | |||||||||||||
319 | _current = blendedImage(_start, _end, alpha); | - | ||||||||||||
320 | } never executed: end of block | 0 | ||||||||||||
321 | - | |||||||||||||
322 | QScrollbarStyleAnimation::QScrollbarStyleAnimation(Mode mode, QObject *target) : QNumberStyleAnimation(target), _mode(mode), _active(false) | - | ||||||||||||
323 | { | - | ||||||||||||
324 | switch (mode) { | - | ||||||||||||
325 | case Activating: never executed: case Activating: | 0 | ||||||||||||
326 | setDuration(ScrollBarFadeOutDuration); | - | ||||||||||||
327 | setStartValue(0.0); | - | ||||||||||||
328 | setEndValue(1.0); | - | ||||||||||||
329 | break; never executed: break; | 0 | ||||||||||||
330 | case Deactivating: never executed: case Deactivating: | 0 | ||||||||||||
331 | setDuration(ScrollBarFadeOutDelay + ScrollBarFadeOutDuration); | - | ||||||||||||
332 | setDelay(ScrollBarFadeOutDelay); | - | ||||||||||||
333 | setStartValue(1.0); | - | ||||||||||||
334 | setEndValue(0.0); | - | ||||||||||||
335 | break; never executed: break; | 0 | ||||||||||||
336 | } | - | ||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||
338 | - | |||||||||||||
339 | QScrollbarStyleAnimation::Mode QScrollbarStyleAnimation::mode() const | - | ||||||||||||
340 | { | - | ||||||||||||
341 | return _mode; never executed: return _mode; | 0 | ||||||||||||
342 | } | - | ||||||||||||
343 | - | |||||||||||||
344 | bool QScrollbarStyleAnimation::wasActive() const | - | ||||||||||||
345 | { | - | ||||||||||||
346 | return _active; never executed: return _active; | 0 | ||||||||||||
347 | } | - | ||||||||||||
348 | - | |||||||||||||
349 | void QScrollbarStyleAnimation::setActive(bool active) | - | ||||||||||||
350 | { | - | ||||||||||||
351 | _active = active; | - | ||||||||||||
352 | } never executed: end of block | 0 | ||||||||||||
353 | - | |||||||||||||
354 | void QScrollbarStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
355 | { | - | ||||||||||||
356 | QNumberStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
357 | if (_mode == Deactivating && qFuzzyIsNull(currentValue()))
| 0 | ||||||||||||
358 | target()->setProperty("visible", false); never executed: target()->setProperty("visible", false); | 0 | ||||||||||||
359 | } never executed: end of block | 0 | ||||||||||||
360 | - | |||||||||||||
361 | QT_END_NAMESPACE | - | ||||||||||||
362 | - | |||||||||||||
363 | #include "moc_qstyleanimation_p.cpp" | - | ||||||||||||
364 | - | |||||||||||||
365 | #endif //QT_NO_ANIMATION | - | ||||||||||||
Source code | Switch to Preprocessed file |