From 7e2fded55e67727043c3dd0a1a5b3883655101c4 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 6 Jul 2020 17:22:12 +0200 Subject: Remove usage of QDesktopWidget(Private) from most places in QtWidgets Call QGuiApplication and QScreen APIs directly to get geometries, and make use of QScreen::grabWindow grabbing the screen it's called on when called with WId == 0. This assumes that QGuiApplication::screen and QWidget::screen never return nullptr, which is already assumed in other places. In QSplashScreen, simplify the code to operate on the screen of the QSplashScreen itself. Remove the case that handles a QDesktopWidget parent - QSplashScreen doesn't have a constructor that takes a QWidget* parent anymore. In the QEffect implementation, we can rely on the widget pointer not being nullptr (it's tested in the free functions client code uses). Includes a few drive-by changes to coding style and logic in qtooltip.cpp, where the tip label placement now prefers the screen of the widget the label is created for, and uses the position only as a fallback. What remains is the special handling of QDesktopWidget and the Qt::Desktop type in QWidget and QApplication. Change-Id: I30b67bab8ae82ddfcc7bbbec3c10f6e935b74f06 Reviewed-by: Shawn Rutledge Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/widgets/widgets/qsplashscreen.cpp | 61 +++++++---------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) (limited to 'src/widgets/widgets/qsplashscreen.cpp') diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp index 1f1c71dcb8..2c2d1922be 100644 --- a/src/widgets/widgets/qsplashscreen.cpp +++ b/src/widgets/widgets/qsplashscreen.cpp @@ -40,7 +40,6 @@ #include "qsplashscreen.h" #include "qapplication.h" -#include #include "qpainter.h" #include "qpixmap.h" #include "qtextdocument.h" @@ -69,10 +68,6 @@ public: int currAlign; inline QSplashScreenPrivate(); - - void setPixmap(const QPixmap &p, const QScreen *screen = nullptr); - - static const QScreen *screenFor(const QWidget *w); }; /*! @@ -153,7 +148,9 @@ QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) QSplashScreen::QSplashScreen(QScreen *screen, const QPixmap &pixmap, Qt::WindowFlags f) : QWidget(*(new QSplashScreenPrivate()), nullptr, Qt::SplashScreen | Qt::FramelessWindowHint | f) { - d_func()->setPixmap(pixmap, screen); + Q_D(QSplashScreen); + d->setScreen(screen); + setPixmap(pixmap); } /*! @@ -283,52 +280,16 @@ void QSplashScreen::finish(QWidget *mainWin) */ void QSplashScreen::setPixmap(const QPixmap &pixmap) { - d_func()->setPixmap(pixmap, QSplashScreenPrivate::screenFor(this)); -} - -// In setPixmap(), resize and try to position on a screen according to: -// 1) If the screen for the given widget is available, use that -// 2) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on -// QSplashScreen(QWidget *, QPixmap). -// 3) If a widget with associated QWindow is found, use that -// 4) When nothing can be found, try to center it over the cursor - -const QScreen *QSplashScreenPrivate::screenFor(const QWidget *w) -{ - if (w && w->screen()) - return w->screen(); - - for (const QWidget *p = w; p !=nullptr ; p = p->parentWidget()) { - if (auto dsw = qobject_cast(p)) - return dsw->screen(); - if (QWindow *window = p->windowHandle()) - return window->screen(); - } - -#if QT_CONFIG(cursor) - // Note: We could rely on QPlatformWindow::initialGeometry() to center it - // over the cursor, but not all platforms (namely Android) use that. - if (QGuiApplication::screens().size() > 1) { - if (auto screenAtCursor = QGuiApplication::screenAt(QCursor::pos())) - return screenAtCursor; - } -#endif // cursor - return QGuiApplication::primaryScreen(); -} - -void QSplashScreenPrivate::setPixmap(const QPixmap &p, const QScreen *screen) -{ - Q_Q(QSplashScreen); + Q_D(QSplashScreen); + d->pixmap = pixmap; + setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha()); - pixmap = p; - q->setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha()); + const QRect r(QPoint(), pixmap.size() / pixmap.devicePixelRatio()); + resize(r.size()); - QRect r(QPoint(), pixmap.size() / pixmap.devicePixelRatio()); - q->resize(r.size()); - if (screen) - q->move(screen->geometry().center() - r.center()); - if (q->isVisible()) - q->repaint(); + move(screen()->geometry().center() - r.center()); + if (isVisible()) + repaint(); } /*! -- cgit v1.2.3