Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qeffects.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 "qapplication.h" | - | ||||||||||||
35 | #ifndef QT_NO_EFFECTS | - | ||||||||||||
36 | #include "qdesktopwidget.h" | - | ||||||||||||
37 | #include "qeffects_p.h" | - | ||||||||||||
38 | #include "qevent.h" | - | ||||||||||||
39 | #include "qimage.h" | - | ||||||||||||
40 | #include "qpainter.h" | - | ||||||||||||
41 | #include "qscreen.h" | - | ||||||||||||
42 | #include "qpixmap.h" | - | ||||||||||||
43 | #include "qpointer.h" | - | ||||||||||||
44 | #include "qtimer.h" | - | ||||||||||||
45 | #include "qelapsedtimer.h" | - | ||||||||||||
46 | #include "qdebug.h" | - | ||||||||||||
47 | - | |||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||
49 | - | |||||||||||||
50 | /* | - | ||||||||||||
51 | Internal class QAlphaWidget. | - | ||||||||||||
52 | - | |||||||||||||
53 | The QAlphaWidget is shown while the animation lasts | - | ||||||||||||
54 | and displays the pixmap resulting from the alpha blending. | - | ||||||||||||
55 | */ | - | ||||||||||||
56 | - | |||||||||||||
57 | class QAlphaWidget: public QWidget, private QEffects | - | ||||||||||||
58 | { | - | ||||||||||||
59 | Q_OBJECT | - | ||||||||||||
60 | public: | - | ||||||||||||
61 | QAlphaWidget(QWidget* w, Qt::WindowFlags f = 0); | - | ||||||||||||
62 | ~QAlphaWidget(); | - | ||||||||||||
63 | - | |||||||||||||
64 | void run(int time); | - | ||||||||||||
65 | - | |||||||||||||
66 | protected: | - | ||||||||||||
67 | void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE; | - | ||||||||||||
68 | void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
69 | void alphaBlend(); | - | ||||||||||||
70 | bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; | - | ||||||||||||
71 | - | |||||||||||||
72 | protected slots: | - | ||||||||||||
73 | void render(); | - | ||||||||||||
74 | - | |||||||||||||
75 | private: | - | ||||||||||||
76 | QPixmap pm; | - | ||||||||||||
77 | double alpha; | - | ||||||||||||
78 | QImage backImage; | - | ||||||||||||
79 | QImage frontImage; | - | ||||||||||||
80 | QImage mixedImage; | - | ||||||||||||
81 | QPointer<QWidget> widget; | - | ||||||||||||
82 | int duration; | - | ||||||||||||
83 | int elapsed; | - | ||||||||||||
84 | bool showWidget; | - | ||||||||||||
85 | QTimer anim; | - | ||||||||||||
86 | QElapsedTimer checkTime; | - | ||||||||||||
87 | }; | - | ||||||||||||
88 | - | |||||||||||||
89 | static QAlphaWidget* q_blend = 0; | - | ||||||||||||
90 | - | |||||||||||||
91 | /* | - | ||||||||||||
92 | Constructs a QAlphaWidget. | - | ||||||||||||
93 | */ | - | ||||||||||||
94 | QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) | - | ||||||||||||
95 | : QWidget(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(w)), f) | - | ||||||||||||
96 | { | - | ||||||||||||
97 | #ifndef Q_OS_WIN | - | ||||||||||||
98 | setEnabled(false); | - | ||||||||||||
99 | #endif | - | ||||||||||||
100 | setAttribute(Qt::WA_NoSystemBackground, true); | - | ||||||||||||
101 | widget = w; | - | ||||||||||||
102 | alpha = 0; | - | ||||||||||||
103 | } never executed: end of block | 0 | ||||||||||||
104 | - | |||||||||||||
105 | QAlphaWidget::~QAlphaWidget() | - | ||||||||||||
106 | { | - | ||||||||||||
107 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
108 | // Restore user-defined opacity value | - | ||||||||||||
109 | if (widget) | - | ||||||||||||
110 | widget->setWindowOpacity(1); | - | ||||||||||||
111 | #endif | - | ||||||||||||
112 | } | - | ||||||||||||
113 | - | |||||||||||||
114 | /* | - | ||||||||||||
115 | \reimp | - | ||||||||||||
116 | */ | - | ||||||||||||
117 | void QAlphaWidget::paintEvent(QPaintEvent*) | - | ||||||||||||
118 | { | - | ||||||||||||
119 | QPainter p(this); | - | ||||||||||||
120 | p.drawPixmap(0, 0, pm); | - | ||||||||||||
121 | } never executed: end of block | 0 | ||||||||||||
122 | - | |||||||||||||
123 | /* | - | ||||||||||||
124 | Starts the alphablending animation. | - | ||||||||||||
125 | The animation will take about \a time ms | - | ||||||||||||
126 | */ | - | ||||||||||||
127 | void QAlphaWidget::run(int time) | - | ||||||||||||
128 | { | - | ||||||||||||
129 | duration = time; | - | ||||||||||||
130 | - | |||||||||||||
131 | if (duration < 0)
| 0 | ||||||||||||
132 | duration = 150; never executed: duration = 150; | 0 | ||||||||||||
133 | - | |||||||||||||
134 | if (!widget)
| 0 | ||||||||||||
135 | return; never executed: return; | 0 | ||||||||||||
136 | - | |||||||||||||
137 | elapsed = 0; | - | ||||||||||||
138 | checkTime.start(); | - | ||||||||||||
139 | - | |||||||||||||
140 | showWidget = true; | - | ||||||||||||
141 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
142 | qApp->installEventFilter(this); | - | ||||||||||||
143 | widget->setWindowOpacity(0.0); | - | ||||||||||||
144 | widget->show(); | - | ||||||||||||
145 | connect(&anim, SIGNAL(timeout()), this, SLOT(render())); | - | ||||||||||||
146 | anim.start(1); | - | ||||||||||||
147 | #else | - | ||||||||||||
148 | //This is roughly equivalent to calling setVisible(true) without actually showing the widget | - | ||||||||||||
149 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - | ||||||||||||
150 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - | ||||||||||||
151 | - | |||||||||||||
152 | qApp->installEventFilter(this); | - | ||||||||||||
153 | - | |||||||||||||
154 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
155 | resize(widget->size().width(), widget->size().height()); | - | ||||||||||||
156 | - | |||||||||||||
157 | frontImage = widget->grab().toImage(); | - | ||||||||||||
158 | backImage = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(), | - | ||||||||||||
159 | widget->geometry().x(), widget->geometry().y(), | - | ||||||||||||
160 | widget->geometry().width(), widget->geometry().height()).toImage(); | - | ||||||||||||
161 | - | |||||||||||||
162 | if (!backImage.isNull() && checkTime.elapsed() < duration / 2) {
| 0 | ||||||||||||
163 | mixedImage = backImage.copy(); | - | ||||||||||||
164 | pm = QPixmap::fromImage(mixedImage); | - | ||||||||||||
165 | show(); | - | ||||||||||||
166 | setEnabled(false); | - | ||||||||||||
167 | - | |||||||||||||
168 | connect(&anim, SIGNAL(timeout()), this, SLOT(render())); | - | ||||||||||||
169 | anim.start(1); | - | ||||||||||||
170 | } else { never executed: end of block | 0 | ||||||||||||
171 | duration = 0; | - | ||||||||||||
172 | render(); | - | ||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||
174 | #endif | - | ||||||||||||
175 | } | - | ||||||||||||
176 | - | |||||||||||||
177 | /* | - | ||||||||||||
178 | \reimp | - | ||||||||||||
179 | */ | - | ||||||||||||
180 | bool QAlphaWidget::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||
181 | { | - | ||||||||||||
182 | switch (e->type()) { | - | ||||||||||||
183 | case QEvent::Move: never executed: case QEvent::Move: | 0 | ||||||||||||
184 | if (o != widget)
| 0 | ||||||||||||
185 | break; never executed: break; | 0 | ||||||||||||
186 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
187 | update(); | - | ||||||||||||
188 | break; never executed: break; | 0 | ||||||||||||
189 | case QEvent::Hide: never executed: case QEvent::Hide: | 0 | ||||||||||||
190 | case QEvent::Close: never executed: case QEvent::Close: | 0 | ||||||||||||
191 | if (o != widget)
| 0 | ||||||||||||
192 | break; never executed: break; | 0 | ||||||||||||
193 | case QEvent::MouseButtonPress: code before this statement never executed: case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||
194 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||
195 | showWidget = false; | - | ||||||||||||
196 | render(); | - | ||||||||||||
197 | break; never executed: break; | 0 | ||||||||||||
198 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||
199 | QKeyEvent *ke = (QKeyEvent*)e; | - | ||||||||||||
200 | if (ke->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||
201 | showWidget = false; | - | ||||||||||||
202 | } else { never executed: end of block | 0 | ||||||||||||
203 | duration = 0; | - | ||||||||||||
204 | } never executed: end of block | 0 | ||||||||||||
205 | render(); | - | ||||||||||||
206 | break; never executed: break; | 0 | ||||||||||||
207 | } | - | ||||||||||||
208 | default: never executed: default: | 0 | ||||||||||||
209 | break; never executed: break; | 0 | ||||||||||||
210 | } | - | ||||||||||||
211 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 | ||||||||||||
212 | } | - | ||||||||||||
213 | - | |||||||||||||
214 | /* | - | ||||||||||||
215 | \reimp | - | ||||||||||||
216 | */ | - | ||||||||||||
217 | void QAlphaWidget::closeEvent(QCloseEvent *e) | - | ||||||||||||
218 | { | - | ||||||||||||
219 | e->accept(); | - | ||||||||||||
220 | if (!q_blend)
| 0 | ||||||||||||
221 | return; never executed: return; | 0 | ||||||||||||
222 | - | |||||||||||||
223 | showWidget = false; | - | ||||||||||||
224 | render(); | - | ||||||||||||
225 | - | |||||||||||||
226 | QWidget::closeEvent(e); | - | ||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||
228 | - | |||||||||||||
229 | /* | - | ||||||||||||
230 | Render alphablending for the time elapsed. | - | ||||||||||||
231 | - | |||||||||||||
232 | Show the blended widget and free all allocated source | - | ||||||||||||
233 | if the blending is finished. | - | ||||||||||||
234 | */ | - | ||||||||||||
235 | void QAlphaWidget::render() | - | ||||||||||||
236 | { | - | ||||||||||||
237 | int tempel = checkTime.elapsed(); | - | ||||||||||||
238 | if (elapsed >= tempel)
| 0 | ||||||||||||
239 | elapsed++; never executed: elapsed++; | 0 | ||||||||||||
240 | else | - | ||||||||||||
241 | elapsed = tempel; never executed: elapsed = tempel; | 0 | ||||||||||||
242 | - | |||||||||||||
243 | if (duration != 0)
| 0 | ||||||||||||
244 | alpha = tempel / double(duration); never executed: alpha = tempel / double(duration); | 0 | ||||||||||||
245 | else | - | ||||||||||||
246 | alpha = 1; never executed: alpha = 1; | 0 | ||||||||||||
247 | - | |||||||||||||
248 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
249 | if (alpha >= 1 || !showWidget) { | - | ||||||||||||
250 | anim.stop(); | - | ||||||||||||
251 | qApp->removeEventFilter(this); | - | ||||||||||||
252 | widget->setWindowOpacity(1); | - | ||||||||||||
253 | q_blend = 0; | - | ||||||||||||
254 | deleteLater(); | - | ||||||||||||
255 | } else { | - | ||||||||||||
256 | widget->setWindowOpacity(alpha); | - | ||||||||||||
257 | } | - | ||||||||||||
258 | #else | - | ||||||||||||
259 | if (alpha >= 1 || !showWidget) {
| 0 | ||||||||||||
260 | anim.stop(); | - | ||||||||||||
261 | qApp->removeEventFilter(this); | - | ||||||||||||
262 | - | |||||||||||||
263 | if (widget) {
| 0 | ||||||||||||
264 | if (!showWidget) {
| 0 | ||||||||||||
265 | #ifdef Q_OS_WIN | - | ||||||||||||
266 | setEnabled(true); | - | ||||||||||||
267 | setFocus(); | - | ||||||||||||
268 | #endif // Q_OS_WIN | - | ||||||||||||
269 | widget->hide(); | - | ||||||||||||
270 | } else { never executed: end of block | 0 | ||||||||||||
271 | //Since we are faking the visibility of the widget | - | ||||||||||||
272 | //we need to unset the hidden state on it before calling show | - | ||||||||||||
273 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - | ||||||||||||
274 | widget->show(); | - | ||||||||||||
275 | lower(); | - | ||||||||||||
276 | } never executed: end of block | 0 | ||||||||||||
277 | } | - | ||||||||||||
278 | q_blend = 0; | - | ||||||||||||
279 | deleteLater(); | - | ||||||||||||
280 | } else { never executed: end of block | 0 | ||||||||||||
281 | alphaBlend(); | - | ||||||||||||
282 | pm = QPixmap::fromImage(mixedImage); | - | ||||||||||||
283 | repaint(); | - | ||||||||||||
284 | } never executed: end of block | 0 | ||||||||||||
285 | #endif // defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
286 | } | - | ||||||||||||
287 | - | |||||||||||||
288 | /* | - | ||||||||||||
289 | Calculate an alphablended image. | - | ||||||||||||
290 | */ | - | ||||||||||||
291 | void QAlphaWidget::alphaBlend() | - | ||||||||||||
292 | { | - | ||||||||||||
293 | const int a = qRound(alpha*256); | - | ||||||||||||
294 | const int ia = 256 - a; | - | ||||||||||||
295 | - | |||||||||||||
296 | const int sw = frontImage.width(); | - | ||||||||||||
297 | const int sh = frontImage.height(); | - | ||||||||||||
298 | const int bpl = frontImage.bytesPerLine(); | - | ||||||||||||
299 | switch(frontImage.depth()) { | - | ||||||||||||
300 | case 32: never executed: case 32: | 0 | ||||||||||||
301 | { | - | ||||||||||||
302 | uchar *mixed_data = mixedImage.bits(); | - | ||||||||||||
303 | const uchar *back_data = backImage.bits(); | - | ||||||||||||
304 | const uchar *front_data = frontImage.bits(); | - | ||||||||||||
305 | - | |||||||||||||
306 | for (int sy = 0; sy < sh; sy++) {
| 0 | ||||||||||||
307 | quint32* mixed = (quint32*)mixed_data; | - | ||||||||||||
308 | const quint32* back = (const quint32*)back_data; | - | ||||||||||||
309 | const quint32* front = (const quint32*)front_data; | - | ||||||||||||
310 | for (int sx = 0; sx < sw; sx++) {
| 0 | ||||||||||||
311 | quint32 bp = back[sx]; | - | ||||||||||||
312 | quint32 fp = front[sx]; | - | ||||||||||||
313 | - | |||||||||||||
314 | mixed[sx] = qRgb((qRed(bp)*ia + qRed(fp)*a)>>8, | - | ||||||||||||
315 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - | ||||||||||||
316 | (qBlue(bp)*ia + qBlue(fp)*a)>>8); | - | ||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||
318 | mixed_data += bpl; | - | ||||||||||||
319 | back_data += bpl; | - | ||||||||||||
320 | front_data += bpl; | - | ||||||||||||
321 | } never executed: end of block | 0 | ||||||||||||
322 | } | - | ||||||||||||
323 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||
324 | break; never executed: break; | 0 | ||||||||||||
325 | } | - | ||||||||||||
326 | } | - | ||||||||||||
327 | - | |||||||||||||
328 | /* | - | ||||||||||||
329 | Internal class QRollEffect | - | ||||||||||||
330 | - | |||||||||||||
331 | The QRollEffect widget is shown while the animation lasts | - | ||||||||||||
332 | and displays a scrolling pixmap. | - | ||||||||||||
333 | */ | - | ||||||||||||
334 | - | |||||||||||||
335 | class QRollEffect : public QWidget, private QEffects | - | ||||||||||||
336 | { | - | ||||||||||||
337 | Q_OBJECT | - | ||||||||||||
338 | public: | - | ||||||||||||
339 | QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient); | - | ||||||||||||
340 | - | |||||||||||||
341 | void run(int time); | - | ||||||||||||
342 | - | |||||||||||||
343 | protected: | - | ||||||||||||
344 | void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
345 | void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
346 | - | |||||||||||||
347 | private slots: | - | ||||||||||||
348 | void scroll(); | - | ||||||||||||
349 | - | |||||||||||||
350 | private: | - | ||||||||||||
351 | QPointer<QWidget> widget; | - | ||||||||||||
352 | - | |||||||||||||
353 | int currentHeight; | - | ||||||||||||
354 | int currentWidth; | - | ||||||||||||
355 | int totalHeight; | - | ||||||||||||
356 | int totalWidth; | - | ||||||||||||
357 | - | |||||||||||||
358 | int duration; | - | ||||||||||||
359 | int elapsed; | - | ||||||||||||
360 | bool done; | - | ||||||||||||
361 | bool showWidget; | - | ||||||||||||
362 | int orientation; | - | ||||||||||||
363 | - | |||||||||||||
364 | QTimer anim; | - | ||||||||||||
365 | QElapsedTimer checkTime; | - | ||||||||||||
366 | - | |||||||||||||
367 | QPixmap pm; | - | ||||||||||||
368 | }; | - | ||||||||||||
369 | - | |||||||||||||
370 | static QRollEffect* q_roll = 0; | - | ||||||||||||
371 | - | |||||||||||||
372 | /* | - | ||||||||||||
373 | Construct a QRollEffect widget. | - | ||||||||||||
374 | */ | - | ||||||||||||
375 | QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient) | - | ||||||||||||
376 | : QWidget(0, f), orientation(orient) | - | ||||||||||||
377 | { | - | ||||||||||||
378 | #ifndef Q_OS_WIN | - | ||||||||||||
379 | setEnabled(false); | - | ||||||||||||
380 | #endif | - | ||||||||||||
381 | - | |||||||||||||
382 | widget = w; | - | ||||||||||||
383 | Q_ASSERT(widget); | - | ||||||||||||
384 | - | |||||||||||||
385 | setAttribute(Qt::WA_NoSystemBackground, true); | - | ||||||||||||
386 | - | |||||||||||||
387 | if (widget->testAttribute(Qt::WA_Resized)) {
| 0 | ||||||||||||
388 | totalWidth = widget->width(); | - | ||||||||||||
389 | totalHeight = widget->height(); | - | ||||||||||||
390 | } else { never executed: end of block | 0 | ||||||||||||
391 | totalWidth = widget->sizeHint().width(); | - | ||||||||||||
392 | totalHeight = widget->sizeHint().height(); | - | ||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||
394 | - | |||||||||||||
395 | currentHeight = totalHeight; | - | ||||||||||||
396 | currentWidth = totalWidth; | - | ||||||||||||
397 | - | |||||||||||||
398 | if (orientation & (RightScroll|LeftScroll))
| 0 | ||||||||||||
399 | currentWidth = 0; never executed: currentWidth = 0; | 0 | ||||||||||||
400 | if (orientation & (DownScroll|UpScroll))
| 0 | ||||||||||||
401 | currentHeight = 0; never executed: currentHeight = 0; | 0 | ||||||||||||
402 | - | |||||||||||||
403 | pm = widget->grab(); | - | ||||||||||||
404 | } never executed: end of block | 0 | ||||||||||||
405 | - | |||||||||||||
406 | /* | - | ||||||||||||
407 | \reimp | - | ||||||||||||
408 | */ | - | ||||||||||||
409 | void QRollEffect::paintEvent(QPaintEvent*) | - | ||||||||||||
410 | { | - | ||||||||||||
411 | int x = orientation & RightScroll ? qMin(0, currentWidth - totalWidth) : 0;
| 0 | ||||||||||||
412 | int y = orientation & DownScroll ? qMin(0, currentHeight - totalHeight) : 0;
| 0 | ||||||||||||
413 | - | |||||||||||||
414 | QPainter p(this); | - | ||||||||||||
415 | p.drawPixmap(x, y, pm); | - | ||||||||||||
416 | } never executed: end of block | 0 | ||||||||||||
417 | - | |||||||||||||
418 | /* | - | ||||||||||||
419 | \reimp | - | ||||||||||||
420 | */ | - | ||||||||||||
421 | void QRollEffect::closeEvent(QCloseEvent *e) | - | ||||||||||||
422 | { | - | ||||||||||||
423 | e->accept(); | - | ||||||||||||
424 | if (done)
| 0 | ||||||||||||
425 | return; never executed: return; | 0 | ||||||||||||
426 | - | |||||||||||||
427 | showWidget = false; | - | ||||||||||||
428 | done = true; | - | ||||||||||||
429 | scroll(); | - | ||||||||||||
430 | - | |||||||||||||
431 | QWidget::closeEvent(e); | - | ||||||||||||
432 | } never executed: end of block | 0 | ||||||||||||
433 | - | |||||||||||||
434 | /* | - | ||||||||||||
435 | Start the animation. | - | ||||||||||||
436 | - | |||||||||||||
437 | The animation will take about \a time ms, or is | - | ||||||||||||
438 | calculated if \a time is negative | - | ||||||||||||
439 | */ | - | ||||||||||||
440 | void QRollEffect::run(int time) | - | ||||||||||||
441 | { | - | ||||||||||||
442 | if (!widget)
| 0 | ||||||||||||
443 | return; never executed: return; | 0 | ||||||||||||
444 | - | |||||||||||||
445 | duration = time; | - | ||||||||||||
446 | elapsed = 0; | - | ||||||||||||
447 | - | |||||||||||||
448 | if (duration < 0) {
| 0 | ||||||||||||
449 | int dist = 0; | - | ||||||||||||
450 | if (orientation & (RightScroll|LeftScroll))
| 0 | ||||||||||||
451 | dist += totalWidth - currentWidth; never executed: dist += totalWidth - currentWidth; | 0 | ||||||||||||
452 | if (orientation & (DownScroll|UpScroll))
| 0 | ||||||||||||
453 | dist += totalHeight - currentHeight; never executed: dist += totalHeight - currentHeight; | 0 | ||||||||||||
454 | duration = qMin(qMax(dist/3, 50), 120); | - | ||||||||||||
455 | } never executed: end of block | 0 | ||||||||||||
456 | - | |||||||||||||
457 | connect(&anim, SIGNAL(timeout()), this, SLOT(scroll())); | - | ||||||||||||
458 | - | |||||||||||||
459 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
460 | resize(qMin(currentWidth, totalWidth), qMin(currentHeight, totalHeight)); | - | ||||||||||||
461 | - | |||||||||||||
462 | //This is roughly equivalent to calling setVisible(true) without actually showing the widget | - | ||||||||||||
463 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - | ||||||||||||
464 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - | ||||||||||||
465 | - | |||||||||||||
466 | show(); | - | ||||||||||||
467 | setEnabled(false); | - | ||||||||||||
468 | - | |||||||||||||
469 | showWidget = true; | - | ||||||||||||
470 | done = false; | - | ||||||||||||
471 | anim.start(1); | - | ||||||||||||
472 | checkTime.start(); | - | ||||||||||||
473 | } never executed: end of block | 0 | ||||||||||||
474 | - | |||||||||||||
475 | /* | - | ||||||||||||
476 | Roll according to the time elapsed. | - | ||||||||||||
477 | */ | - | ||||||||||||
478 | void QRollEffect::scroll() | - | ||||||||||||
479 | { | - | ||||||||||||
480 | if (!done && widget) {
| 0 | ||||||||||||
481 | int tempel = checkTime.elapsed(); | - | ||||||||||||
482 | if (elapsed >= tempel)
| 0 | ||||||||||||
483 | elapsed++; never executed: elapsed++; | 0 | ||||||||||||
484 | else | - | ||||||||||||
485 | elapsed = tempel; never executed: elapsed = tempel; | 0 | ||||||||||||
486 | - | |||||||||||||
487 | if (currentWidth != totalWidth) {
| 0 | ||||||||||||
488 | currentWidth = totalWidth * (elapsed/duration) | - | ||||||||||||
489 | + (2 * totalWidth * (elapsed%duration) + duration) | - | ||||||||||||
490 | / (2 * duration); | - | ||||||||||||
491 | // equiv. to int((totalWidth*elapsed) / duration + 0.5) | - | ||||||||||||
492 | done = (currentWidth >= totalWidth); | - | ||||||||||||
493 | } never executed: end of block | 0 | ||||||||||||
494 | if (currentHeight != totalHeight) {
| 0 | ||||||||||||
495 | currentHeight = totalHeight * (elapsed/duration) | - | ||||||||||||
496 | + (2 * totalHeight * (elapsed%duration) + duration) | - | ||||||||||||
497 | / (2 * duration); | - | ||||||||||||
498 | // equiv. to int((totalHeight*elapsed) / duration + 0.5) | - | ||||||||||||
499 | done = (currentHeight >= totalHeight); | - | ||||||||||||
500 | } never executed: end of block | 0 | ||||||||||||
501 | done = (currentHeight >= totalHeight) &&
| 0 | ||||||||||||
502 | (currentWidth >= totalWidth);
| 0 | ||||||||||||
503 | - | |||||||||||||
504 | int w = totalWidth; | - | ||||||||||||
505 | int h = totalHeight; | - | ||||||||||||
506 | int x = widget->geometry().x(); | - | ||||||||||||
507 | int y = widget->geometry().y(); | - | ||||||||||||
508 | - | |||||||||||||
509 | if (orientation & RightScroll || orientation & LeftScroll)
| 0 | ||||||||||||
510 | w = qMin(currentWidth, totalWidth); never executed: w = qMin(currentWidth, totalWidth); | 0 | ||||||||||||
511 | if (orientation & DownScroll || orientation & UpScroll)
| 0 | ||||||||||||
512 | h = qMin(currentHeight, totalHeight); never executed: h = qMin(currentHeight, totalHeight); | 0 | ||||||||||||
513 | - | |||||||||||||
514 | setUpdatesEnabled(false); | - | ||||||||||||
515 | if (orientation & UpScroll)
| 0 | ||||||||||||
516 | y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); never executed: y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); | 0 | ||||||||||||
517 | if (orientation & LeftScroll)
| 0 | ||||||||||||
518 | x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); never executed: x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); | 0 | ||||||||||||
519 | if (orientation & UpScroll || orientation & LeftScroll)
| 0 | ||||||||||||
520 | move(x, y); never executed: move(x, y); | 0 | ||||||||||||
521 | - | |||||||||||||
522 | resize(w, h); | - | ||||||||||||
523 | setUpdatesEnabled(true); | - | ||||||||||||
524 | repaint(); | - | ||||||||||||
525 | } never executed: end of block | 0 | ||||||||||||
526 | if (done || !widget) {
| 0 | ||||||||||||
527 | anim.stop(); | - | ||||||||||||
528 | if (widget) {
| 0 | ||||||||||||
529 | if (!showWidget) {
| 0 | ||||||||||||
530 | #ifdef Q_OS_WIN | - | ||||||||||||
531 | setEnabled(true); | - | ||||||||||||
532 | setFocus(); | - | ||||||||||||
533 | #endif | - | ||||||||||||
534 | widget->hide(); | - | ||||||||||||
535 | } else { never executed: end of block | 0 | ||||||||||||
536 | //Since we are faking the visibility of the widget | - | ||||||||||||
537 | //we need to unset the hidden state on it before calling show | - | ||||||||||||
538 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - | ||||||||||||
539 | widget->show(); | - | ||||||||||||
540 | lower(); | - | ||||||||||||
541 | } never executed: end of block | 0 | ||||||||||||
542 | } | - | ||||||||||||
543 | q_roll = 0; | - | ||||||||||||
544 | deleteLater(); | - | ||||||||||||
545 | } never executed: end of block | 0 | ||||||||||||
546 | } never executed: end of block | 0 | ||||||||||||
547 | - | |||||||||||||
548 | /*! | - | ||||||||||||
549 | Scroll widget \a w in \a time ms. \a orient may be 1 (vertical), 2 | - | ||||||||||||
550 | (horizontal) or 3 (diagonal). | - | ||||||||||||
551 | */ | - | ||||||||||||
552 | void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) | - | ||||||||||||
553 | { | - | ||||||||||||
554 | if (q_roll) {
| 0 | ||||||||||||
555 | q_roll->deleteLater(); | - | ||||||||||||
556 | q_roll = 0; | - | ||||||||||||
557 | } never executed: end of block | 0 | ||||||||||||
558 | - | |||||||||||||
559 | if (!w)
| 0 | ||||||||||||
560 | return; never executed: return; | 0 | ||||||||||||
561 | - | |||||||||||||
562 | QApplication::sendPostedEvents(w, QEvent::Move); | - | ||||||||||||
563 | QApplication::sendPostedEvents(w, QEvent::Resize); | - | ||||||||||||
564 | Qt::WindowFlags flags = Qt::ToolTip; | - | ||||||||||||
565 | - | |||||||||||||
566 | // those can be popups - they would steal the focus, but are disabled | - | ||||||||||||
567 | q_roll = new QRollEffect(w, flags, orient); | - | ||||||||||||
568 | q_roll->run(time); | - | ||||||||||||
569 | } never executed: end of block | 0 | ||||||||||||
570 | - | |||||||||||||
571 | /*! | - | ||||||||||||
572 | Fade in widget \a w in \a time ms. | - | ||||||||||||
573 | */ | - | ||||||||||||
574 | void qFadeEffect(QWidget* w, int time) | - | ||||||||||||
575 | { | - | ||||||||||||
576 | if (q_blend) {
| 0 | ||||||||||||
577 | q_blend->deleteLater(); | - | ||||||||||||
578 | q_blend = 0; | - | ||||||||||||
579 | } never executed: end of block | 0 | ||||||||||||
580 | - | |||||||||||||
581 | if (!w)
| 0 | ||||||||||||
582 | return; never executed: return; | 0 | ||||||||||||
583 | - | |||||||||||||
584 | QApplication::sendPostedEvents(w, QEvent::Move); | - | ||||||||||||
585 | QApplication::sendPostedEvents(w, QEvent::Resize); | - | ||||||||||||
586 | - | |||||||||||||
587 | Qt::WindowFlags flags = Qt::ToolTip; | - | ||||||||||||
588 | - | |||||||||||||
589 | // those can be popups - they would steal the focus, but are disabled | - | ||||||||||||
590 | q_blend = new QAlphaWidget(w, flags); | - | ||||||||||||
591 | - | |||||||||||||
592 | q_blend->run(time); | - | ||||||||||||
593 | } never executed: end of block | 0 | ||||||||||||
594 | - | |||||||||||||
595 | QT_END_NAMESPACE | - | ||||||||||||
596 | - | |||||||||||||
597 | /* | - | ||||||||||||
598 | Delete this after timeout | - | ||||||||||||
599 | */ | - | ||||||||||||
600 | - | |||||||||||||
601 | #include "qeffects.moc" | - | ||||||||||||
602 | - | |||||||||||||
603 | #endif //QT_NO_EFFECTS | - | ||||||||||||
Source code | Switch to Preprocessed file |