17#include "private/qwidget_p.h"
33
34
35
36
37
68 QElapsedTimer checkTime;
74
75
79 QWidgetPrivate::get(
this)->setScreen(w->screen());
83 setAttribute(Qt::WA_NoSystemBackground,
true);
86 connect(w, &QWidget::destroyed,
this, []() {
q_blend.reset(); });
94 widget->setWindowOpacity(1);
99
100
104 p.drawPixmap(0, 0, pm);
108
109
110
126 qApp->installEventFilter(
this);
127 widget->setWindowOpacity(0.0);
129 connect(&anim, &QTimer::timeout,
this, &QAlphaWidget::render);
133 widget->setAttribute(Qt::WA_WState_ExplicitShowHide,
true);
134 widget->setAttribute(Qt::WA_WState_Hidden,
false);
136 qApp->installEventFilter(
this);
138 move(widget->geometry().x(),widget->geometry().y());
139 resize(widget->size().width(), widget->size().height());
141 frontImage = widget->grab().toImage();
142 backImage = QGuiApplication::primaryScreen()->grabWindow(0,
143 widget->geometry().x(), widget->geometry().y(),
144 widget->geometry().width(), widget->geometry().height()).toImage();
146 if (!backImage.isNull() && checkTime.elapsed() < duration / 2) {
147 mixedImage = backImage.copy();
148 pm = QPixmap::fromImage(mixedImage);
152 connect(&anim, &QTimer::timeout,
this, &QAlphaWidget::render);
162
163
170 move(widget->geometry().x(),widget->geometry().y());
178 case QEvent::MouseButtonPress:
179 case QEvent::MouseButtonDblClick:
183 case QEvent::KeyPress: {
184#ifndef QT_NO_SHORTCUT
185 QKeyEvent *ke =
static_cast<QKeyEvent *>(e);
186 if (ke->matches(QKeySequence::Cancel)) {
199 return QWidget::eventFilter(o, e);
203
204
214 QWidget::closeEvent(e);
218
219
220
221
222
225 int tempel = checkTime.elapsed();
226 if (elapsed >= tempel)
232 alpha = tempel /
double(duration);
237 if (alpha >= 1 || !showWidget) {
239 qApp->removeEventFilter(
this);
240 widget->setWindowOpacity(1);
243 widget->setWindowOpacity(alpha);
246 if (alpha >= 1 || !showWidget) {
248 qApp->removeEventFilter(
this);
256 widget->setAttribute(Qt::WA_WState_Hidden,
true);
264 pm = QPixmap::fromImage(mixedImage);
271
272
275 const int a = qRound(alpha*256);
276 const int ia = 256 - a;
278 const int sw = frontImage.width();
279 const int sh = frontImage.height();
280 const qsizetype bpl = frontImage.bytesPerLine();
281 switch(frontImage.depth()) {
284 uchar *mixed_data = mixedImage.bits();
285 const uchar *back_data = backImage.bits();
286 const uchar *front_data = frontImage.bits();
288 for (
int sy = 0; sy < sh; sy++) {
289 quint32* mixed = (quint32*)mixed_data;
290 const quint32* back = (
const quint32*)back_data;
291 const quint32* front = (
const quint32*)front_data;
292 for (
int sx = 0; sx < sw; sx++) {
293 quint32 bp = back[sx];
294 quint32 fp = front[sx];
296 mixed[sx] = qRgb((qRed(bp)*ia + qRed(fp)*a)>>8,
297 (qGreen(bp)*ia + qGreen(fp)*a)>>8,
298 (qBlue(bp)*ia + qBlue(fp)*a)>>8);
312
313
314
315
316
348 QElapsedTimer checkTime;
356
357
359 : QWidget(
nullptr, f), orientation(orient)
361 QWidgetPrivate::get(
this)->setScreen(w->screen());
369 setAttribute(Qt::WA_NoSystemBackground,
true);
371 if (widget->testAttribute(Qt::WA_Resized)) {
372 totalWidth = widget->width();
373 totalHeight = widget->height();
375 totalWidth = widget->sizeHint().width();
376 totalHeight = widget->sizeHint().height();
379 currentHeight = totalHeight;
380 currentWidth = totalWidth;
388 connect(w, &QWidget::destroyed,
this, []() {
q_roll.reset(); });
392
393
396 int x = orientation &
RightScroll ? qMin(0, currentWidth - totalWidth) : 0;
397 int y = orientation &
DownScroll ? qMin(0, currentHeight - totalHeight) : 0;
400 p.drawPixmap(x, y, pm);
404
405
416 QWidget::closeEvent(e);
420
421
422
423
424
436 dist += totalWidth - currentWidth;
438 dist += totalHeight - currentHeight;
439 duration = qMin(qMax(dist/3, 50), 120);
442 connect(&anim, &QTimer::timeout,
this, &QRollEffect::scroll);
444 move(widget->geometry().x(),widget->geometry().y());
445 resize(qMin(currentWidth, totalWidth), qMin(currentHeight, totalHeight));
448 widget->setAttribute(Qt::WA_WState_ExplicitShowHide,
true);
449 widget->setAttribute(Qt::WA_WState_Hidden,
false);
461
462
465 if (!done && widget) {
466 int tempel = checkTime.elapsed();
467 if (elapsed >= tempel)
472 if (currentWidth != totalWidth) {
473 currentWidth = totalWidth * (elapsed/duration)
474 + (2 * totalWidth * (elapsed%duration) + duration)
478 if (currentHeight != totalHeight) {
479 currentHeight = totalHeight * (elapsed/duration)
480 + (2 * totalHeight * (elapsed%duration) + duration)
484 done = (currentHeight >= totalHeight) &&
485 (currentWidth >= totalWidth);
489 int x = widget->geometry().x();
490 int y = widget->geometry().y();
493 w = qMin(currentWidth, totalWidth);
495 h = qMin(currentHeight, totalHeight);
497 setUpdatesEnabled(
false);
498 if (orientation & UpScroll)
499 y = widget->geometry().y() + qMax(0, totalHeight - currentHeight);
500 if (orientation & LeftScroll)
501 x = widget->geometry().x() + qMax(0, totalWidth - currentWidth);
506 setUpdatesEnabled(
true);
509 if (done || !widget) {
521 widget->setAttribute(Qt::WA_WState_Hidden,
true);
531
532
533
541 QCoreApplication::sendPostedEvents(w, QEvent::Move);
542 QCoreApplication::sendPostedEvents(w, QEvent::Resize);
543 Qt::WindowFlags flags = Qt::ToolTip;
551
552
560 QCoreApplication::sendPostedEvents(w, QEvent::Move);
561 QCoreApplication::sendPostedEvents(w, QEvent::Resize);
563 Qt::WindowFlags flags = Qt::ToolTip;
574
575
577#include "qeffects.moc"
QPainter(QPaintDevice *)
Constructs a painter that begins painting the paint device immediately.
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void closeEvent(QCloseEvent *) override
This event handler is called with the given event when Qt receives a window close request for a top-l...
Combined button and popup list for selecting options.
static std::unique_ptr< QRollEffect, DeleteLater > q_roll
void qScrollEffect(QWidget *w, QEffects::DirFlags orient, int time)
void qFadeEffect(QWidget *w, int time)
static std::unique_ptr< QAlphaWidget, DeleteLater > q_blend
void operator()(QObject *o) const