Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | class QAlphaWidget: public QWidget, private QEffects | - |
5 | { | - |
6 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
7 | public: | - |
8 | QAlphaWidget(QWidget* w, Qt::WindowFlags f = 0); | - |
9 | ~QAlphaWidget(); | - |
10 | | - |
11 | void run(int time); | - |
12 | | - |
13 | protected: | - |
14 | void paintEvent(QPaintEvent* e); | - |
15 | void closeEvent(QCloseEvent*); | - |
16 | void alphaBlend(); | - |
17 | bool eventFilter(QObject *, QEvent *); | - |
18 | | - |
19 | protected : | - |
20 | void render(); | - |
21 | | - |
22 | private: | - |
23 | QPixmap pm; | - |
24 | double alpha; | - |
25 | QImage backImage; | - |
26 | QImage frontImage; | - |
27 | QImage mixedImage; | - |
28 | QPointer<QWidget> widget; | - |
29 | int duration; | - |
30 | int elapsed; | - |
31 | bool showWidget; | - |
32 | QTimer anim; | - |
33 | QElapsedTimer checkTime; | - |
34 | }; | - |
35 | | - |
36 | static QAlphaWidget* q_blend = 0; | - |
37 | | - |
38 | | - |
39 | | - |
40 | | - |
41 | QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) | - |
42 | : QWidget(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(w)), f) | - |
43 | { | - |
44 | | - |
45 | setEnabled(false); | - |
46 | | - |
47 | setAttribute(Qt::WA_NoSystemBackground, true); | - |
48 | widget = w; | - |
49 | alpha = 0; | - |
50 | } | 0 |
51 | | - |
52 | QAlphaWidget::~QAlphaWidget() | - |
53 | { | - |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | } | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | void QAlphaWidget::paintEvent(QPaintEvent*) | - |
65 | { | - |
66 | QPainter p(this); | - |
67 | p.drawPixmap(0, 0, pm); | - |
68 | } | 0 |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | void QAlphaWidget::run(int time) | - |
75 | { | - |
76 | duration = time; | - |
77 | | - |
78 | if (duration < 0) never evaluated: duration < 0 | 0 |
79 | duration = 150; never executed: duration = 150; | 0 |
80 | | - |
81 | if (!widget) | 0 |
82 | return; | 0 |
83 | | - |
84 | elapsed = 0; | - |
85 | checkTime.start(); | - |
86 | | - |
87 | showWidget = true; | - |
88 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - |
89 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - |
90 | | - |
91 | (static_cast<QApplication *>(QCoreApplication::instance()))->installEventFilter(this); | - |
92 | | - |
93 | move(widget->geometry().x(),widget->geometry().y()); | - |
94 | resize(widget->size().width(), widget->size().height()); | - |
95 | | - |
96 | frontImage = widget->grab().toImage(); | - |
97 | backImage = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(), | - |
98 | widget->geometry().x(), widget->geometry().y(), | - |
99 | widget->geometry().width(), widget->geometry().height()).toImage(); | - |
100 | | - |
101 | if (!backImage.isNull() && checkTime.elapsed() < duration / 2) { never evaluated: !backImage.isNull() never evaluated: checkTime.elapsed() < duration / 2 | 0 |
102 | mixedImage = backImage.copy(); | - |
103 | pm = QPixmap::fromImage(mixedImage); | - |
104 | show(); | - |
105 | setEnabled(false); | - |
106 | | - |
107 | connect(&anim, "2""timeout()", this, "1""render()"); | - |
108 | anim.start(1); | - |
109 | } else { | 0 |
110 | duration = 0; | - |
111 | render(); | - |
112 | } | 0 |
113 | | - |
114 | } | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | bool QAlphaWidget::eventFilter(QObject *o, QEvent *e) | - |
120 | { | - |
121 | switch (e->type()) { | - |
122 | case QEvent::Move: | - |
123 | if (o != widget) never evaluated: o != widget | 0 |
124 | break; | 0 |
125 | move(widget->geometry().x(),widget->geometry().y()); | - |
126 | update(); | - |
127 | break; | 0 |
128 | case QEvent::Hide: | - |
129 | case QEvent::Close: | - |
130 | if (o != widget) never evaluated: o != widget | 0 |
131 | break; | 0 |
132 | case QEvent::MouseButtonPress: code before this statement never executed: case QEvent::MouseButtonPress: | 0 |
133 | case QEvent::MouseButtonDblClick: | - |
134 | showWidget = false; | - |
135 | render(); | - |
136 | break; | 0 |
137 | case QEvent::KeyPress: { | - |
138 | QKeyEvent *ke = (QKeyEvent*)e; | - |
139 | if (ke->key() == Qt::Key_Escape) { never evaluated: ke->key() == Qt::Key_Escape | 0 |
140 | showWidget = false; | - |
141 | } else { | 0 |
142 | duration = 0; | - |
143 | } | 0 |
144 | render(); | - |
145 | break; | 0 |
146 | } | - |
147 | default: | - |
148 | break; | 0 |
149 | } | - |
150 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 |
151 | } | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | void QAlphaWidget::closeEvent(QCloseEvent *e) | - |
157 | { | - |
158 | e->accept(); | - |
159 | if (!q_blend) never evaluated: !q_blend | 0 |
160 | return; | 0 |
161 | | - |
162 | showWidget = false; | - |
163 | render(); | - |
164 | | - |
165 | QWidget::closeEvent(e); | - |
166 | } | 0 |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | void QAlphaWidget::render() | - |
175 | { | - |
176 | int tempel = checkTime.elapsed(); | - |
177 | if (elapsed >= tempel) never evaluated: elapsed >= tempel | 0 |
178 | elapsed++; never executed: elapsed++; | 0 |
179 | else | - |
180 | elapsed = tempel; never executed: elapsed = tempel; | 0 |
181 | | - |
182 | if (duration != 0) never evaluated: duration != 0 | 0 |
183 | alpha = tempel / double(duration); never executed: alpha = tempel / double(duration); | 0 |
184 | else | - |
185 | alpha = 1; never executed: alpha = 1; | 0 |
186 | if (alpha >= 1 || !showWidget) { never evaluated: alpha >= 1 never evaluated: !showWidget | 0 |
187 | anim.stop(); | - |
188 | (static_cast<QApplication *>(QCoreApplication::instance()))->removeEventFilter(this); | - |
189 | | - |
190 | if (widget) { | 0 |
191 | if (!showWidget) { never evaluated: !showWidget | 0 |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | widget->hide(); | - |
197 | } else { | 0 |
198 | | - |
199 | | - |
200 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - |
201 | widget->show(); | - |
202 | lower(); | - |
203 | } | 0 |
204 | } | - |
205 | q_blend = 0; | - |
206 | deleteLater(); | - |
207 | } else { | 0 |
208 | alphaBlend(); | - |
209 | pm = QPixmap::fromImage(mixedImage); | - |
210 | repaint(); | - |
211 | } | 0 |
212 | | - |
213 | } | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | void QAlphaWidget::alphaBlend() | - |
219 | { | - |
220 | const int a = qRound(alpha*256); | - |
221 | const int ia = 256 - a; | - |
222 | | - |
223 | const int sw = frontImage.width(); | - |
224 | const int sh = frontImage.height(); | - |
225 | const int bpl = frontImage.bytesPerLine(); | - |
226 | switch(frontImage.depth()) { | - |
227 | case 32: | - |
228 | { | - |
229 | uchar *mixed_data = mixedImage.bits(); | - |
230 | const uchar *back_data = backImage.bits(); | - |
231 | const uchar *front_data = frontImage.bits(); | - |
232 | | - |
233 | for (int sy = 0; sy < sh; sy++) { | 0 |
234 | quint32* mixed = (quint32*)mixed_data; | - |
235 | const quint32* back = (const quint32*)back_data; | - |
236 | const quint32* front = (const quint32*)front_data; | - |
237 | for (int sx = 0; sx < sw; sx++) { | 0 |
238 | quint32 bp = back[sx]; | - |
239 | quint32 fp = front[sx]; | - |
240 | | - |
241 | mixed[sx] = qRgb((qRed(bp)*ia + qRed(fp)*a)>>8, | - |
242 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - |
243 | (qBlue(bp)*ia + qBlue(fp)*a)>>8); | - |
244 | } | 0 |
245 | mixed_data += bpl; | - |
246 | back_data += bpl; | - |
247 | front_data += bpl; | - |
248 | } | 0 |
249 | } | - |
250 | default: | - |
251 | break; | 0 |
252 | } | - |
253 | } | 0 |
254 | class QRollEffect : public QWidget, private QEffects | - |
255 | { | - |
256 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
257 | public: | - |
258 | QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient); | - |
259 | | - |
260 | void run(int time); | - |
261 | | - |
262 | protected: | - |
263 | void paintEvent(QPaintEvent*); | - |
264 | void closeEvent(QCloseEvent*); | - |
265 | | - |
266 | private : | - |
267 | void scroll(); | - |
268 | | - |
269 | private: | - |
270 | QPointer<QWidget> widget; | - |
271 | | - |
272 | int currentHeight; | - |
273 | int currentWidth; | - |
274 | int totalHeight; | - |
275 | int totalWidth; | - |
276 | | - |
277 | int duration; | - |
278 | int elapsed; | - |
279 | bool done; | - |
280 | bool showWidget; | - |
281 | int orientation; | - |
282 | | - |
283 | QTimer anim; | - |
284 | QElapsedTimer checkTime; | - |
285 | | - |
286 | QPixmap pm; | - |
287 | }; | - |
288 | | - |
289 | static QRollEffect* q_roll = 0; | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient) | - |
295 | : QWidget(0, f), orientation(orient) | - |
296 | { | - |
297 | | - |
298 | setEnabled(false); | - |
299 | | - |
300 | | - |
301 | widget = w; | - |
302 | qt_noop(); | - |
303 | | - |
304 | setAttribute(Qt::WA_NoSystemBackground, true); | - |
305 | | - |
306 | if (widget->testAttribute(Qt::WA_Resized)) { never evaluated: widget->testAttribute(Qt::WA_Resized) | 0 |
307 | totalWidth = widget->width(); | - |
308 | totalHeight = widget->height(); | - |
309 | } else { | 0 |
310 | totalWidth = widget->sizeHint().width(); | - |
311 | totalHeight = widget->sizeHint().height(); | - |
312 | } | 0 |
313 | | - |
314 | currentHeight = totalHeight; | - |
315 | currentWidth = totalWidth; | - |
316 | | - |
317 | if (orientation & (RightScroll|LeftScroll)) never evaluated: orientation & (RightScroll|LeftScroll) | 0 |
318 | currentWidth = 0; never executed: currentWidth = 0; | 0 |
319 | if (orientation & (DownScroll|UpScroll)) never evaluated: orientation & (DownScroll|UpScroll) | 0 |
320 | currentHeight = 0; never executed: currentHeight = 0; | 0 |
321 | | - |
322 | pm = widget->grab(); | - |
323 | } | 0 |
324 | | - |
325 | | - |
326 | | - |
327 | | - |
328 | void QRollEffect::paintEvent(QPaintEvent*) | - |
329 | { | - |
330 | int x = orientation & RightScroll ? qMin(0, currentWidth - totalWidth) : 0; never evaluated: orientation & RightScroll | 0 |
331 | int y = orientation & DownScroll ? qMin(0, currentHeight - totalHeight) : 0; never evaluated: orientation & DownScroll | 0 |
332 | | - |
333 | QPainter p(this); | - |
334 | p.drawPixmap(x, y, pm); | - |
335 | } | 0 |
336 | | - |
337 | | - |
338 | | - |
339 | | - |
340 | void QRollEffect::closeEvent(QCloseEvent *e) | - |
341 | { | - |
342 | e->accept(); | - |
343 | if (done) | 0 |
344 | return; | 0 |
345 | | - |
346 | showWidget = false; | - |
347 | done = true; | - |
348 | scroll(); | - |
349 | | - |
350 | QWidget::closeEvent(e); | - |
351 | } | 0 |
352 | | - |
353 | | - |
354 | | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | void QRollEffect::run(int time) | - |
360 | { | - |
361 | if (!widget) | 0 |
362 | return; | 0 |
363 | | - |
364 | duration = time; | - |
365 | elapsed = 0; | - |
366 | | - |
367 | if (duration < 0) { never evaluated: duration < 0 | 0 |
368 | int dist = 0; | - |
369 | if (orientation & (RightScroll|LeftScroll)) never evaluated: orientation & (RightScroll|LeftScroll) | 0 |
370 | dist += totalWidth - currentWidth; never executed: dist += totalWidth - currentWidth; | 0 |
371 | if (orientation & (DownScroll|UpScroll)) never evaluated: orientation & (DownScroll|UpScroll) | 0 |
372 | dist += totalHeight - currentHeight; never executed: dist += totalHeight - currentHeight; | 0 |
373 | duration = qMin(qMax(dist/3, 50), 120); | - |
374 | } | 0 |
375 | | - |
376 | connect(&anim, "2""timeout()", this, "1""scroll()"); | - |
377 | | - |
378 | move(widget->geometry().x(),widget->geometry().y()); | - |
379 | resize(qMin(currentWidth, totalWidth), qMin(currentHeight, totalHeight)); | - |
380 | | - |
381 | | - |
382 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - |
383 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - |
384 | | - |
385 | show(); | - |
386 | setEnabled(false); | - |
387 | | - |
388 | showWidget = true; | - |
389 | done = false; | - |
390 | anim.start(1); | - |
391 | checkTime.start(); | - |
392 | } | 0 |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | void QRollEffect::scroll() | - |
398 | { | - |
399 | if (!done && widget) { | 0 |
400 | int tempel = checkTime.elapsed(); | - |
401 | if (elapsed >= tempel) never evaluated: elapsed >= tempel | 0 |
402 | elapsed++; never executed: elapsed++; | 0 |
403 | else | - |
404 | elapsed = tempel; never executed: elapsed = tempel; | 0 |
405 | | - |
406 | if (currentWidth != totalWidth) { never evaluated: currentWidth != totalWidth | 0 |
407 | currentWidth = totalWidth * (elapsed/duration) | - |
408 | + (2 * totalWidth * (elapsed%duration) + duration) | - |
409 | / (2 * duration); | - |
410 | | - |
411 | done = (currentWidth >= totalWidth); | - |
412 | } | 0 |
413 | if (currentHeight != totalHeight) { never evaluated: currentHeight != totalHeight | 0 |
414 | currentHeight = totalHeight * (elapsed/duration) | - |
415 | + (2 * totalHeight * (elapsed%duration) + duration) | - |
416 | / (2 * duration); | - |
417 | | - |
418 | done = (currentHeight >= totalHeight); | - |
419 | } | 0 |
420 | done = (currentHeight >= totalHeight) && never evaluated: (currentHeight >= totalHeight) | 0 |
421 | (currentWidth >= totalWidth); never evaluated: (currentWidth >= totalWidth) | 0 |
422 | | - |
423 | int w = totalWidth; | - |
424 | int h = totalHeight; | - |
425 | int x = widget->geometry().x(); | - |
426 | int y = widget->geometry().y(); | - |
427 | | - |
428 | if (orientation & RightScroll || orientation & LeftScroll) never evaluated: orientation & RightScroll never evaluated: orientation & LeftScroll | 0 |
429 | w = qMin(currentWidth, totalWidth); never executed: w = qMin(currentWidth, totalWidth); | 0 |
430 | if (orientation & DownScroll || orientation & UpScroll) never evaluated: orientation & DownScroll never evaluated: orientation & UpScroll | 0 |
431 | h = qMin(currentHeight, totalHeight); never executed: h = qMin(currentHeight, totalHeight); | 0 |
432 | | - |
433 | setUpdatesEnabled(false); | - |
434 | if (orientation & UpScroll) never evaluated: orientation & UpScroll | 0 |
435 | y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); never executed: y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); | 0 |
436 | if (orientation & LeftScroll) never evaluated: orientation & LeftScroll | 0 |
437 | x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); never executed: x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); | 0 |
438 | if (orientation & UpScroll || orientation & LeftScroll) never evaluated: orientation & UpScroll never evaluated: orientation & LeftScroll | 0 |
439 | move(x, y); never executed: move(x, y); | 0 |
440 | | - |
441 | resize(w, h); | - |
442 | setUpdatesEnabled(true); | - |
443 | repaint(); | - |
444 | } | 0 |
445 | if (done || !widget) { | 0 |
446 | anim.stop(); | - |
447 | if (widget) { | 0 |
448 | if (!showWidget) { never evaluated: !showWidget | 0 |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | widget->hide(); | - |
454 | } else { | 0 |
455 | | - |
456 | | - |
457 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - |
458 | widget->show(); | - |
459 | lower(); | - |
460 | } | 0 |
461 | } | - |
462 | q_roll = 0; | - |
463 | deleteLater(); | - |
464 | } | 0 |
465 | } | 0 |
466 | | - |
467 | | - |
468 | | - |
469 | | - |
470 | | - |
471 | void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) | - |
472 | { | - |
473 | if (q_roll) { partially evaluated: q_roll no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
474 | q_roll->deleteLater(); | - |
475 | q_roll = 0; | - |
476 | } | 0 |
477 | | - |
478 | if (!w) partially evaluated: !w yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
479 | return; executed: return; Execution Count:1 | 1 |
480 | | - |
481 | QApplication::sendPostedEvents(w, QEvent::Move); | - |
482 | QApplication::sendPostedEvents(w, QEvent::Resize); | - |
483 | Qt::WindowFlags flags = Qt::ToolTip; | - |
484 | | - |
485 | | - |
486 | q_roll = new QRollEffect(w, flags, orient); | - |
487 | q_roll->run(time); | - |
488 | } | 0 |
489 | | - |
490 | | - |
491 | | - |
492 | | - |
493 | void qFadeEffect(QWidget* w, int time) | - |
494 | { | - |
495 | if (q_blend) { partially evaluated: q_blend no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
496 | q_blend->deleteLater(); | - |
497 | q_blend = 0; | - |
498 | } | 0 |
499 | | - |
500 | if (!w) partially evaluated: !w yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
501 | return; executed: return; Execution Count:1 | 1 |
502 | | - |
503 | QApplication::sendPostedEvents(w, QEvent::Move); | - |
504 | QApplication::sendPostedEvents(w, QEvent::Resize); | - |
505 | | - |
506 | Qt::WindowFlags flags = Qt::ToolTip; | - |
507 | | - |
508 | | - |
509 | q_blend = new QAlphaWidget(w, flags); | - |
510 | | - |
511 | q_blend->run(time); | - |
512 | } | 0 |
513 | | - |
514 | | - |
515 | | - |
516 | | - |
517 | | - |
518 | | - |
519 | | - |
520 | | - |
| | |