summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget_p.h
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-16 20:43:34 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-06-08 20:29:49 +0200
commit44fb925f50471ebc23dcccfaa4e9d9873b05d205 (patch)
treee4e212052b66242ff94aa98f6df7b15dbeb945f7 /src/widgets/kernel/qwidget_p.h
parenta061a646429c6e9d695458fc0ecb0021a30e12ee (diff)
Phase 2 of removing QDesktopWidget
Remove QDestopWidget public header, simplify the implementation that maintains a Qt::Desktop type QWidget for each QScreen, and turn QWidget's initial target screen into a QScreen pointer. QApplication::desktop() now takes an optional QScreen pointer, and returns a QWidget pointer, so that applications and widgets can get access to the root widget for a specific screen without having to resort to private APIs. QDesktopWidgetPrivate implementations to look up a screen for an index, widget, or point are now all inline functions that thinly wrap QGuiApplication::screens/screenAt calls. We should consider adding those as convenience APIs to QScreen instead. Note that QWidget::screen is assumed to return a valid pointer; there is code that handles the case that it returns nullptr (but also code that trusts that it never is nullptr), so this needs to be defined, verified with tests, and asserted. We can then simplify the code further. Change-Id: Ifc89be65a0dce265b6729feaf54121c35137cb94 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets/kernel/qwidget_p.h')
-rw-r--r--src/widgets/kernel/qwidget_p.h36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 3e52a6ad2f..08954cc778 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -61,6 +61,7 @@
#include "QtGui/qinputmethod.h"
#include "QtGui/qopengl.h"
#include "QtGui/qsurfaceformat.h"
+#include "QtGui/qscreen.h"
#include "QtWidgets/qsizepolicy.h"
#include "QtWidgets/qstyle.h"
#include "QtWidgets/qapplication.h"
@@ -144,8 +145,7 @@ struct QTLWExtra {
QRect frameStrut;
QRect normalGeometry; // used by showMin/maximized/FullScreen
Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
- // ### TODO replace initialScreenIndex with QScreen *, in case the screens change at runtime
- int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent.
+ QScreen *initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent.
#ifndef QT_NO_OPENGL
std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures;
@@ -476,13 +476,11 @@ public:
void setModal_sys();
- // This is an helper function that return the available geometry for
- // a widget and takes care is this one is in QGraphicsView.
- // If the widget is not embed in a scene then the geometry available is
- // null, we let QDesktopWidget decide for us.
- static QRect screenGeometry(const QWidget *widget)
+ // These helper functions return the (available) geometry for the screen
+ // the widget is on, and takes care if this one is embedded in a QGraphicsView.
+ static QRect graphicsViewParentRect(const QWidget *widget)
{
- QRect screen;
+ QRect rect;
#if QT_CONFIG(graphicsview)
QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
//It's embedded if it has an ancestor
@@ -491,16 +489,30 @@ public:
// One view, let be smart and return the viewport rect then the popup is aligned
if (ancestorProxy->scene()->views().size() == 1) {
QGraphicsView *view = ancestorProxy->scene()->views().at(0);
- screen = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
+ rect = view->mapToScene(view->viewport()->rect()).boundingRect().toRect();
} else {
- screen = ancestorProxy->scene()->sceneRect().toRect();
+ rect = ancestorProxy->scene()->sceneRect().toRect();
}
}
}
#else
Q_UNUSED(widget);
#endif
- return screen;
+ return rect;
+ }
+ static QRect screenGeometry(const QWidget *widget)
+ {
+ QRect rect = graphicsViewParentRect(widget);
+ if (rect.isNull())
+ rect = widget->screen()->geometry();
+ return rect;
+ }
+ static QRect availableScreenGeometry(const QWidget *widget)
+ {
+ QRect rect = graphicsViewParentRect(widget);
+ if (rect.isNull())
+ rect = widget->screen()->availableGeometry();
+ return rect;
}
inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)