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/util/qcompleter.cpp | 2 +- src/widgets/util/qscroller.cpp | 1 - src/widgets/util/qsystemtrayicon.cpp | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/widgets/util') diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 3083889954..cdd06f4790 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -158,7 +158,7 @@ #include "QtWidgets/qapplication.h" #include "QtGui/qevent.h" #include -#include +#include #if QT_CONFIG(lineedit) #include "QtWidgets/qlineedit.h" #endif diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp index 003f27de56..b94d8f4b81 100644 --- a/src/widgets/util/qscroller.cpp +++ b/src/widgets/util/qscroller.cpp @@ -57,7 +57,6 @@ #include #include #endif -#include #include #include #include diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index 9e49b1ec57..556427387f 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -60,7 +60,6 @@ #include "qstyle.h" #include "qgridlayout.h" #include "qapplication.h" -#include #include "qbitmap.h" #include @@ -599,12 +598,15 @@ void QBalloonTip::resizeEvent(QResizeEvent *ev) void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) { this->showArrow = showArrow; - QRect scr = QDesktopWidgetPrivate::screenGeometry(pos); + QScreen *screen = QGuiApplication::screenAt(pos); + if (!screen) + screen = QGuiApplication::primaryScreen(); + QRect screenRect = screen->geometry(); QSize sh = sizeHint(); const int border = 1; const int ah = 18, ao = 18, aw = 18, rc = 7; - bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height()); - bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width()); + bool arrowAtTop = (pos.y() + sh.height() + ah < screenRect.height()); + bool arrowAtLeft = (pos.x() + sh.width() - ao < screenRect.width()); setContentsMargins(border + 3, border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2); updateGeometry(); sh = sizeHint(); @@ -630,14 +632,14 @@ void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) path.lineTo(ml + ao, mt - ah); path.lineTo(ml + ao + aw, mt); } - move(qMax(pos.x() - ao, scr.left() + 2), pos.y()); + move(qMax(pos.x() - ao, screenRect.left() + 2), pos.y()); } else if (arrowAtTop && !arrowAtLeft) { if (showArrow) { path.lineTo(mr - ao - aw, mt); path.lineTo(mr - ao, mt - ah); path.lineTo(mr - ao, mt); } - move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y()); + move(qMin(pos.x() - sh.width() + ao, screenRect.right() - sh.width() - 2), pos.y()); } path.lineTo(mr - rc, mt); path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90); @@ -649,7 +651,7 @@ void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) path.lineTo(mr - ao, mb + ah); path.lineTo(mr - ao - aw, mb); } - move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), + move(qMin(pos.x() - sh.width() + ao, screenRect.right() - sh.width() - 2), pos.y() - sh.height()); } else if (!arrowAtTop && arrowAtLeft) { if (showArrow) { @@ -657,7 +659,7 @@ void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) path.lineTo(ao, mb + ah); path.lineTo(ao, mb); } - move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height()); + move(qMax(pos.x() - ao, screenRect.x() + 2), pos.y() - sh.height()); } path.lineTo(ml + rc, mb); path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90); -- cgit v1.2.3