qeffects.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9