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>
This commit is contained in:
parent
a061a64642
commit
44fb925f50
@ -49,7 +49,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
|
@ -56,7 +56,6 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QPushButton>
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include <QPainter>
|
||||
#include <QSlider>
|
||||
#include <QLabel>
|
||||
#include <QDesktopWidget>
|
||||
#include <qmath.h>
|
||||
|
||||
PathDeformControls::PathDeformControls(QWidget *parent,
|
||||
|
@ -55,7 +55,6 @@
|
||||
#include <QBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFontComboBox>
|
||||
|
@ -344,8 +344,6 @@ QString QPlatformScreen::serialNumber() const
|
||||
physicalSize() function, since this is the function it uses to calculate the dpi to use when
|
||||
converting point sizes to pixels sizes. However, this is unfortunate on some systems, as the
|
||||
native system fakes its dpi size.
|
||||
|
||||
QPlatformScreen is also used by the public api QDesktopWidget for information about the desktop.
|
||||
*/
|
||||
|
||||
/*! \fn QRect QPlatformScreen::geometry() const = 0
|
||||
|
@ -56,7 +56,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QDesktopWidget;
|
||||
class QAndroidPlatformServices;
|
||||
class QAndroidSystemLocale;
|
||||
class QPlatformAccessibility;
|
||||
|
@ -120,7 +120,7 @@ static bool monitorData(HMONITOR hMonitor, QWindowsScreenData *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
// from QDesktopWidget, taking WindowsScreenDataList as LPARAM
|
||||
// from monitorData, taking WindowsScreenDataList as LPARAM
|
||||
BOOL QT_WIN_CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM p)
|
||||
{
|
||||
QWindowsScreenData data;
|
||||
|
@ -662,7 +662,6 @@ QT_CLASS_LIB(QClipboard, QtGui, qclipboard.h)
|
||||
QT_CLASS_LIB(QCursor, QtGui, qcursor.h)
|
||||
QT_CLASS_LIB(QCursor, QtGui, qcursor.h)
|
||||
QT_CLASS_LIB(QCursorShape, QtWidgets, qcursor.h)
|
||||
QT_CLASS_LIB(QDesktopWidget, QtWidgets, qdesktopwidget.h)
|
||||
QT_CLASS_LIB(QDrag, QtWidgets, qdrag.h)
|
||||
QT_CLASS_LIB(QtEvents, QtGui, qevent.h)
|
||||
QT_CLASS_LIB(QInputEvent, QtGui, qevent.h)
|
||||
|
@ -12,7 +12,7 @@ qt_add_module(Widgets
|
||||
itemviews/qfileiconprovider.cpp itemviews/qfileiconprovider.h itemviews/qfileiconprovider_p.h
|
||||
kernel/qapplication.cpp kernel/qapplication.h kernel/qapplication_p.h
|
||||
kernel/qboxlayout.cpp kernel/qboxlayout.h
|
||||
kernel/qdesktopwidget.cpp kernel/qdesktopwidget.h kernel/qdesktopwidget_p.h
|
||||
kernel/qdesktopwidget.cpp kernel/qdesktopwidget_p.h
|
||||
kernel/qgesture.cpp kernel/qgesture.h kernel/qgesture_p.h
|
||||
kernel/qgesturemanager.cpp kernel/qgesturemanager_p.h
|
||||
kernel/qgesturerecognizer.cpp kernel/qgesturerecognizer.h
|
||||
|
@ -12,7 +12,7 @@ qt_add_module(Widgets
|
||||
itemviews/qfileiconprovider.cpp itemviews/qfileiconprovider.h itemviews/qfileiconprovider_p.h
|
||||
kernel/qapplication.cpp kernel/qapplication.h kernel/qapplication_p.h
|
||||
kernel/qboxlayout.cpp kernel/qboxlayout.h
|
||||
kernel/qdesktopwidget.cpp kernel/qdesktopwidget.h kernel/qdesktopwidget_p.h
|
||||
kernel/qdesktopwidget.cpp kernel/qdesktopwidget_p.h
|
||||
kernel/qgesture.cpp kernel/qgesture.h kernel/qgesture_p.h
|
||||
kernel/qgesturemanager.cpp kernel/qgesturemanager_p.h
|
||||
kernel/qgesturerecognizer.cpp kernel/qgesturerecognizer.h
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "qcolordialog.h"
|
||||
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qdrawutil.h"
|
||||
#include "qevent.h"
|
||||
@ -1565,7 +1564,7 @@ bool QColorDialogPrivate::selectColor(const QColor &col)
|
||||
|
||||
QColor QColorDialogPrivate::grabScreenColor(const QPoint &p)
|
||||
{
|
||||
const QDesktopWidget *desktop = QApplication::desktop();
|
||||
const QWidget *desktop = QApplication::desktop();
|
||||
const QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
|
||||
QImage i = pixmap.toImage();
|
||||
return i.pixel(0, 0);
|
||||
|
@ -49,7 +49,6 @@
|
||||
#endif
|
||||
|
||||
#include "qevent.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qapplication.h"
|
||||
#include "qlayout.h"
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include <QtWidgets/qstyle.h>
|
||||
#include <QtWidgets/qstyleoption.h>
|
||||
#include <QtWidgets/qgridlayout.h>
|
||||
#include <QtWidgets/qdesktopwidget.h>
|
||||
#include <QtWidgets/qpushbutton.h>
|
||||
#include <QtWidgets/qcheckbox.h>
|
||||
#include <QtGui/qaccessible.h>
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "qapplication.h"
|
||||
#include "qboxlayout.h"
|
||||
#include "qlayoutitem.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qevent.h"
|
||||
#include "qframe.h"
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
|
||||
#include <uxtheme.h>
|
||||
#include <vssym32.h>
|
||||
|
@ -226,7 +226,6 @@
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#include <QtCore/QMetaMethod>
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtWidgets/qdesktopwidget.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtWidgets/qgraphicslayout.h>
|
||||
#include <QtWidgets/qgraphicsproxywidget.h>
|
||||
|
@ -285,8 +285,6 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/qscopedvaluerollback.h>
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtWidgets/qdesktopwidget.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtWidgets/qlayout.h>
|
||||
#include <QtGui/qtransform.h>
|
||||
|
@ -11,7 +11,6 @@ HEADERS += \
|
||||
kernel/qapplication_p.h \
|
||||
kernel/qwidgetrepaintmanager_p.h \
|
||||
kernel/qboxlayout.h \
|
||||
kernel/qdesktopwidget.h \
|
||||
kernel/qgridlayout.h \
|
||||
kernel/qlayout.h \
|
||||
kernel/qlayout_p.h \
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "qapplication.h"
|
||||
#include "qclipboard.h"
|
||||
#include "qcursor.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include "qdesktopwidget_p.h"
|
||||
#include "qdir.h"
|
||||
#include "qevent.h"
|
||||
#include "qfile.h"
|
||||
@ -2521,22 +2521,30 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget)
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Returns the desktop widget (also called the root window).
|
||||
Returns the desktop widget (also called the root window) for \a screen.
|
||||
|
||||
If \a screen is nullptr, then the widget that represents the entire virtual
|
||||
desktop is returned, and its geometry will be the union of all screens.
|
||||
|
||||
Use the desktop widget for a specific screen as the parent of a new toplevel
|
||||
widget to position the widget on a specific screen.
|
||||
|
||||
The desktop may be composed of multiple screens, so it would be incorrect,
|
||||
for example, to attempt to \e center some widget in the desktop's geometry.
|
||||
QDesktopWidget has various functions for obtaining useful geometries upon
|
||||
the desktop, such as QDesktopWidget::screenGeometry() and
|
||||
QDesktopWidget::availableGeometry().
|
||||
Use QScreen::geometry() and QScreen::availableGeometry() to get the dimensions
|
||||
of a specific screen instead.
|
||||
*/
|
||||
QDesktopWidget *QApplication::desktop()
|
||||
QWidget *QApplication::desktop(QScreen *screen)
|
||||
{
|
||||
CHECK_QAPP_INSTANCE(nullptr)
|
||||
if (!qt_desktopWidget || // not created yet
|
||||
!(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
|
||||
qt_desktopWidget = new QDesktopWidget();
|
||||
}
|
||||
return qt_desktopWidget;
|
||||
if (!screen)
|
||||
return qt_desktopWidget;
|
||||
QDesktopWidgetPrivate *dwp = static_cast<QDesktopWidgetPrivate*>(qt_widget_private(qt_desktopWidget));
|
||||
return dwp->widgetForScreen(screen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -51,7 +51,6 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
class QDesktopWidget;
|
||||
class QStyle;
|
||||
class QEventLoop;
|
||||
class QIcon;
|
||||
@ -106,7 +105,7 @@ public:
|
||||
static QWidgetList allWidgets();
|
||||
static QWidgetList topLevelWidgets();
|
||||
|
||||
static QDesktopWidget *desktop();
|
||||
static QWidget *desktop(QScreen *screen = nullptr);
|
||||
|
||||
static QWidget *activePopupWidget();
|
||||
static QWidget *activeModalWidget();
|
||||
|
@ -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.
|
||||
@ -38,7 +38,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "qglobal.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include "qdesktopwidget_p.h"
|
||||
#include "qscreen.h"
|
||||
#include "qwidget_p.h"
|
||||
@ -50,109 +49,66 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QDesktopScreenWidget::QDesktopScreenWidget(QScreen *screen, const QRect &geometry)
|
||||
: QWidget(nullptr, Qt::Desktop), m_screen(screen)
|
||||
: QWidget(nullptr, Qt::Desktop)
|
||||
{
|
||||
setVisible(false);
|
||||
if (QWindow *winHandle = windowHandle())
|
||||
winHandle->setScreen(screen);
|
||||
setScreenGeometry(geometry);
|
||||
}
|
||||
|
||||
void QDesktopScreenWidget::setScreenGeometry(const QRect &geometry)
|
||||
{
|
||||
m_geometry = geometry;
|
||||
setGeometry(geometry);
|
||||
}
|
||||
|
||||
int QDesktopScreenWidget::screenNumber() const
|
||||
QScreen *QDesktopScreenWidget::screen() const
|
||||
{
|
||||
const QDesktopWidgetPrivate *desktopWidgetP
|
||||
= static_cast<const QDesktopWidgetPrivate *>(qt_widget_private(QApplication::desktop()));
|
||||
return desktopWidgetP->screens.indexOf(const_cast<QDesktopScreenWidget *>(this));
|
||||
}
|
||||
|
||||
const QRect QDesktopWidgetPrivate::screenGeometry(const QWidget *widget)
|
||||
{
|
||||
if (Q_UNLIKELY(!widget)) {
|
||||
qWarning("QDesktopWidget::screenGeometry(): Attempt "
|
||||
"to get the screen geometry of a null widget");
|
||||
return QRect();
|
||||
}
|
||||
QRect rect = QWidgetPrivate::screenGeometry(widget);
|
||||
if (rect.isNull())
|
||||
return screenGeometry(screenNumber(widget));
|
||||
else return rect;
|
||||
}
|
||||
|
||||
const QRect QDesktopWidgetPrivate::availableGeometry(const QWidget *widget)
|
||||
{
|
||||
if (Q_UNLIKELY(!widget)) {
|
||||
qWarning("QDesktopWidget::availableGeometry(): Attempt "
|
||||
"to get the available geometry of a null widget");
|
||||
return QRect();
|
||||
}
|
||||
QRect rect = QWidgetPrivate::screenGeometry(widget);
|
||||
if (rect.isNull())
|
||||
return availableGeometry(screenNumber(widget));
|
||||
else
|
||||
return rect;
|
||||
}
|
||||
|
||||
QDesktopScreenWidget *QDesktopWidgetPrivate::widgetForScreen(QScreen *qScreen) const
|
||||
{
|
||||
foreach (QDesktopScreenWidget *widget, screens) {
|
||||
if (widget->assignedScreen() == qScreen)
|
||||
return widget;
|
||||
for (auto it : qAsConst(desktopWidgetP->screenWidgets)) {
|
||||
if (it.second == this)
|
||||
return it.first;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void QDesktopWidgetPrivate::_q_updateScreens()
|
||||
QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
|
||||
{
|
||||
qDeleteAll(screenWidgets.values());
|
||||
}
|
||||
|
||||
void QDesktopWidgetPrivate::updateScreens()
|
||||
{
|
||||
Q_Q(QDesktopWidget);
|
||||
const QList<QScreen *> screenList = QGuiApplication::screens();
|
||||
const int targetLength = screenList.length();
|
||||
|
||||
// Re-build our screens list. This is the easiest way to later compute which signals to emit.
|
||||
// Create new screen widgets as necessary. While iterating, keep the old list in place so
|
||||
// that widgetForScreen works.
|
||||
// Create new screen widgets as necessary.
|
||||
// Furthermore, we note which screens have changed, and compute the overall virtual geometry.
|
||||
QList<QDesktopScreenWidget *> newScreens;
|
||||
QList<int> changedScreens;
|
||||
QFlatMap<QScreen*, QDesktopScreenWidget*> newScreenWidgets;
|
||||
QRegion virtualGeometry;
|
||||
|
||||
for (int i = 0; i < targetLength; ++i) {
|
||||
QScreen *qScreen = screenList.at(i);
|
||||
const QRect screenGeometry = qScreen->geometry();
|
||||
QDesktopScreenWidget *screenWidget = widgetForScreen(qScreen);
|
||||
if (screenWidget) {
|
||||
// an old screen. update geometry and remember the index in the *new* list
|
||||
if (screenGeometry != screenWidget->screenGeometry()) {
|
||||
screenWidget->setScreenGeometry(screenGeometry);
|
||||
changedScreens.push_back(i);
|
||||
}
|
||||
} else {
|
||||
for (QScreen *screen : screenList) {
|
||||
const QRect screenGeometry = screen->geometry();
|
||||
QDesktopScreenWidget *screenWidget = screenWidgets.value(screen);
|
||||
if (!screenWidget) {
|
||||
// a new screen, create a widget and connect the signals.
|
||||
screenWidget = new QDesktopScreenWidget(qScreen, screenGeometry);
|
||||
QObject::connect(qScreen, SIGNAL(geometryChanged(QRect)),
|
||||
q, SLOT(_q_updateScreens()), Qt::QueuedConnection);
|
||||
QObject::connect(qScreen, SIGNAL(destroyed()),
|
||||
q, SLOT(_q_updateScreens()), Qt::QueuedConnection);
|
||||
screenWidget = new QDesktopScreenWidget(screen, screenGeometry);
|
||||
QObjectPrivate::connect(screen, &QScreen::geometryChanged,
|
||||
this, &QDesktopWidgetPrivate::updateScreens, Qt::QueuedConnection);
|
||||
QObjectPrivate::connect(screen, &QObject::destroyed,
|
||||
this, &QDesktopWidgetPrivate::updateScreens, Qt::QueuedConnection);
|
||||
}
|
||||
// record all the screens and the overall geometry.
|
||||
newScreens.push_back(screenWidget);
|
||||
newScreenWidgets.insert(screen, screenWidget);
|
||||
virtualGeometry += screenGeometry;
|
||||
}
|
||||
|
||||
// Now we apply the accumulated updates.
|
||||
screens.swap(newScreens); // now [newScreens] is the old screen list
|
||||
Q_ASSERT(screens.size() == targetLength);
|
||||
qSwap(screenWidgets, newScreenWidgets); // now [newScreenWidgets] is the old screen list
|
||||
Q_ASSERT(screenWidgets.size() == screenList.length());
|
||||
q->setGeometry(virtualGeometry.boundingRect());
|
||||
|
||||
// Delete the QDesktopScreenWidget that are not used any more.
|
||||
foreach (QDesktopScreenWidget *screen, newScreens) {
|
||||
if (!screens.contains(screen))
|
||||
delete screen;
|
||||
for (auto it : qAsConst(newScreenWidgets)) {
|
||||
if (!screenWidgets.contains(it.first))
|
||||
delete it.second;
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,90 +117,12 @@ QDesktopWidget::QDesktopWidget()
|
||||
{
|
||||
Q_D(QDesktopWidget);
|
||||
setObjectName(QLatin1String("desktop"));
|
||||
d->_q_updateScreens();
|
||||
connect(qApp, SIGNAL(screenAdded(QScreen*)), this, SLOT(_q_updateScreens()));
|
||||
d->updateScreens();
|
||||
QObjectPrivate::connect(qApp, &QApplication::screenAdded, d, &QDesktopWidgetPrivate::updateScreens);
|
||||
}
|
||||
|
||||
QDesktopWidget::~QDesktopWidget()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *QDesktopWidget::screen(int screen)
|
||||
{
|
||||
Q_D(QDesktopWidget);
|
||||
if (screen < 0 || screen >= d->screens.length())
|
||||
return d->screens.at(0);
|
||||
return d->screens.at(screen);
|
||||
}
|
||||
|
||||
const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo)
|
||||
{
|
||||
const QScreen *screen = QDesktopWidgetPrivate::screen(screenNo);
|
||||
return screen ? screen->availableGeometry() : QRect();
|
||||
}
|
||||
|
||||
const QRect QDesktopWidgetPrivate::screenGeometry(int screenNo)
|
||||
{
|
||||
const QScreen *screen = QDesktopWidgetPrivate::screen(screenNo);
|
||||
return screen ? screen->geometry() : QRect();
|
||||
}
|
||||
|
||||
int QDesktopWidgetPrivate::screenNumber(const QWidget *w)
|
||||
{
|
||||
if (!w)
|
||||
return 0;
|
||||
|
||||
const QList<QScreen *> allScreens = QGuiApplication::screens();
|
||||
QList<QScreen *> screens = allScreens;
|
||||
if (screens.isEmpty()) // This should never happen
|
||||
return 0;
|
||||
|
||||
// If there is more than one virtual desktop
|
||||
if (screens.count() != screens.constFirst()->virtualSiblings().count()) {
|
||||
// Find the root widget, get a QScreen from it and use the
|
||||
// virtual siblings for checking the window position.
|
||||
if (const QScreen *winScreen = qt_widget_private(const_cast<QWidget *>(w))->associatedScreen())
|
||||
screens = winScreen->virtualSiblings();
|
||||
}
|
||||
|
||||
// Get the screen number from window position using screen geometry
|
||||
// and proper screens.
|
||||
QRect frame = w->frameGeometry();
|
||||
if (!w->isWindow())
|
||||
frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0)));
|
||||
|
||||
QScreen *widgetScreen = nullptr;
|
||||
int largestArea = 0;
|
||||
foreach (QScreen *screen, screens) {
|
||||
const QRect deviceIndependentScreenGeometry =
|
||||
QHighDpi::fromNativePixels(screen->handle()->geometry(), screen);
|
||||
const QRect intersected = deviceIndependentScreenGeometry.intersected(frame);
|
||||
int area = intersected.width() * intersected.height();
|
||||
if (largestArea < area) {
|
||||
widgetScreen = screen;
|
||||
largestArea = area;
|
||||
}
|
||||
}
|
||||
return allScreens.indexOf(widgetScreen);
|
||||
}
|
||||
|
||||
int QDesktopWidgetPrivate::screenNumber(const QPoint &p)
|
||||
{
|
||||
QScreen *screen = QGuiApplication::screenAt(p);
|
||||
return screen ? QGuiApplication::screens().indexOf(screen) : 0;
|
||||
}
|
||||
|
||||
QScreen *QDesktopWidgetPrivate::screen(int screenNo)
|
||||
{
|
||||
QList<QScreen *> screens = QGuiApplication::screens();
|
||||
if (screenNo == -1)
|
||||
screenNo = 0;
|
||||
if (screenNo < 0 || screenNo >= screens.size())
|
||||
return nullptr;
|
||||
return screens.at(screenNo);
|
||||
}
|
||||
QDesktopWidget::~QDesktopWidget() = default;
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qdesktopwidget.cpp"
|
||||
#include "moc_qdesktopwidget_p.cpp"
|
||||
|
@ -1,72 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDESKTOPWIDGET_H
|
||||
#define QDESKTOPWIDGET_H
|
||||
|
||||
#include <QtWidgets/qtwidgetsglobal.h>
|
||||
#include <QtWidgets/qwidget.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
class QApplication;
|
||||
class QDesktopWidgetPrivate;
|
||||
|
||||
class Q_WIDGETS_EXPORT QDesktopWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QDesktopWidget();
|
||||
~QDesktopWidget();
|
||||
|
||||
QT_DEPRECATED_X("Use QScreen") QWidget *screen(int screen = -1);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QDesktopWidget)
|
||||
Q_DECLARE_PRIVATE(QDesktopWidget)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_updateScreens())
|
||||
|
||||
friend class QApplication;
|
||||
friend class QApplicationPrivate;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QDESKTOPWIDGET_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.
|
||||
@ -52,56 +52,96 @@
|
||||
#define QDESKTOPWIDGET_P_H
|
||||
|
||||
#include <QtWidgets/private/qtwidgetsglobal_p.h>
|
||||
#include "QDesktopWidget"
|
||||
#include "private/qwidget_p.h"
|
||||
|
||||
#include <QtCore/qalgorithms.h>
|
||||
#include <QtGui/qscreen.h>
|
||||
#include <QtCore/private/qflatmap_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QDesktopWidgetPrivate;
|
||||
|
||||
class Q_WIDGETS_EXPORT QDesktopWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QDesktopWidget();
|
||||
~QDesktopWidget();
|
||||
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QDesktopWidget)
|
||||
Q_DECLARE_PRIVATE(QDesktopWidget)
|
||||
|
||||
friend class QApplication;
|
||||
friend class QApplicationPrivate;
|
||||
};
|
||||
|
||||
class QDesktopScreenWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QDesktopScreenWidget(QScreen *screen, const QRect &geometry);
|
||||
explicit QDesktopScreenWidget(QScreen *, const QRect &geometry);
|
||||
|
||||
int screenNumber() const;
|
||||
void setScreenGeometry(const QRect &geometry);
|
||||
|
||||
QScreen *assignedScreen() const { return m_screen.data(); }
|
||||
QRect screenGeometry() const { return m_geometry; }
|
||||
|
||||
private:
|
||||
// The widget updates its screen and geometry automatically. We need to save them separately
|
||||
// to detect changes, and trigger the appropriate signals.
|
||||
const QPointer<QScreen> m_screen;
|
||||
QRect m_geometry;
|
||||
QScreen *screen() const;
|
||||
};
|
||||
|
||||
class QDesktopWidgetPrivate : public QWidgetPrivate {
|
||||
Q_DECLARE_PUBLIC(QDesktopWidget)
|
||||
|
||||
public:
|
||||
~QDesktopWidgetPrivate() { qDeleteAll(screens); }
|
||||
void _q_updateScreens();
|
||||
QDesktopScreenWidget *widgetForScreen(QScreen *qScreen) const;
|
||||
~QDesktopWidgetPrivate();
|
||||
void updateScreens();
|
||||
QDesktopScreenWidget *widgetForScreen(QScreen *qScreen) const
|
||||
{
|
||||
return screenWidgets.value(qScreen);
|
||||
}
|
||||
|
||||
static int screenNumber(const QWidget *widget = nullptr);
|
||||
static int screenNumber(const QPoint &);
|
||||
static inline int screenNumber(const QWidget *widget = nullptr)
|
||||
{
|
||||
if (!widget)
|
||||
return 0;
|
||||
return QGuiApplication::screens().indexOf(widget->screen());
|
||||
}
|
||||
|
||||
static QScreen *screen(int screenNo = -1);
|
||||
static inline int screenNumber(const QPoint &point)
|
||||
{
|
||||
int screenNo = 0;
|
||||
if (QScreen *screen = QGuiApplication::screenAt(point))
|
||||
screenNo = QGuiApplication::screens().indexOf(screen);
|
||||
return screenNo;
|
||||
}
|
||||
|
||||
static const QRect screenGeometry(int screen = -1);
|
||||
static const QRect screenGeometry(const QWidget *widget);
|
||||
static const QRect screenGeometry(const QPoint &point)
|
||||
static inline QScreen *screen(int screenNo = -1)
|
||||
{
|
||||
const QList<QScreen *> screens = QGuiApplication::screens();
|
||||
if (screenNo == -1)
|
||||
screenNo = 0;
|
||||
if (screenNo < 0 || screenNo >= screens.size())
|
||||
return nullptr;
|
||||
return screens.at(screenNo);
|
||||
}
|
||||
|
||||
static inline QRect screenGeometry(int screenNo = -1)
|
||||
{
|
||||
QRect rect;
|
||||
if (const QScreen *s = screen(screenNo))
|
||||
rect = s->geometry();
|
||||
return rect;
|
||||
}
|
||||
static inline QRect screenGeometry(const QPoint &point)
|
||||
{ return screenGeometry(screenNumber(point)); }
|
||||
|
||||
static const QRect availableGeometry(int screen = -1);
|
||||
static const QRect availableGeometry(const QWidget *widget);
|
||||
static const QRect availableGeometry(const QPoint &point)
|
||||
static inline QRect availableGeometry(int screenNo = -1)
|
||||
{
|
||||
QRect rect;
|
||||
if (const QScreen *s = screen(screenNo))
|
||||
rect = s->availableGeometry();
|
||||
return rect;
|
||||
}
|
||||
static inline QRect availableGeometry(const QPoint &point)
|
||||
{ return availableGeometry(screenNumber(point)); }
|
||||
|
||||
QList<QDesktopScreenWidget *> screens;
|
||||
QFlatMap<QScreen*, QDesktopScreenWidget*> screenWidgets;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <QtWidgets/private/qtwidgetsglobal_p.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <qevent.h>
|
||||
#include <qpointer.h>
|
||||
@ -139,7 +138,7 @@ public:
|
||||
bool tipChanged(const QPoint &pos, const QString &text, QObject *o);
|
||||
void placeTip(const QPoint &pos, QWidget *w);
|
||||
|
||||
static int getTipScreen(const QPoint &pos, QWidget *w);
|
||||
static QScreen *getTipScreen(const QPoint &pos, QWidget *w);
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
@ -366,12 +365,12 @@ bool QTipLabel::eventFilter(QObject *o, QEvent *e)
|
||||
return false;
|
||||
}
|
||||
|
||||
int QTipLabel::getTipScreen(const QPoint &pos, QWidget *w)
|
||||
QScreen *QTipLabel::getTipScreen(const QPoint &pos, QWidget *w)
|
||||
{
|
||||
if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1)
|
||||
return QDesktopWidgetPrivate::screenNumber(pos);
|
||||
else
|
||||
return QDesktopWidgetPrivate::screenNumber(w);
|
||||
int screenNo = QGuiApplication::primaryScreen()->virtualSiblings().size() > 1
|
||||
? QDesktopWidgetPrivate::screenNumber(pos)
|
||||
: QDesktopWidgetPrivate::screenNumber(w);
|
||||
return QDesktopWidgetPrivate::screen(screenNo);
|
||||
}
|
||||
|
||||
void QTipLabel::placeTip(const QPoint &pos, QWidget *w)
|
||||
@ -396,8 +395,7 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w)
|
||||
#endif //QT_NO_STYLE_STYLESHEET
|
||||
|
||||
QPoint p = pos;
|
||||
const QScreen *screen = QGuiApplication::screens().value(getTipScreen(pos, w),
|
||||
QGuiApplication::primaryScreen());
|
||||
const QScreen *screen = getTipScreen(pos, w);
|
||||
// a QScreen's handle *should* never be null, so this is a bit paranoid
|
||||
if (const QPlatformScreen *platformScreen = screen ? screen->handle() : nullptr) {
|
||||
const QSize cursorSize = QHighDpi::fromNativePixels(platformScreen->cursor()->size(),
|
||||
@ -494,16 +492,18 @@ void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, cons
|
||||
}
|
||||
|
||||
if (!text.isEmpty()){ // no tip can be reused, create new tip:
|
||||
QWidget *tipLabelParent = [pos, w]() -> QWidget* {
|
||||
#ifdef Q_OS_WIN32
|
||||
// On windows, we can't use the widget as parent otherwise the window will be
|
||||
// raised when the tooltip will be shown
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
new QTipLabel(text, pos, QApplication::desktop()->screen(QTipLabel::getTipScreen(pos, w)), msecDisplayTime);
|
||||
QT_WARNING_POP
|
||||
// On windows, we can't use the widget as parent otherwise the window will be
|
||||
// raised when the tooltip will be shown
|
||||
QScreen *screen = QTipLabel::getTipScreen(pos, w);
|
||||
return QApplication::desktop(screen);
|
||||
#else
|
||||
new QTipLabel(text, pos, w, msecDisplayTime); // sets QTipLabel::instance to itself
|
||||
Q_UNUSED(pos);
|
||||
return w;
|
||||
#endif
|
||||
}();
|
||||
new QTipLabel(text, pos, tipLabelParent, msecDisplayTime); // sets QTipLabel::instance to itself
|
||||
QTipLabel::instance->setTipRect(w, rect);
|
||||
QTipLabel::instance->placeTip(pos, w);
|
||||
QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include "qpointer.h"
|
||||
#include "qapplication.h"
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qevent.h"
|
||||
#include "qpixmap.h"
|
||||
|
@ -990,10 +990,10 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
|
||||
if (allWidgets)
|
||||
allWidgets->insert(q);
|
||||
|
||||
int targetScreen = -1;
|
||||
QScreen *targetScreen = nullptr;
|
||||
if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
|
||||
const QDesktopScreenWidget *sw = qobject_cast<const QDesktopScreenWidget *>(parentWidget);
|
||||
targetScreen = sw ? sw->screenNumber() : 0;
|
||||
targetScreen = sw ? sw->screen() : nullptr;
|
||||
parentWidget = nullptr;
|
||||
}
|
||||
|
||||
@ -1006,10 +1006,10 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (targetScreen >= 0) {
|
||||
topData()->initialScreenIndex = targetScreen;
|
||||
if (targetScreen) {
|
||||
topData()->initialScreen = targetScreen;
|
||||
if (QWindow *window = q->windowHandle())
|
||||
window->setScreen(QGuiApplication::screens().value(targetScreen, nullptr));
|
||||
window->setScreen(targetScreen);
|
||||
}
|
||||
|
||||
data.fstrut_dirty = true;
|
||||
@ -1293,13 +1293,13 @@ void QWidgetPrivate::create()
|
||||
else
|
||||
win->resize(q->size());
|
||||
if (win->isTopLevel()) {
|
||||
int screenNumber = topData()->initialScreenIndex;
|
||||
topData()->initialScreenIndex = -1;
|
||||
if (screenNumber < 0) {
|
||||
screenNumber = q->windowType() != Qt::Desktop
|
||||
? QDesktopWidgetPrivate::screenNumber(q) : 0;
|
||||
QScreen *targetScreen = topData()->initialScreen;
|
||||
topData()->initialScreen = nullptr;
|
||||
if (!targetScreen) {
|
||||
targetScreen = q->windowType() != Qt::Desktop
|
||||
? q->screen() : nullptr;
|
||||
}
|
||||
win->setScreen(QGuiApplication::screens().value(screenNumber, nullptr));
|
||||
win->setScreen(targetScreen);
|
||||
}
|
||||
|
||||
QSurfaceFormat format = win->requestedFormat();
|
||||
@ -1602,7 +1602,7 @@ void QWidgetPrivate::createTLExtra()
|
||||
x->sizeAdjusted = false;
|
||||
x->embedded = 0;
|
||||
x->window = nullptr;
|
||||
x->initialScreenIndex = -1;
|
||||
x->initialScreen = nullptr;
|
||||
|
||||
#ifdef QWIDGET_EXTRA_DEBUG
|
||||
static int count = 0;
|
||||
@ -2507,8 +2507,8 @@ QScreen *QWidget::screen() const
|
||||
return associatedScreen;
|
||||
if (auto topLevel = window()) {
|
||||
if (auto topData = qt_widget_private(topLevel)->topData()) {
|
||||
if (auto initialScreen = QGuiApplicationPrivate::screen_list.value(topData->initialScreenIndex))
|
||||
return initialScreen;
|
||||
if (topData->initialScreen)
|
||||
return topData->initialScreen;
|
||||
}
|
||||
if (auto screenByPos = QGuiApplication::screenAt(topLevel->geometry().center()))
|
||||
return screenByPos;
|
||||
@ -3472,8 +3472,7 @@ QPoint QWidget::pos() const
|
||||
issues with windows.
|
||||
|
||||
\note Do not use this function to find the width of a screen on
|
||||
a \l{QDesktopWidget}{multiple screen desktop}. Read
|
||||
\l{QDesktopWidget#Screen Geometry}{this note} for details.
|
||||
a multi-screen desktop. See QScreen for details.
|
||||
|
||||
By default, this property contains a value that depends on the user's
|
||||
platform and screen geometry.
|
||||
@ -10487,13 +10486,13 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
|
||||
Qt::WindowFlags oldFlags = data.window_flags;
|
||||
bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
|
||||
|
||||
int targetScreen = -1;
|
||||
QScreen *targetScreen = nullptr;
|
||||
// Handle a request to move the widget to a particular screen
|
||||
if (newparent && newparent->windowType() == Qt::Desktop) {
|
||||
// make sure the widget is created on the same screen as the
|
||||
// programmer specified desktop widget
|
||||
const QDesktopScreenWidget *sw = qobject_cast<const QDesktopScreenWidget *>(newparent);
|
||||
targetScreen = sw ? sw->screenNumber() : 0;
|
||||
targetScreen = sw ? sw->screen() : nullptr;
|
||||
newparent = nullptr;
|
||||
}
|
||||
|
||||
@ -10523,9 +10522,9 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
|
||||
|
||||
if (!newparent) {
|
||||
f |= Qt::Window;
|
||||
if (targetScreen == -1) {
|
||||
if (!targetScreen) {
|
||||
if (parent)
|
||||
targetScreen = QDesktopWidgetPrivate::screenNumber(q->parentWidget()->window());
|
||||
targetScreen = q->parentWidget()->window()->screen();
|
||||
}
|
||||
}
|
||||
|
||||
@ -10568,12 +10567,12 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
|
||||
q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
|
||||
|
||||
// move the window to the selected screen
|
||||
if (!newparent && targetScreen != -1) {
|
||||
if (!newparent && targetScreen) {
|
||||
// only if it is already created
|
||||
if (q->testAttribute(Qt::WA_WState_Created))
|
||||
q->windowHandle()->setScreen(QGuiApplication::screens().value(targetScreen, 0));
|
||||
q->windowHandle()->setScreen(targetScreen);
|
||||
else
|
||||
topData()->initialScreenIndex = targetScreen;
|
||||
topData()->initialScreen = targetScreen;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -157,7 +157,6 @@
|
||||
#endif
|
||||
#include "QtWidgets/qapplication.h"
|
||||
#include "QtGui/qevent.h"
|
||||
#include "QtWidgets/qdesktopwidget.h"
|
||||
#include <private/qapplication_p.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#if QT_CONFIG(lineedit)
|
||||
@ -921,7 +920,7 @@ void QCompleterPrivate::_q_autoResizePopup()
|
||||
|
||||
void QCompleterPrivate::showPopup(const QRect& rect)
|
||||
{
|
||||
const QRect screen = QDesktopWidgetPrivate::availableGeometry(widget);
|
||||
const QRect screen = QWidgetPrivate::availableScreenGeometry(widget);
|
||||
Qt::LayoutDirection dir = widget->layoutDirection();
|
||||
QPoint pos;
|
||||
int rh, w;
|
||||
|
@ -57,7 +57,6 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#endif
|
||||
#include <QDesktopWidget>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <QVector2D>
|
||||
#include <QtCore/qmath.h>
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include "qstyle.h"
|
||||
#include "qgridlayout.h"
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qbitmap.h"
|
||||
|
||||
@ -132,7 +131,7 @@ static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon)
|
||||
of type QEvent::ToolTip. Additionally, the QSystemTrayIcon receives wheel events of
|
||||
type QEvent::Wheel. These are not supported on any other platform.
|
||||
|
||||
\sa QDesktopServices, QDesktopWidget, {Desktop Integration}, {System Tray Icon Example}
|
||||
\sa QDesktopServices, {Desktop Integration}, {System Tray Icon Example}
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -533,7 +532,7 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title,
|
||||
msgLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
// smart size for the message label
|
||||
int limit = QDesktopWidgetPrivate::availableGeometry(msgLabel).size().width() / 3;
|
||||
int limit = QWidgetPrivate::availableScreenGeometry(msgLabel).width() / 3;
|
||||
if (msgLabel->sizeHint().width() > limit) {
|
||||
msgLabel->setWordWrap(true);
|
||||
if (msgLabel->sizeHint().width() > limit) {
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include <qpa/qplatformmenu.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <qlistview.h>
|
||||
#if QT_CONFIG(tableview)
|
||||
@ -321,11 +320,12 @@ void QComboBoxPrivate::trySetValidIndex()
|
||||
setCurrentIndex(QModelIndex());
|
||||
}
|
||||
|
||||
QRect QComboBoxPrivate::popupGeometry(int screen) const
|
||||
QRect QComboBoxPrivate::popupGeometry() const
|
||||
{
|
||||
Q_Q(const QComboBox);
|
||||
return QStylePrivate::useFullScreenForPopup()
|
||||
? QDesktopWidgetPrivate::screenGeometry(screen)
|
||||
: QDesktopWidgetPrivate::availableGeometry(screen);
|
||||
? QWidgetPrivate::screenGeometry(q)
|
||||
: QWidgetPrivate::availableScreenGeometry(q);
|
||||
}
|
||||
|
||||
bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)
|
||||
@ -2613,7 +2613,7 @@ void QComboBox::showPopup()
|
||||
QComboBoxPrivateContainer* container = d->viewContainer();
|
||||
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
|
||||
QStyle::SC_ComboBoxListBoxPopup, this));
|
||||
QRect screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(this));
|
||||
QRect screen = d->popupGeometry();
|
||||
|
||||
QPoint below = mapToGlobal(listRect.bottomLeft());
|
||||
int belowHeight = screen.bottom() - below.y();
|
||||
|
@ -372,7 +372,7 @@ public:
|
||||
void updateArrow(QStyle::StateFlag state);
|
||||
bool updateHoverControl(const QPoint &pos);
|
||||
void trySetValidIndex();
|
||||
QRect popupGeometry(int screen = -1) const;
|
||||
QRect popupGeometry() const;
|
||||
QStyle::SubControl newHoverControl(const QPoint &pos);
|
||||
int computeWidthHint() const;
|
||||
QSize recomputeSizeHint(QSize &sh) const;
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include <qabstractspinbox.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdatetimeedit.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <qdebug.h>
|
||||
#include <qevent.h>
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "QtWidgets/qtabbar.h"
|
||||
#endif
|
||||
#include "QtWidgets/qstyle.h"
|
||||
#include "QtWidgets/qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "QtWidgets/qapplication.h"
|
||||
#include "QtCore/qvariant.h"
|
||||
@ -3024,7 +3023,7 @@ QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget)
|
||||
if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1)
|
||||
desktop = QDesktopWidgetPrivate::screenGeometry(rect.topLeft());
|
||||
else
|
||||
desktop = QDesktopWidgetPrivate::screenGeometry(widget);
|
||||
desktop = QWidgetPrivate::screenGeometry(widget);
|
||||
|
||||
if (desktop.isValid()) {
|
||||
rect.setWidth(qMin(rect.width(), desktop.width()));
|
||||
|
@ -41,7 +41,6 @@
|
||||
|
||||
#include <qaction.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <qdrawutil.h>
|
||||
#include <qevent.h>
|
||||
#include <qfontmetrics.h>
|
||||
|
@ -38,7 +38,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include "qeffects_p.h"
|
||||
#include "qevent.h"
|
||||
#include "qimage.h"
|
||||
@ -54,15 +53,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static QWidget *effectParent(const QWidget* w)
|
||||
{
|
||||
const int screenNumber = w ? QGuiApplication::screens().indexOf(w->screen()) : 0;
|
||||
QT_WARNING_PUSH // ### Qt 6: Find a replacement for QDesktopWidget::screen()
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
return QApplication::desktop()->screen(screenNumber);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
/*
|
||||
Internal class QAlphaWidget.
|
||||
|
||||
@ -108,7 +98,7 @@ static QAlphaWidget* q_blend = nullptr;
|
||||
Constructs a QAlphaWidget.
|
||||
*/
|
||||
QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f)
|
||||
: QWidget(effectParent(w), f)
|
||||
: QWidget(QApplication::desktop(w ? w->screen() : nullptr), f)
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
setEnabled(false);
|
||||
@ -389,7 +379,7 @@ static QRollEffect* q_roll = nullptr;
|
||||
Construct a QRollEffect widget.
|
||||
*/
|
||||
QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient)
|
||||
: QWidget(effectParent(w), f), orientation(orient)
|
||||
: QWidget(QApplication::desktop(w ? w->screen() : nullptr), f), orientation(orient)
|
||||
{
|
||||
#ifndef Q_OS_WIN
|
||||
setEnabled(false);
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include <qevent.h>
|
||||
#include <qapplication.h>
|
||||
#include <private/qcombobox_p.h>
|
||||
#include <QDesktopWidget>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
@ -545,7 +544,7 @@ bool QFontComboBox::event(QEvent *e)
|
||||
QListView *lview = qobject_cast<QListView*>(view());
|
||||
if (lview) {
|
||||
lview->window()->setFixedWidth(qMin(width() * 5 / 3,
|
||||
QDesktopWidgetPrivate::availableGeometry(lview).width()));
|
||||
QWidgetPrivate::availableScreenGeometry(lview).width()));
|
||||
}
|
||||
}
|
||||
return QComboBox::event(e);
|
||||
|
@ -165,7 +165,6 @@
|
||||
#include <QPainter>
|
||||
#include <QFontMetrics>
|
||||
#include <QStyleOption>
|
||||
#include <QDesktopWidget>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <QDebug>
|
||||
#include <qmath.h>
|
||||
@ -1733,7 +1732,7 @@ QMdiArea::~QMdiArea()
|
||||
*/
|
||||
QSize QMdiArea::sizeHint() const
|
||||
{
|
||||
// Calculate a proper scale factor for QDesktopWidget::size().
|
||||
// Calculate a proper scale factor for the desktop's size.
|
||||
// This also takes into account that we can have nested workspaces.
|
||||
int nestedCount = 0;
|
||||
QWidget *widget = this->parentWidget();
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include "qmacnativewidget_mac.h"
|
||||
#endif
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
# include "qaccessible.h"
|
||||
#endif
|
||||
@ -324,8 +323,8 @@ QRect QMenuPrivate::popupGeometry() const
|
||||
{
|
||||
Q_Q(const QMenu);
|
||||
return useFullScreenForPopup()
|
||||
? QDesktopWidgetPrivate::screenGeometry(q)
|
||||
: QDesktopWidgetPrivate::availableGeometry(q);
|
||||
? QWidgetPrivate::screenGeometry(q)
|
||||
: QWidgetPrivate::availableScreenGeometry(q);
|
||||
}
|
||||
|
||||
QRect QMenuPrivate::popupGeometry(int screen) const
|
||||
@ -2385,15 +2384,12 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po
|
||||
// Ensure that we get correct sizeHints by placing this window on the correct screen.
|
||||
// However if the QMenu was constructed with a QDesktopScreenWidget as its parent,
|
||||
// then initialScreenIndex was set, so we should respect that for the lifetime of this menu.
|
||||
// Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing.
|
||||
// However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162)
|
||||
if (!eventLoop) {
|
||||
bool screenSet = false;
|
||||
const int screenIndex = topData()->initialScreenIndex;
|
||||
if (screenIndex >= 0)
|
||||
popupScreen = screenIndex;
|
||||
if (auto s = QGuiApplication::screens().value(popupScreen)) {
|
||||
if (setScreen(s))
|
||||
QScreen *screen = topData()->initialScreen;
|
||||
if (screen) {
|
||||
if (setScreen(screen))
|
||||
itemsDirty = true;
|
||||
screenSet = true;
|
||||
} else if (QMenu *parentMenu = qobject_cast<QMenu *>(parent)) {
|
||||
|
@ -522,8 +522,6 @@ public:
|
||||
bool tearoffHighlighted : 1;
|
||||
//menu fading/scrolling effects
|
||||
bool doChildEffects : 1;
|
||||
|
||||
int popupScreen = -1;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include <qstyle.h>
|
||||
#include <qlayout.h>
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
# include <qaccessible.h>
|
||||
#endif
|
||||
@ -355,7 +354,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
|
||||
|
||||
if(!defaultPopDown || (fitUp && !fitDown))
|
||||
pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
|
||||
QMenuPrivate::get(activeMenu)->topData()->initialScreenIndex = QGuiApplication::screens().indexOf(popupScreen);
|
||||
QMenuPrivate::get(activeMenu)->topData()->initialScreen = popupScreen;
|
||||
activeMenu->popup(pos);
|
||||
if(activateFirst)
|
||||
activeMenu->d_func()->setFirstActionActive();
|
||||
|
@ -39,7 +39,6 @@
|
||||
|
||||
#include "qapplication.h"
|
||||
#include "qbitmap.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#if QT_CONFIG(dialog)
|
||||
#include <private/qdialog_p.h>
|
||||
@ -622,7 +621,7 @@ QPoint QPushButtonPrivate::adjustedMenuPosition()
|
||||
QPoint globalPos = q->mapToGlobal(rect.topLeft());
|
||||
int x = globalPos.x();
|
||||
int y = globalPos.y();
|
||||
const QRect availableGeometry = QDesktopWidgetPrivate::availableGeometry(q);
|
||||
const QRect availableGeometry = QWidgetPrivate::availableScreenGeometry(q);
|
||||
if (horizontal) {
|
||||
if (globalPos.y() + rect.height() + menuSize.height() <= availableGeometry.bottom()) {
|
||||
y += rect.height();
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include "qstyleoption.h"
|
||||
#include "qlayout.h"
|
||||
#include "qdebug.h"
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include <private/qwidget_p.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
@ -304,7 +303,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e)
|
||||
bool hasVerticalSizeConstraint = true;
|
||||
bool hasHorizontalSizeConstraint = true;
|
||||
if (tlw->isWindow())
|
||||
availableGeometry = QDesktopWidgetPrivate::availableGeometry(tlw);
|
||||
availableGeometry = QWidgetPrivate::availableScreenGeometry(tlw);
|
||||
else {
|
||||
const QWidget *tlwParent = tlw->parentWidget();
|
||||
// Check if tlw is inside QAbstractScrollArea/QScrollArea.
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "qsplashscreen.h"
|
||||
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qpainter.h"
|
||||
#include "qpixmap.h"
|
||||
@ -294,25 +293,14 @@ void QSplashScreen::setPixmap(const QPixmap &pixmap)
|
||||
// 3) If a widget with associated QWindow is found, use that
|
||||
// 4) When nothing can be found, try to center it over the cursor
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
static inline int screenNumberOf(const QDesktopScreenWidget *dsw)
|
||||
{
|
||||
auto desktopWidgetPrivate =
|
||||
static_cast<QDesktopWidgetPrivate *>(qt_widget_private(QApplication::desktop()));
|
||||
return desktopWidgetPrivate->screens.indexOf(const_cast<QDesktopScreenWidget *>(dsw));
|
||||
}
|
||||
#endif
|
||||
|
||||
const QScreen *QSplashScreenPrivate::screenFor(const QWidget *w)
|
||||
{
|
||||
if (w && w->screen())
|
||||
return w->screen();
|
||||
|
||||
for (const QWidget *p = w; p !=nullptr ; p = p->parentWidget()) {
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
if (auto dsw = qobject_cast<const QDesktopScreenWidget *>(p))
|
||||
return QGuiApplication::screens().value(screenNumberOf(dsw));
|
||||
#endif
|
||||
return dsw->screen();
|
||||
if (QWindow *window = p->windowHandle())
|
||||
return window->screen();
|
||||
}
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "private/qtabbar_p.h"
|
||||
#include "qapplication.h"
|
||||
#include "qbitmap.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qevent.h"
|
||||
#include "qlayout.h"
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include <qapplication.h>
|
||||
#include <private/qapplication_p.h>
|
||||
#include <qevent.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <qdebug.h>
|
||||
#include <qabstracttextdocumentlayout.h>
|
||||
#include "private/qtextdocumentlayout_p.h"
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "qtoolbutton.h"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include <qdrawutil.h>
|
||||
#include <qevent.h>
|
||||
|
@ -41,7 +41,6 @@
|
||||
|
||||
#include "qframe.h"
|
||||
#include "qapplication.h"
|
||||
#include "qdesktopwidget.h"
|
||||
#include <private/qdesktopwidget_p.h>
|
||||
#include "qcursor.h"
|
||||
#if QT_CONFIG(sizegrip)
|
||||
@ -221,7 +220,7 @@ void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e)
|
||||
|
||||
// Workaround for window managers which refuse to move a tool window partially offscreen.
|
||||
if (QGuiApplication::platformName() == QLatin1String("xcb")) {
|
||||
const QRect desktop = QDesktopWidgetPrivate::availableGeometry(widget);
|
||||
const QRect desktop = QWidgetPrivate::availableScreenGeometry(widget);
|
||||
pp.rx() = qMax(pp.x(), desktop.left());
|
||||
pp.ry() = qMax(pp.y(), desktop.top());
|
||||
p.rx() = qMin(p.x(), desktop.right());
|
||||
|
@ -1943,10 +1943,8 @@ void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const
|
||||
if (!menu)
|
||||
return;
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
if (auto *window = static_cast<QWidget *>(parent)->window()->windowHandle()) {
|
||||
QMenuPrivate::get(menu)->topData()->initialScreenIndex =
|
||||
QGuiApplication::screens().indexOf(window->screen());
|
||||
}
|
||||
if (auto *window = static_cast<QWidget *>(parent)->window()->windowHandle())
|
||||
QMenuPrivate::get(menu)->topData()->initialScreen = window->screen();
|
||||
menu->popup(screenPos);
|
||||
#endif
|
||||
}
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <qimage.h>
|
||||
#include <qimagereader.h>
|
||||
#ifndef QT_NO_WIDGETS
|
||||
#include <qdesktopwidget.h>
|
||||
#include <qsplashscreen.h>
|
||||
#endif
|
||||
#include <qpaintengine.h>
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <QtWidgets/QColorDialog>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
|
||||
class tst_languageChange : public QObject
|
||||
{
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <qstyle.h>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSizeGrip>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QWindow>
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
|
||||
#include <QtTest/QtTestWidgets>
|
||||
#include <QtWidgets/qdesktopwidget.h>
|
||||
#include <QtWidgets/qgraphicseffect.h>
|
||||
#include <QtWidgets/qgraphicsview.h>
|
||||
#include <QtWidgets/qgraphicsscene.h>
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QBitmap>
|
||||
#include <QCursor>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
#include <QLabel>
|
||||
#include <QDial>
|
||||
|
@ -27,7 +27,6 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QProxyStyle>
|
||||
#include <QSignalSpy>
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include "../../../../shared/fakedirmodel.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
|
@ -1 +0,0 @@
|
||||
tst_qdesktopwidget
|
@ -44,7 +44,6 @@
|
||||
#include <qstyle.h>
|
||||
#include <qwidget.h>
|
||||
#include <qstylefactory.h>
|
||||
#include <qdesktopwidget.h>
|
||||
#include <private/qwidget_p.h>
|
||||
#include <private/qwidgetrepaintmanager_p.h>
|
||||
#include <private/qapplication_p.h>
|
||||
@ -9170,7 +9169,7 @@ void tst_QWidget::translucentWidget()
|
||||
QPixmap widgetSnapshot;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QWidget *desktopWidget = QApplication::desktop()->screen(0);
|
||||
QWidget *desktopWidget = QApplication::desktop();
|
||||
widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
|
||||
#else
|
||||
widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <QStyleOption>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDockWidget>
|
||||
#include <QScrollBar>
|
||||
#include <QTextEdit>
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <QStatusBar>
|
||||
#include <QListWidget>
|
||||
#include <QWidgetAction>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
#include <QSpinBox>
|
||||
#include <qdialog.h>
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QScreen>
|
||||
#include <QtGui/QStaticText>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
#include <QtWidgets/QGraphicsView>
|
||||
#include <QtWidgets/QGraphicsScene>
|
||||
#include <QtWidgets/QGraphicsRectItem>
|
||||
@ -504,8 +503,8 @@ static QPixmap grabWidgetWithoutRepaint(const QWidget *widget, QRect clipArea)
|
||||
// because GDI functions can't grab OpenGL layer content.
|
||||
// Instead the whole screen should be captured, with an adjusted clip area, which contains
|
||||
// the final composited content.
|
||||
QDesktopWidget *desktopWidget = QApplication::desktop();
|
||||
const QWidget *mainScreenWidget = desktopWidget->screen();
|
||||
QWidget *desktopWidget = QApplication::desktop(QGuiApplication::primaryScreen());
|
||||
const QWidget *mainScreenWidget = desktopWidget;
|
||||
targetWidget = mainScreenWidget;
|
||||
clipArea = QRect(widget->mapToGlobal(clipArea.topLeft()),
|
||||
widget->mapToGlobal(clipArea.bottomRight()));
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTextDocument>
|
||||
#include <QDesktopWidget>
|
||||
#include <QTextLayout>
|
||||
#include <QFontMetrics>
|
||||
#include <QDebug>
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <QtWidgets/QGraphicsView>
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QPixmapCache>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
|
||||
#include "chiptester/chiptester.h"
|
||||
//#define CALLGRIND_DEBUG
|
||||
@ -69,7 +68,7 @@ public:
|
||||
|
||||
void tryResize(int width, int height)
|
||||
{
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
QWidget *desktop = QApplication::desktop();
|
||||
if (desktop->width() < width)
|
||||
width = desktop->width();
|
||||
if (desktop->height() < height)
|
||||
|
@ -43,7 +43,7 @@ namespace QtDiag {
|
||||
static const char *qtWidgetClasses[] = {
|
||||
"QAbstractItemView", "QAbstractScrollArea", "QAbstractSlider", "QAbstractSpinBox",
|
||||
"QCalendarWidget", "QCheckBox", "QColorDialog", "QColumnView", "QComboBox",
|
||||
"QCommandLinkButton", "QDateEdit", "QDateTimeEdit", "QDesktopWidget", "QDial",
|
||||
"QCommandLinkButton", "QDateEdit", "QDateTimeEdit", "QDial",
|
||||
"QDialog", "QDialogButtonBox", "QDockWidget", "QDoubleSpinBox", "QErrorMessage",
|
||||
"QFileDialog", "QFontComboBox", "QFontDialog", "QFrame", "QGraphicsView",
|
||||
"QGroupBox", "QHeaderView", "QInputDialog", "QLCDNumber", "QLabel", "QLineEdit",
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <QPrintPreviewDialog>
|
||||
#include <QPageSetupDialog>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGroupBox>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
@ -83,8 +82,7 @@ static QString screenInfo(const QWidget *w)
|
||||
{
|
||||
QString result;
|
||||
QTextStream str(&result);
|
||||
#if QT_VERSION > 0x050000
|
||||
QScreen *screen = Q_NULLPTR;
|
||||
QScreen *screen = nullptr;
|
||||
if (const QWindow *window = w->windowHandle())
|
||||
screen = window->screen();
|
||||
if (screen) {
|
||||
@ -98,12 +96,6 @@ static QString screenInfo(const QWidget *w)
|
||||
} else {
|
||||
str << "<null>";
|
||||
}
|
||||
#else
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
int screenNumber = desktop->screenNumber(w);
|
||||
str << "Screen #" <<screenNumber << ' ' << desktop->screenGeometry(screenNumber).width()
|
||||
<< 'x' << desktop->screenGeometry(screenNumber).height() << " PD: " << w->logicalDpiX() << "DPI";
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
str << ", SM_C_CURSOR: " << GetSystemMetrics(SM_CXCURSOR) << 'x' << GetSystemMetrics(SM_CYCURSOR);
|
||||
#endif
|
||||
|
@ -1,17 +0,0 @@
|
||||
# Generated from qdesktopwidget.pro.
|
||||
|
||||
#####################################################################
|
||||
## qdesktopwidget Binary:
|
||||
#####################################################################
|
||||
|
||||
add_qt_manual_test(qdesktopwidget
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
||||
|
||||
#### Keys ignored in scope 1:.:.:qdesktopwidget.pro:<TRUE>:
|
||||
# TEMPLATE = "app"
|
@ -1,212 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
class DesktopView : public QGraphicsView
|
||||
{
|
||||
#if QT_DEPRECATED_SINCE(5, 11)
|
||||
Q_OBJECT
|
||||
public:
|
||||
DesktopView()
|
||||
: that(0)
|
||||
{
|
||||
scene = new QGraphicsScene;
|
||||
setScene(scene);
|
||||
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
connect(desktop, SIGNAL(resized(int)), this, SLOT(updateScene()));
|
||||
connect(desktop, SIGNAL(resized(int)), this, SLOT(desktopResized(int)));
|
||||
connect(desktop, SIGNAL(workAreaResized(int)), this, SLOT(updateScene()));
|
||||
connect(desktop, SIGNAL(workAreaResized(int)), this, SLOT(desktopWorkAreaResized(int)));
|
||||
connect(desktop, SIGNAL(screenCountChanged(int)), this, SLOT(updateScene()));
|
||||
connect(desktop, SIGNAL(screenCountChanged(int)), this, SLOT(desktopScreenCountChanged(int)));
|
||||
|
||||
updateScene();
|
||||
|
||||
QTransform transform;
|
||||
transform.scale(0.25, 0.25);
|
||||
setTransform(transform);
|
||||
|
||||
setBackgroundBrush(Qt::darkGray);
|
||||
desktopScreenCountChanged(-1);
|
||||
}
|
||||
|
||||
protected:
|
||||
void moveEvent(QMoveEvent *e)
|
||||
{
|
||||
if (that) {
|
||||
that->setRect(appRect());
|
||||
scene->update();
|
||||
}
|
||||
QGraphicsView::moveEvent(e);
|
||||
}
|
||||
void resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
if (that) {
|
||||
that->setRect(appRect());
|
||||
}
|
||||
QGraphicsView::resizeEvent(e);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void updateScene()
|
||||
{
|
||||
scene->clear();
|
||||
|
||||
const QDesktopWidget *desktop = QApplication::desktop();
|
||||
const bool isVirtualDesktop = desktop->isVirtualDesktop();
|
||||
const int homeScreen = desktop->screenNumber(this);
|
||||
|
||||
QRect sceneRect;
|
||||
int screenCount = desktop->screenCount();
|
||||
for (int s = 0; s < screenCount; ++s) {
|
||||
const bool isPrimary = desktop->primaryScreen() == s;
|
||||
const QRect screenRect = desktop->screenGeometry(s);
|
||||
const QRect workRect = desktop->availableGeometry(s);
|
||||
const QBrush fillBrush = palette().brush(isPrimary ? QPalette::Active : QPalette::Inactive, QPalette::Highlight);
|
||||
QGraphicsRectItem *screen = new QGraphicsRectItem(0, 0, screenRect.width(), screenRect.height());
|
||||
|
||||
if (isVirtualDesktop) {
|
||||
thatRoot = QPoint();
|
||||
screen->setPos(screenRect.x(), screenRect.y());
|
||||
} else {
|
||||
// for non-virtual desktops we assume that screens are
|
||||
// simply next to each other
|
||||
if (s)
|
||||
screen->setPos(sceneRect.right(), 0);
|
||||
if (s == homeScreen)
|
||||
thatRoot = screen->pos().toPoint();
|
||||
}
|
||||
|
||||
screen->setBrush(fillBrush);
|
||||
scene->addItem(screen);
|
||||
sceneRect.setLeft(qMin(sceneRect.left(), screenRect.left()));
|
||||
sceneRect.setRight(qMax(sceneRect.right(), screenRect.right()));
|
||||
sceneRect.setTop(qMin(sceneRect.top(), screenRect.top()));
|
||||
sceneRect.setBottom(qMax(sceneRect.bottom(), screenRect.bottom()));
|
||||
|
||||
QGraphicsRectItem *workArea = new QGraphicsRectItem(screen);
|
||||
workArea->setRect(0, 0, workRect.width(), workRect.height());
|
||||
workArea->setPos(workRect.x() - screenRect.x(), workRect.y() - screenRect.y());
|
||||
workArea->setBrush(Qt::white);
|
||||
|
||||
QGraphicsSimpleTextItem *screenNumber = new QGraphicsSimpleTextItem(workArea);
|
||||
screenNumber->setText(QString::number(s));
|
||||
screenNumber->setPen(QPen(Qt::black, 1));
|
||||
screenNumber->setBrush(fillBrush);
|
||||
screenNumber->setFont(QFont("Arial Black", 18));
|
||||
screenNumber->setTransform(QTransform().scale(10, 10));
|
||||
screenNumber->setTransformOriginPoint(screenNumber->boundingRect().center());
|
||||
QSizeF center = (workRect.size() - screenNumber->boundingRect().size()) / 2;
|
||||
screenNumber->setPos(center.width(), center.height());
|
||||
|
||||
screen->show();
|
||||
screen->setZValue(1);
|
||||
}
|
||||
|
||||
if (isVirtualDesktop) {
|
||||
QGraphicsRectItem *virtualDesktop = new QGraphicsRectItem;
|
||||
virtualDesktop->setRect(sceneRect);
|
||||
virtualDesktop->setPen(QPen(Qt::black));
|
||||
virtualDesktop->setBrush(Qt::DiagCrossPattern);
|
||||
scene->addItem(virtualDesktop);
|
||||
virtualDesktop->setZValue(-1);
|
||||
virtualDesktop->show();
|
||||
}
|
||||
|
||||
that = new QGraphicsRectItem;
|
||||
that->setBrush(Qt::red);
|
||||
that->setOpacity(0.5);
|
||||
that->setZValue(2);
|
||||
that->setRect(appRect());
|
||||
that->show();
|
||||
scene->addItem(that);
|
||||
|
||||
scene->setSceneRect(sceneRect);
|
||||
scene->update();
|
||||
}
|
||||
|
||||
QRect appRect() const
|
||||
{
|
||||
QRect rect = frameGeometry();
|
||||
if (!QApplication::desktop()->isVirtualDesktop()) {
|
||||
rect.translate(thatRoot);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
void desktopResized(int screen)
|
||||
{
|
||||
qDebug() << "Screen was resized: " << screen
|
||||
<< ", new size =" << QApplication::desktop()->screenGeometry(screen);
|
||||
}
|
||||
void desktopWorkAreaResized(int screen)
|
||||
{
|
||||
qDebug() << "Screen workarea was resized: " << screen
|
||||
<< ", new size =" << QApplication::desktop()->availableGeometry(screen);
|
||||
}
|
||||
void desktopScreenCountChanged(int screenCount)
|
||||
{
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
qDebug() << "";
|
||||
if (screenCount != -1) {
|
||||
qDebug() << "Screen count was changed to " << screenCount;
|
||||
} else {
|
||||
screenCount = desktop->screenCount();
|
||||
qDebug() << "Screen count: " << screenCount;
|
||||
}
|
||||
for (int i = 0; i < screenCount; ++i) {
|
||||
qDebug() << " #" << i << ": geometry =" << desktop->screenGeometry(i)
|
||||
<< "; available geometry =" << desktop->availableGeometry(i);
|
||||
}
|
||||
qDebug() << "";
|
||||
}
|
||||
|
||||
private:
|
||||
QGraphicsScene *scene;
|
||||
QGraphicsRectItem *that;
|
||||
QPoint thatRoot;
|
||||
#endif
|
||||
};
|
||||
|
||||
#include "main.moc"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
DesktopView view;
|
||||
view.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
TEMPLATE = app
|
||||
QT += widgets
|
||||
SOURCES += main.cpp
|
@ -39,7 +39,6 @@
|
||||
#include <QAction>
|
||||
#include <QStatusBar>
|
||||
#include <QLineEdit>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
@ -229,14 +228,11 @@ void screenAdded(QScreen* screen)
|
||||
(screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
|
||||
ScreenWatcherMainWindow *w = new ScreenWatcherMainWindow(screen);
|
||||
|
||||
// Set the screen via QDesktopWidget. This corresponds to setScreen() for the underlying
|
||||
// QWindow. This is essential when having separate X screens since the the positioning below is
|
||||
// not sufficient to get the windows show up on the desired screen.
|
||||
QList<QScreen *> screens = QGuiApplication::screens();
|
||||
int screenNumber = screens.indexOf(screen);
|
||||
Q_ASSERT(screenNumber >= 0);
|
||||
// ### Qt 6: Find a replacement for QDesktopWidget::screen()
|
||||
w->setParent(qApp->desktop()->screen(screenNumber));
|
||||
// Set the screen; this corresponds to setScreen() for the underlying
|
||||
// QWindow. This is essential when having separate X screens since the
|
||||
// positioning below is not sufficient to get the windows show up on the
|
||||
// desired screen.
|
||||
w->setParent(qApp->desktop(screen));
|
||||
|
||||
w->show();
|
||||
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include <QTabBar>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QDesktopWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QProxyStyle>
|
||||
#include <qdebug.h>
|
||||
|
Loading…
Reference in New Issue
Block a user