summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwhatsthis.cpp
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/kernel/qwhatsthis.cpp
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/kernel/qwhatsthis.cpp')
-rw-r--r--src/widgets/kernel/qwhatsthis.cpp45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp
index c5a9989837..7ca50f9dab 100644
--- a/src/widgets/kernel/qwhatsthis.cpp
+++ b/src/widgets/kernel/qwhatsthis.cpp
@@ -41,7 +41,7 @@
#include "qpointer.h"
#include "qapplication.h"
#include <private/qguiapplication_p.h>
-#include <private/qdesktopwidget_p.h>
+#include "qwidget.h"
#include "qevent.h"
#include "qpixmap.h"
#include "qscreen.h"
@@ -235,8 +235,7 @@ QWhatsThat::~QWhatsThat()
void QWhatsThat::showEvent(QShowEvent *)
{
- background = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->internalWinId(),
- x(), y(), width(), height());
+ background = QGuiApplication::primaryScreen()->grabWindow(0, x(), y(), width(), height());
}
void QWhatsThat::mousePressEvent(QMouseEvent* e)
@@ -579,16 +578,16 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
QWhatsThat *whatsThat = new QWhatsThat(text, nullptr, widget);
// okay, now to find a suitable location
- int scr = (widget ?
- QDesktopWidgetPrivate::screenNumber(widget) :
- QDesktopWidgetPrivate::screenNumber(QPoint(x,y))
- );
- QRect screen = QDesktopWidgetPrivate::screenGeometry(scr);
+ QScreen *screen = widget ? widget->screen()
+ : QGuiApplication::screenAt(QPoint(x, y));
+ if (!screen)
+ screen = QGuiApplication::primaryScreen();
+ QRect screenRect = screen->geometry();
int w = whatsThat->width();
int h = whatsThat->height();
- int sx = screen.x();
- int sy = screen.y();
+ int sx = screenRect.x();
+ int sy = screenRect.y();
// first try locating the widget immediately above/below,
// with nice alignment if possible.
@@ -601,13 +600,13 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
else
x = x - w/2;
- // squeeze it in if that would result in part of what's this
- // being only partially visible
- if (x + w + shadowWidth > sx+screen.width())
- x = (widget? (qMin(screen.width(),
- pos.x() + widget->width())
- ) : screen.width())
+ // squeeze it in if that would result in part of what's this
+ // being only partially visible
+ if (x + w + shadowWidth > sx+screenRect.width()) {
+ x = (widget ? qMin(screenRect.width(), pos.x() + widget->width())
+ : screenRect.width())
- w;
+ }
if (x < sx)
x = sx;
@@ -615,18 +614,18 @@ void QWhatsThisPrivate::say(QWidget * widget, const QString &text, int x, int y)
if (widget && h > widget->height() + 16) {
y = pos.y() + widget->height() + 2; // below, two pixels spacing
// what's this is above or below, wherever there's most space
- if (y + h + 10 > sy+screen.height())
+ if (y + h + 10 > sy + screenRect.height())
y = pos.y() + 2 - shadowWidth - h; // above, overlap
}
y = y + 2;
- // squeeze it in if that would result in part of what's this
- // being only partially visible
- if (y + h + shadowWidth > sy+screen.height())
- y = (widget ? (qMin(screen.height(),
- pos.y() + widget->height())
- ) : screen.height())
+ // squeeze it in if that would result in part of what's this
+ // being only partially visible
+ if (y + h + shadowWidth > sy + screenRect.height()) {
+ y = (widget ? qMin(screenRect.height(), pos.y() + widget->height())
+ : screenRect.height())
- h;
+ }
if (y < sy)
y = sy;