summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-06 17:22:12 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-07 11:49:32 +0200
commit7e2fded55e67727043c3dd0a1a5b3883655101c4 (patch)
treee7ba2ab69ebe9077be9614f574f7f2dc1d375a79 /src/widgets/dialogs
parentbcbc4d4de2d4d27f70fc56baf104d93b31d57061 (diff)
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 <shawn.rutledge@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp11
-rw-r--r--src/widgets/dialogs/qdialog.cpp25
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp3
-rw-r--r--src/widgets/dialogs/qwizard.cpp1
4 files changed, 19 insertions, 21 deletions
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 <private/qdesktopwidget_p.h>
#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())
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 0f0e213e71..52976611aa 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -49,7 +49,6 @@
#endif
#include "qevent.h"
-#include <private/qdesktopwidget_p.h>
#include "qapplication.h"
#include "qlayout.h"
#if QT_CONFIG(sizegrip)
@@ -872,23 +871,23 @@ void QDialog::showEvent(QShowEvent *event)
/*! \internal */
void QDialog::adjustPosition(QWidget* w)
{
-
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
if (theme->themeHint(QPlatformTheme::WindowAutoPlacement).toBool())
return;
QPoint p(0, 0);
- int extraw = 0, extrah = 0, scrn = 0;
+ int extraw = 0, extrah = 0;
if (w)
w = w->window();
QRect desk;
- if (w) {
- scrn = QDesktopWidgetPrivate::screenNumber(w);
- } else if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1) {
- scrn = QDesktopWidgetPrivate::screenNumber(QCursor::pos());
- } else {
- scrn = QDesktopWidgetPrivate::screenNumber(this);
- }
- desk = QDesktopWidgetPrivate::availableGeometry(scrn);
+ QScreen *scrn = nullptr;
+ if (w)
+ scrn = w->screen();
+ else if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1)
+ scrn = QGuiApplication::screenAt(QCursor::pos());
+ else
+ scrn = screen();
+ if (scrn)
+ desk = scrn->availableGeometry();
QWidgetList list = QApplication::topLevelWidgets();
for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) {
@@ -942,9 +941,9 @@ void QDialog::adjustPosition(QWidget* w)
// QTBUG-52735: Manually set the correct target screen since scaling in a
// subsequent call to QWindow::resize() may otherwise use the wrong factor
// if the screen changed notification is still in an event queue.
- if (scrn >= 0) {
+ if (scrn) {
if (QWindow *window = windowHandle())
- window->setScreen(QGuiApplication::screens().at(scrn));
+ window->setScreen(scrn);
}
move(p);
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index e0edc2f755..22d86b301a 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -64,7 +64,6 @@
#include <QtGui/qfontmetrics.h>
#include <QtGui/qclipboard.h>
#include "private/qabstractbutton_p.h"
-#include <private/qdesktopwidget_p.h>
#ifdef Q_OS_WIN
# include <QtCore/qt_windows.h>
@@ -363,7 +362,7 @@ void QMessageBoxPrivate::updateSize()
if (!q->isVisible())
return;
- QSize screenSize = QDesktopWidgetPrivate::availableGeometry(QCursor::pos()).size();
+ const QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size();
int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
// on small screens allows the messagebox be the same size as the screen
if (screenSize.width() <= 1024)
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 0860f9defe..2548a668ce 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -47,7 +47,6 @@
#include "qapplication.h"
#include "qboxlayout.h"
#include "qlayoutitem.h"
-#include <private/qdesktopwidget_p.h>
#include "qevent.h"
#include "qframe.h"
#include "qlabel.h"