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/dialogs/qcolordialog.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/widgets/dialogs/qcolordialog.cpp') diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 8e5895f48b..30c81f8c0e 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -40,7 +40,6 @@ #include "qcolordialog.h" #include "qapplication.h" -#include #include "qdrawutil.h" #include "qevent.h" #include "qimage.h" @@ -1564,9 +1563,11 @@ bool QColorDialogPrivate::selectColor(const QColor &col) QColor QColorDialogPrivate::grabScreenColor(const QPoint &p) { - const QWidget *desktop = QApplication::desktop(); - const QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1); - QImage i = pixmap.toImage(); + QScreen *screen = QGuiApplication::screenAt(p); + if (!screen) + screen = QGuiApplication::primaryScreen(); + const QPixmap pixmap = screen->grabWindow(0, p.x(), p.y(), 1, 1); + const QImage i = pixmap.toImage(); return i.pixel(0, 0); } @@ -1758,7 +1759,7 @@ void QColorDialogPrivate::initWidgets() } else { // better color picker size for small displays #if defined(QT_SMALL_COLORDIALOG) - QSize screenSize = QDesktopWidgetPrivate::availableGeometry(QCursor::pos()).size(); + QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size(); pWidth = pHeight = qMin(screenSize.width(), screenSize.height()); pHeight -= 20; if(screenSize.height() > screenSize.width()) -- cgit v1.2.3