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);
93 widget->setWindowOpacity(1);
98
99
103 p.drawPixmap(0, 0, pm);
107
108
109
125 qApp->installEventFilter(
this);
126 widget->setWindowOpacity(0.0);
128 connect(&anim, &QTimer::timeout,
this, &QAlphaWidget::render);
132 widget->setAttribute(Qt::WA_WState_ExplicitShowHide,
true);
133 widget->setAttribute(Qt::WA_WState_Hidden,
false);
135 qApp->installEventFilter(
this);
137 move(widget->geometry().x(),widget->geometry().y());
138 resize(widget->size().width(), widget->size().height());
140 frontImage = widget->grab().toImage();
141 backImage = QGuiApplication::primaryScreen()->grabWindow(0,
142 widget->geometry().x(), widget->geometry().y(),
143 widget->geometry().width(), widget->geometry().height()).toImage();
145 if (!backImage.isNull() && checkTime.elapsed() < duration / 2) {
146 mixedImage = backImage.copy();
147 pm = QPixmap::fromImage(mixedImage);
151 connect(&anim, &QTimer::timeout,
this, &QAlphaWidget::render);
161
162
169 move(widget->geometry().x(),widget->geometry().y());
177 case QEvent::MouseButtonPress:
178 case QEvent::MouseButtonDblClick:
182 case QEvent::KeyPress: {
183#ifndef QT_NO_SHORTCUT
184 QKeyEvent *ke =
static_cast<QKeyEvent *>(e);
185 if (ke->matches(QKeySequence::Cancel)) {
198 return QWidget::eventFilter(o, e);
202
203
213 QWidget::closeEvent(e);
217
218
219
220
221
224 int tempel = checkTime.elapsed();
225 if (elapsed >= tempel)
231 alpha = tempel /
double(duration);
236 if (alpha >= 1 || !showWidget) {
238 qApp->removeEventFilter(
this);
239 widget->setWindowOpacity(1);
242 widget->setWindowOpacity(alpha);
245 if (alpha >= 1 || !showWidget) {
247 qApp->removeEventFilter(
this);
255 widget->setAttribute(Qt::WA_WState_Hidden,
true);
263 pm = QPixmap::fromImage(mixedImage);
270
271
274 const int a = qRound(alpha*256);
275 const int ia = 256 - a;
277 const int sw = frontImage.width();
278 const int sh = frontImage.height();
279 const qsizetype bpl = frontImage.bytesPerLine();
280 switch(frontImage.depth()) {
283 uchar *mixed_data = mixedImage.bits();
284 const uchar *back_data = backImage.bits();
285 const uchar *front_data = frontImage.bits();
287 for (
int sy = 0; sy < sh; sy++) {
288 quint32* mixed = (quint32*)mixed_data;
289 const quint32* back = (
const quint32*)back_data;
290 const quint32* front = (
const quint32*)front_data;
291 for (
int sx = 0; sx < sw; sx++) {
292 quint32 bp = back[sx];
293 quint32 fp = front[sx];
295 mixed[sx] = qRgb((qRed(bp)*ia + qRed(fp)*a)>>8,
296 (qGreen(bp)*ia + qGreen(fp)*a)>>8,
297 (qBlue(bp)*ia + qBlue(fp)*a)>>8);
311
312
313
314
315
347 QElapsedTimer checkTime;
355
356
358 : QWidget(
nullptr, f), orientation(orient)
360 QWidgetPrivate::get(
this)->setScreen(w->screen());
368 setAttribute(Qt::WA_NoSystemBackground,
true);
370 if (widget->testAttribute(Qt::WA_Resized)) {
371 totalWidth = widget->width();
372 totalHeight = widget->height();
374 totalWidth = widget->sizeHint().width();
375 totalHeight = widget->sizeHint().height();
378 currentHeight = totalHeight;
379 currentWidth = totalWidth;
390
391
394 int x = orientation &
RightScroll ? qMin(0, currentWidth - totalWidth) : 0;
395 int y = orientation &
DownScroll ? qMin(0, currentHeight - totalHeight) : 0;
398 p.drawPixmap(x, y, pm);
402
403
414 QWidget::closeEvent(e);
418
419
420
421
422
434 dist += totalWidth - currentWidth;
436 dist += totalHeight - currentHeight;
437 duration = qMin(qMax(dist/3, 50), 120);
440 connect(&anim, &QTimer::timeout,
this, &QRollEffect::scroll);
442 move(widget->geometry().x(),widget->geometry().y());
443 resize(qMin(currentWidth, totalWidth), qMin(currentHeight, totalHeight));
446 widget->setAttribute(Qt::WA_WState_ExplicitShowHide,
true);
447 widget->setAttribute(Qt::WA_WState_Hidden,
false);
459
460
463 if (!done && widget) {
464 int tempel = checkTime.elapsed();
465 if (elapsed >= tempel)
470 if (currentWidth != totalWidth) {
471 currentWidth = totalWidth * (elapsed/duration)
472 + (2 * totalWidth * (elapsed%duration) + duration)
476 if (currentHeight != totalHeight) {
477 currentHeight = totalHeight * (elapsed/duration)
478 + (2 * totalHeight * (elapsed%duration) + duration)
482 done = (currentHeight >= totalHeight) &&
483 (currentWidth >= totalWidth);
487 int x = widget->geometry().x();
488 int y = widget->geometry().y();
491 w = qMin(currentWidth, totalWidth);
493 h = qMin(currentHeight, totalHeight);
495 setUpdatesEnabled(
false);
496 if (orientation & UpScroll)
497 y = widget->geometry().y() + qMax(0, totalHeight - currentHeight);
498 if (orientation & LeftScroll)
499 x = widget->geometry().x() + qMax(0, totalWidth - currentWidth);
504 setUpdatesEnabled(
true);
507 if (done || !widget) {
519 widget->setAttribute(Qt::WA_WState_Hidden,
true);
529
530
531
539 QCoreApplication::sendPostedEvents(w, QEvent::Move);
540 QCoreApplication::sendPostedEvents(w, QEvent::Resize);
541 Qt::WindowFlags flags = Qt::ToolTip;
549
550
558 QCoreApplication::sendPostedEvents(w, QEvent::Move);
559 QCoreApplication::sendPostedEvents(w, QEvent::Resize);
561 Qt::WindowFlags flags = Qt::ToolTip;
572
573
575#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...
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