diff options
23 files changed, 24 insertions, 766 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 2d1bfa65d3..e5f2fd1c49 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1706,7 +1706,7 @@ void QColorDialogPrivate::initWidgets() #else // small displays (e.g. PDAs) cannot fit the full color dialog, // so just use the color picker. - smallDisplay = (QDesktopWidgetPrivate::width() < 480 || QDesktopWidgetPrivate::height() < 350); + smallDisplay = (QGuiApplication::primaryScreen()->virtualGeometry().width() < 480 || QGuiApplication::primaryScreen()->virtualGeometry().height() < 350); const int lumSpace = topLay->spacing() / 2; #endif diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index d5daedef3e..14cfe6800c 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -884,7 +884,7 @@ void QDialog::adjustPosition(QWidget* w) QRect desk; if (w) { scrn = QDesktopWidgetPrivate::screenNumber(w); - } else if (QDesktopWidgetPrivate::isVirtualDesktop()) { + } else if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1) { scrn = QDesktopWidgetPrivate::screenNumber(QCursor::pos()); } else { scrn = QDesktopWidgetPrivate::screenNumber(this); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index d2bd84216c..c7aac8b9da 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -399,7 +399,7 @@ void QWizardHeader::setup(const QWizardLayoutInfo &info, const QString &title, /* There is no widthForHeight() function, so we simulate it with a loop. */ - int candidateSubTitleWidth = qMin(512, 2 * QDesktopWidgetPrivate::width() / 3); + int candidateSubTitleWidth = qMin(512, 2 * QGuiApplication::primaryScreen()->virtualGeometry().width() / 3); int delta = candidateSubTitleWidth >> 1; while (delta > 0) { if (subTitleLabel->heightForWidth(candidateSubTitleWidth - delta) diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index ca14e03a72..30e386569a 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -1293,7 +1293,7 @@ QSize QGraphicsView::sizeHint() const if (d->scene) { QSizeF baseSize = d->matrix.mapRect(sceneRect()).size(); baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2); - return baseSize.boundedTo((3 * QDesktopWidgetPrivate::size()) / 4).toSize(); + return baseSize.boundedTo((3 * QGuiApplication::primaryScreen()->virtualSize()) / 4).toSize(); } return QAbstractScrollArea::sizeHint(); } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index d7919c9414..6e17901677 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -2517,6 +2517,8 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget) } /*! + \internal + Returns the desktop widget (also called the root window). The desktop may be composed of multiple screens, so it would be incorrect, diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h index 974c789e08..1903aa48dc 100644 --- a/src/widgets/kernel/qapplication.h +++ b/src/widgets/kernel/qapplication.h @@ -46,9 +46,6 @@ #include <QtCore/qpoint.h> #include <QtCore/qsize.h> #include <QtGui/qcursor.h> -#ifdef QT_INCLUDE_COMPAT -# include <QtWidgets/qdesktopwidget.h> -#endif #include <QtGui/qguiapplication.h> QT_BEGIN_NAMESPACE diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index 9f98af86e3..dd74fbf53e 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -71,11 +71,6 @@ int QDesktopScreenWidget::screenNumber() const return desktopWidgetP->screens.indexOf(const_cast<QDesktopScreenWidget *>(this)); } -const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const -{ - return QDesktopWidgetPrivate::screenGeometry(widget); -} - const QRect QDesktopWidgetPrivate::screenGeometry(const QWidget *widget) { if (Q_UNLIKELY(!widget)) { @@ -89,11 +84,6 @@ const QRect QDesktopWidgetPrivate::screenGeometry(const QWidget *widget) else return rect; } -const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const -{ - return QDesktopWidgetPrivate::availableGeometry(widget); -} - const QRect QDesktopWidgetPrivate::availableGeometry(const QWidget *widget) { if (Q_UNLIKELY(!widget)) { @@ -122,7 +112,6 @@ void QDesktopWidgetPrivate::_q_updateScreens() Q_Q(QDesktopWidget); const QList<QScreen *> screenList = QGuiApplication::screens(); const int targetLength = screenList.length(); - bool screenCountChanged = false; // 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 @@ -147,11 +136,8 @@ void QDesktopWidgetPrivate::_q_updateScreens() screenWidget = new QDesktopScreenWidget(qScreen, screenGeometry); QObject::connect(qScreen, SIGNAL(geometryChanged(QRect)), q, SLOT(_q_updateScreens()), Qt::QueuedConnection); - QObject::connect(qScreen, SIGNAL(availableGeometryChanged(QRect)), - q, SLOT(_q_availableGeometryChanged()), Qt::QueuedConnection); QObject::connect(qScreen, SIGNAL(destroyed()), q, SLOT(_q_updateScreens()), Qt::QueuedConnection); - screenCountChanged = true; } // record all the screens and the overall geometry. newScreens.push_back(screenWidget); @@ -165,43 +151,9 @@ void QDesktopWidgetPrivate::_q_updateScreens() // Delete the QDesktopScreenWidget that are not used any more. foreach (QDesktopScreenWidget *screen, newScreens) { - if (!screens.contains(screen)) { + if (!screens.contains(screen)) delete screen; - screenCountChanged = true; - } } - - // Finally, emit the signals. - if (screenCountChanged) { - // Notice that we trigger screenCountChanged even if a screen was removed and another one added, - // in which case the total number of screens did not change. This is the only way for applications - // to notice that a screen was swapped out against another one. -#if QT_DEPRECATED_SINCE(5, 11) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - emit q->screenCountChanged(targetLength); -QT_WARNING_POP -#endif - } -#if QT_DEPRECATED_SINCE(5, 11) - foreach (int changedScreen, changedScreens) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - emit q->resized(changedScreen); -QT_WARNING_POP -#endif -} - -void QDesktopWidgetPrivate::_q_availableGeometryChanged() -{ -#if QT_DEPRECATED_SINCE(5, 11) - Q_Q(QDesktopWidget); - if (QScreen *screen = qobject_cast<QScreen *>(q->sender())) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - emit q->workAreaResized(QGuiApplication::screens().indexOf(screen)); -QT_WARNING_POP -#endif } QDesktopWidget::QDesktopWidget() @@ -211,70 +163,12 @@ QDesktopWidget::QDesktopWidget() setObjectName(QLatin1String("desktop")); d->_q_updateScreens(); connect(qApp, SIGNAL(screenAdded(QScreen*)), this, SLOT(_q_updateScreens())); -#if QT_DEPRECATED_SINCE(5, 11) - connect(qApp, SIGNAL(primaryScreenChanged(QScreen*)), this, SIGNAL(primaryScreenChanged())); -#endif } QDesktopWidget::~QDesktopWidget() { } -#if QT_DEPRECATED_SINCE(5, 11) -bool QDesktopWidget::isVirtualDesktop() const -{ - return QDesktopWidgetPrivate::isVirtualDesktop(); -} -#endif - -bool QDesktopWidgetPrivate::isVirtualDesktop() -{ - return QGuiApplication::primaryScreen()->virtualSiblings().size() > 1; -} - -QRect QDesktopWidgetPrivate::geometry() -{ - return QGuiApplication::primaryScreen()->virtualGeometry(); -} - -QSize QDesktopWidgetPrivate::size() -{ - return geometry().size(); -} - -int QDesktopWidgetPrivate::width() -{ - return geometry().width(); -} - -int QDesktopWidgetPrivate::height() -{ - return geometry().height(); -} - -#if QT_DEPRECATED_SINCE(5, 11) -int QDesktopWidget::primaryScreen() const -{ - return QDesktopWidgetPrivate::primaryScreen(); -} -#endif - -int QDesktopWidgetPrivate::primaryScreen() -{ - return 0; -} - -int QDesktopWidgetPrivate::numScreens() -{ - return qMax(QGuiApplication::screens().size(), 1); -} - -#if QT_DEPRECATED_SINCE(5, 11) -int QDesktopWidget::numScreens() const -{ - return QDesktopWidgetPrivate::numScreens(); -} - QWidget *QDesktopWidget::screen(int screen) { Q_D(QDesktopWidget); @@ -283,45 +177,27 @@ QWidget *QDesktopWidget::screen(int screen) return d->screens.at(screen); } -const QRect QDesktopWidget::availableGeometry(int screenNo) const -{ - return QDesktopWidgetPrivate::availableGeometry(screenNo); -} -#endif - const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo) { const QScreen *screen = QDesktopWidgetPrivate::screen(screenNo); return screen ? screen->availableGeometry() : QRect(); } -#if QT_DEPRECATED_SINCE(5, 11) -const QRect QDesktopWidget::screenGeometry(int screenNo) const -{ - return QDesktopWidgetPrivate::screenGeometry(screenNo); -} -#endif - const QRect QDesktopWidgetPrivate::screenGeometry(int screenNo) { const QScreen *screen = QDesktopWidgetPrivate::screen(screenNo); return screen ? screen->geometry() : QRect(); } -int QDesktopWidget::screenNumber(const QWidget *w) const -{ - return QDesktopWidgetPrivate::screenNumber(w); -} - int QDesktopWidgetPrivate::screenNumber(const QWidget *w) { if (!w) - return primaryScreen(); + return 0; const QList<QScreen *> allScreens = QGuiApplication::screens(); QList<QScreen *> screens = allScreens; if (screens.isEmpty()) // This should never happen - return primaryScreen(); + return 0; // If there is more than one virtual desktop if (screens.count() != screens.constFirst()->virtualSiblings().count()) { @@ -352,17 +228,10 @@ int QDesktopWidgetPrivate::screenNumber(const QWidget *w) return allScreens.indexOf(widgetScreen); } -#if QT_DEPRECATED_SINCE(5, 11) -int QDesktopWidget::screenNumber(const QPoint &p) const -{ - return QDesktopWidgetPrivate::screenNumber(p); -} -#endif - int QDesktopWidgetPrivate::screenNumber(const QPoint &p) { QScreen *screen = QGuiApplication::screenAt(p); - return screen ? QGuiApplication::screens().indexOf(screen) : primaryScreen(); + return screen ? QGuiApplication::screens().indexOf(screen) : 0; } QScreen *QDesktopWidgetPrivate::screen(int screenNo) @@ -375,10 +244,6 @@ QScreen *QDesktopWidgetPrivate::screen(int screenNo) return screens.at(screenNo); } -void QDesktopWidget::resizeEvent(QResizeEvent *) -{ -} - QT_END_NAMESPACE #include "moc_qdesktopwidget.cpp" diff --git a/src/widgets/kernel/qdesktopwidget.h b/src/widgets/kernel/qdesktopwidget.h index e5c587984f..265f320b1f 100644 --- a/src/widgets/kernel/qdesktopwidget.h +++ b/src/widgets/kernel/qdesktopwidget.h @@ -52,78 +52,21 @@ class QDesktopWidgetPrivate; class Q_WIDGETS_EXPORT QDesktopWidget : public QWidget { Q_OBJECT -#if QT_DEPRECATED_SINCE(5, 11) - Q_PROPERTY(bool virtualDesktop READ isVirtualDesktop) - Q_PROPERTY(int screenCount READ screenCount NOTIFY screenCountChanged) - Q_PROPERTY(int primaryScreen READ primaryScreen NOTIFY primaryScreenChanged) -#endif public: QDesktopWidget(); ~QDesktopWidget(); - int screenNumber(const QWidget *widget = nullptr) const; - const QRect screenGeometry(const QWidget *widget) const; - const QRect availableGeometry(const QWidget *widget) const; - -#if QT_DEPRECATED_SINCE(5, 11) - QT_DEPRECATED_X("Use QScreen::virtualSiblings() of primary screen") bool isVirtualDesktop() const; - - QT_DEPRECATED_X("Use QGuiApplication::screens()") int numScreens() const; - QT_DEPRECATED_X("Use QGuiApplication::screens()") int screenCount() const; - QT_DEPRECATED_X("Use QGuiApplication::primaryScreen()") int primaryScreen() const; - - QT_DEPRECATED_X("Use QGuiApplication::screenAt()") int screenNumber(const QPoint &) const; - QT_DEPRECATED_X("Use QScreen") QWidget *screen(int screen = -1); - QT_DEPRECATED_X("Use QGuiApplication::screens()") const QRect screenGeometry(int screen = -1) const; - QT_DEPRECATED_X("Use QGuiApplication::screenAt()") const QRect screenGeometry(const QPoint &point) const - { -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - return screenGeometry(screenNumber(point)); -QT_WARNING_POP - } - - QT_DEPRECATED_X("Use QGuiApplication::screens()") const QRect availableGeometry(int screen = -1) const; - QT_DEPRECATED_X("Use QGuiApplication::screenAt()") const QRect availableGeometry(const QPoint &point) const - { -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - return availableGeometry(screenNumber(point)); -QT_WARNING_POP - } - -Q_SIGNALS: - QT_DEPRECATED_X("Use QScreen::geometryChanged()") void resized(int); - QT_DEPRECATED_X("Use QScreen::availableGeometryChanged()") void workAreaResized(int); - QT_DEPRECATED_X("Use QGuiApplication::screenAdded/Removed()") void screenCountChanged(int); - QT_DEPRECATED_X("Use QGuiApplication::primaryScreenChanged()") void primaryScreenChanged(); -#endif - -protected: - void resizeEvent(QResizeEvent *e) override; - private: Q_DISABLE_COPY(QDesktopWidget) Q_DECLARE_PRIVATE(QDesktopWidget) Q_PRIVATE_SLOT(d_func(), void _q_updateScreens()) - Q_PRIVATE_SLOT(d_func(), void _q_availableGeometryChanged()) friend class QApplication; friend class QApplicationPrivate; }; -#if QT_DEPRECATED_SINCE(5, 11) -inline int QDesktopWidget::screenCount() const -{ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - return numScreens(); -QT_WARNING_POP -} -#endif - QT_END_NAMESPACE #endif // QDESKTOPWIDGET_H diff --git a/src/widgets/kernel/qdesktopwidget.qdoc b/src/widgets/kernel/qdesktopwidget.qdoc deleted file mode 100644 index dd2d9535ae..0000000000 --- a/src/widgets/kernel/qdesktopwidget.qdoc +++ /dev/null @@ -1,336 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \class QDesktopWidget - \brief The QDesktopWidget class provides access to screen information on multi-head systems. - - \ingroup advanced - \ingroup desktop - \inmodule QtWidgets - \obsolete - - Systems with more than one graphics card and monitor can manage the - physical screen space available either as multiple desktops, or as a - large virtual desktop. - - This class provides information about the user's desktop, such as its - total size, number of screens, the geometry of each screen, and whether - they are configured as separate desktops or a single virtual desktop. - - Widgets provided by Qt use this class to place tooltips, menus and - dialog boxes on the correct screen for their parent or application - widgets. Applications can use this class to obtain information that - can be used to save window positions, or to place child widgets and - dialogs on one particular screen. - - \section1 Obtaining a Desktop Widget - - The QApplication::desktop() function is used to get an instance of - QDesktopWidget. - - The widget's screenGeometry() function provides information about the - geometry of the available screens with. The number of screens - available is returned by screenCount, and the screenCountChanged() - signal is emitted when screens are added or removed. - The screen number that a particular point or widget is located in - is returned by screenNumber(). - - \section1 Screen Geometry - - To obtain the dimensions of a particular screen, call the screenGeometry() - function. On some desktop environments, not all of the screen is - available for applications to use; for example, an application dock or - menu bar may take up some space. Use the availableGeometry() function - to obtain the available area for applications. - - QDesktopWidget also inherits the QWidget properties, width() and - height(), which specify the size of the desktop. However, for - desktops with multiple screens, the size of the desktop is the union - of all the screen sizes, so width() and height() should \e not be - used for computing the size of a widget to be placed on one of the - screens. - - On systems that are configured to use the available screens as a - single, large virtual desktop, the virtualDesktop property will be - set to true. In this case, the widget's size is usually the size of - the bounding rectangle of all the screens. - - \section1 Use of the Primary Screen - - For an application, the screen where the main widget resides is the - primary screen. This is stored in the primaryScreen property. - All windows opened in the context of the application should be - constrained to the boundaries of the primary screen; for example, - it would be inconvenient if a dialog box popped up on a different - screen, or split over two screens. - - \image qdesktopwidget.png Managing Multiple Screens - - In the illustration above, Application One's primary screen is - screen 0, and App Two's primary screen is screen 1. - - \sa QApplication, QApplication::desktop() -*/ - -/*! - \fn QDesktopWidget::QDesktopWidget() - - \internal - - Creates the desktop widget. - - If the system supports a virtual desktop, this widget will have - the size of the virtual desktop; otherwise this widget will have - the size of the primary screen. - - Instead of using QDesktopWidget directly, use QApplication::desktop(). -*/ - -/*! - \fn QDesktopWidget::~QDesktopWidget() - - \internal - - Destroys the desktop widget and frees any allocated resources. -*/ - -/*! - \fn int QDesktopWidget::numScreens() const - - Returns the number of available screens. - - \obsolete - - Use QGuiApplication::screens() instead. - - \sa primaryScreen -*/ - -/*! - \fn QWidget *QDesktopWidget::screen(int screen) - - Returns a widget that represents the screen with index \a screen - (a value of -1 means the default screen). - - If the system uses a virtual desktop, the returned widget will - have the geometry of the entire virtual desktop; i.e., bounding - every \a screen. - - \obsolete - - Use QScreen instead. - - \sa primaryScreen, screenCount, virtualDesktop -*/ - -/*! - \fn const QRect QDesktopWidget::availableGeometry(int screen) const - - Returns the available geometry of the screen with index \a screen. What - is available will be subrect of screenGeometry() based on what the - platform decides is available (for example excludes the dock and menu bar - on \macos, or the task bar on Windows). The default screen is used if - \a screen is -1. - - \obsolete - - Use QGuiApplication::screens() instead. - - \sa screenNumber(), screenGeometry(), QScreen::availableGeometry() -*/ - -/*! - \fn const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const - \overload - - Returns the available geometry of the screen which contains \a widget. - - \sa screenGeometry() -*/ - -/*! - \fn const QRect QDesktopWidget::availableGeometry(const QPoint &p) const - \overload - - Returns the available geometry of the screen which contains \a p. - - \obsolete - - Use QGuiApplication::screenAt() instead. - - \sa screenGeometry() -*/ - - -/*! - \fn const QRect QDesktopWidget::screenGeometry(int screen) const - - Returns the geometry of the screen with index \a screen. The default - screen is used if \a screen is -1. - - \obsolete - - Use QGuiApplication::screens() instead. - - \sa screenNumber() -*/ - -/*! - \fn const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const - \overload - - Returns the geometry of the screen which contains \a widget. -*/ - -/*! - \fn const QRect QDesktopWidget::screenGeometry(const QPoint &p) const - \overload - - Returns the geometry of the screen which contains \a p. - - \obsolete - - Use QGuiApplication::screenAt() instead. -*/ - - -/*! - \fn int QDesktopWidget::screenNumber(const QWidget *widget) const - - Returns the index of the screen that contains the largest - part of \a widget, or -1 if the widget not on a screen. - - \sa primaryScreen -*/ - -/*! - \fn int QDesktopWidget::screenNumber(const QPoint &point) const - - \overload - Returns the index of the screen that contains the \a point, or the - screen which is the shortest distance from the \a point. - - \obsolete - - Use QGuiApplication::screenAt() instead. - - \sa primaryScreen -*/ - -/*! - \fn void QDesktopWidget::resizeEvent(QResizeEvent *event) - \reimp - \internal -*/ - -/*! - \fn void QDesktopWidget::resized(int screen) - - This signal is emitted when the size of \a screen changes. - - \obsolete - - Use QScreen::geometryChanged() instead. -*/ - -/*! - \fn void QDesktopWidget::workAreaResized(int screen) - - This signal is emitted when the work area available on \a screen changes. - - \obsolete - - Use QScreen::availableGeometryChanged() instead. -*/ - -/*! - \property QDesktopWidget::screenCount - \brief the number of screens currently available on the system. - - \obsolete - - Use QGuiApplication::screens() instead. - - \since 4.6 -*/ - -/*! - \property QDesktopWidget::primaryScreen - \brief the index of the screen that is configured to be the primary screen - on the system. - - \obsolete - - Use QGuiApplication::primaryScreen() instead. -*/ - -/*! - \property QDesktopWidget::virtualDesktop - - \brief if the system manages the available screens in a virtual desktop. - - For virtual desktops, screen() will always return the same widget. - The size of the virtual desktop is the size of this desktop - widget. - - \obsolete - - Use QScreen::virtualSiblings() of primary screen instead. -*/ - -/*! - \fn void QDesktopWidget::screenCountChanged(int newCount) - - \since 4.6 - - This signal is emitted when the number of screens changes to \a newCount. - - \obsolete - - Use QGuiApplication::screenAdded and QGuiApplication::screenRemoved() instead. - - \sa screenCount -*/ - - -/*! - \fn void QDesktopWidget::primaryScreenChanged() - - \since 5.6 - - \brief This signal is emitted whenever the primary screen changes. - - \note This doesn't mean the QDesktopWidget::primaryScreen index will - necessarily be different, but now it will refer to the new primary screen. - - \obsolete - - Use QGuiApplication::primaryScreenChanged() instead. - - \sa primaryScreen, screenGeometry() -*/ diff --git a/src/widgets/kernel/qdesktopwidget_p.h b/src/widgets/kernel/qdesktopwidget_p.h index 63949055aa..b0ac13808d 100644 --- a/src/widgets/kernel/qdesktopwidget_p.h +++ b/src/widgets/kernel/qdesktopwidget_p.h @@ -84,19 +84,8 @@ class QDesktopWidgetPrivate : public QWidgetPrivate { public: ~QDesktopWidgetPrivate() { qDeleteAll(screens); } void _q_updateScreens(); - void _q_availableGeometryChanged(); QDesktopScreenWidget *widgetForScreen(QScreen *qScreen) const; - static bool isVirtualDesktop(); - - static QRect geometry(); - static QSize size(); - static int width(); - static int height(); - - static int numScreens(); - static int primaryScreen(); - static int screenNumber(const QWidget *widget = nullptr); static int screenNumber(const QPoint &); diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index eda3be0ba3..ca5025ef8f 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -373,7 +373,7 @@ bool QTipLabel::eventFilter(QObject *o, QEvent *e) int QTipLabel::getTipScreen(const QPoint &pos, QWidget *w) { - if (QDesktopWidgetPrivate::isVirtualDesktop()) + if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1) return QDesktopWidgetPrivate::screenNumber(pos); else return QDesktopWidgetPrivate::screenNumber(w); diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp index 8a632a395a..17824fba32 100644 --- a/src/widgets/kernel/qwhatsthis.cpp +++ b/src/widgets/kernel/qwhatsthis.cpp @@ -212,7 +212,7 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor } else { - int sw = QDesktopWidgetPrivate::width() / 3; + int sw = QGuiApplication::primaryScreen()->virtualGeometry().width() / 3; if (sw < 200) sw = 200; else if (sw > 300) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index a1f5b9a26c..a217ef5352 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7252,8 +7252,8 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) // ### Qt 6 - Perhaps it makes sense to dumb down the restoreGeometry() logic, see QTBUG-69104 - if (restoredScreenNumber >= QDesktopWidgetPrivate::numScreens()) - restoredScreenNumber = QDesktopWidgetPrivate::primaryScreen(); + if (restoredScreenNumber >= qMax(QGuiApplication::screens().size(), 1)) + restoredScreenNumber = 0; const qreal screenWidthF = qreal(QDesktopWidgetPrivate::screenGeometry(restoredScreenNumber).width()); // Sanity check bailing out when large variations of screen sizes occur due to // high DPI scaling or different levels of DPI awareness. diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 693692d6c7..3d2396c4a6 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -3021,7 +3021,7 @@ QSize QDockAreaLayout::minimumSize() const QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget) { QRect desktop; - if (QDesktopWidgetPrivate::isVirtualDesktop()) + if (QGuiApplication::primaryScreen()->virtualSiblings().size() > 1) desktop = QDesktopWidgetPrivate::screenGeometry(rect.topLeft()); else desktop = QDesktopWidgetPrivate::screenGeometry(widget); diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 713c5f3d75..e6fd021e4a 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -1744,7 +1744,7 @@ QSize QMdiArea::sizeHint() const } const int scaleFactor = 3 * (nestedCount + 1); - QSize desktopSize = QDesktopWidgetPrivate::size(); + QSize desktopSize = QGuiApplication::primaryScreen()->virtualSize(); QSize size(desktopSize.width() * 2 / scaleFactor, desktopSize.height() * 2 / scaleFactor); for (QMdiSubWindow *child : d_func()->childWindows) { if (!sanityCheck(child, "QMdiArea::sizeHint")) diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 9122273d0d..b45a6b5b01 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1625,7 +1625,7 @@ QSize QMenuBar::minimumSizeHint() const int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, nullptr, this); if(as_gui_menubar) { - int w = parentWidget() ? parentWidget()->width() : QDesktopWidgetPrivate::width(); + int w = parentWidget() ? parentWidget()->width() : QGuiApplication::primaryScreen()->virtualGeometry().width(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) ret = d->actionRects.at(i).size(); @@ -1675,7 +1675,7 @@ QSize QMenuBar::sizeHint() const int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, nullptr, this); if(as_gui_menubar) { - const int w = parentWidget() ? parentWidget()->width() : QDesktopWidgetPrivate::width(); + const int w = parentWidget() ? parentWidget()->width() : QGuiApplication::primaryScreen()->virtualGeometry().width(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; i < d->actionRects.count(); ++i) { const QRect &actionRect = d->actionRects.at(i); diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index 115a557e52..6f9e51cf4a 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -899,7 +899,7 @@ QSize QTabWidget::sizeHint() const if (usesScrollButtons()) t = t.boundedTo(QSize(200,200)); else - t = t.boundedTo(QDesktopWidgetPrivate::size()); + t = t.boundedTo(QGuiApplication::primaryScreen()->virtualGeometry().size()); } QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t); @@ -968,7 +968,7 @@ int QTabWidget::heightForWidth(int width) const if (usesScrollButtons()) t = t.boundedTo(QSize(200,200)); else - t = t.boundedTo(QDesktopWidgetPrivate::size()); + t = t.boundedTo(QGuiApplication::primaryScreen()->virtualSize()); } const bool tabIsHorizontal = (d->pos == North || d->pos == South); diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp index 43aa4c7988..e012ca624d 100644 --- a/src/widgets/widgets/qwidgetresizehandler.cpp +++ b/src/widgets/widgets/qwidgetresizehandler.cpp @@ -336,7 +336,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) switch (e->key()) { case Qt::Key_Left: pos.rx() -= delta; - if (pos.x() <= QDesktopWidgetPrivate::geometry().left()) { + if (pos.x() <= QGuiApplication::primaryScreen()->virtualGeometry().left()) { if (mode == TopLeft || mode == BottomLeft) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; @@ -361,7 +361,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Right: pos.rx() += delta; - if (pos.x() >= QDesktopWidgetPrivate::geometry().right()) { + if (pos.x() >= QGuiApplication::primaryScreen()->virtualGeometry().right()) { if (mode == TopRight || mode == BottomRight) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; @@ -386,7 +386,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Up: pos.ry() -= delta; - if (pos.y() <= QDesktopWidgetPrivate::geometry().top()) { + if (pos.y() <= QGuiApplication::primaryScreen()->virtualGeometry().top()) { if (mode == TopLeft || mode == TopRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; @@ -411,7 +411,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Down: pos.ry() += delta; - if (pos.y() >= QDesktopWidgetPrivate::geometry().bottom()) { + if (pos.y() >= QGuiApplication::primaryScreen()->virtualGeometry().bottom()) { if (mode == BottomLeft || mode == BottomRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; diff --git a/tests/auto/widgets/kernel/CMakeLists.txt b/tests/auto/widgets/kernel/CMakeLists.txt index 51759264b2..ec32603585 100644 --- a/tests/auto/widgets/kernel/CMakeLists.txt +++ b/tests/auto/widgets/kernel/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(qaction) add_subdirectory(qactiongroup) add_subdirectory(qapplication) add_subdirectory(qboxlayout) -add_subdirectory(qdesktopwidget) add_subdirectory(qformlayout) add_subdirectory(qgridlayout) add_subdirectory(qlayout) diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index c66c1822b2..8fbaf948f2 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -2,7 +2,6 @@ TEMPLATE=subdirs SUBDIRS=\ qapplication \ qboxlayout \ - qdesktopwidget \ qformlayout \ qgesturerecognizer \ qgridlayout \ diff --git a/tests/auto/widgets/kernel/qdesktopwidget/CMakeLists.txt b/tests/auto/widgets/kernel/qdesktopwidget/CMakeLists.txt deleted file mode 100644 index 79790049fe..0000000000 --- a/tests/auto/widgets/kernel/qdesktopwidget/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Generated from qdesktopwidget.pro. - -##################################################################### -## tst_qdesktopwidget Test: -##################################################################### - -add_qt_test(tst_qdesktopwidget - SOURCES - tst_qdesktopwidget.cpp - PUBLIC_LIBRARIES - Qt::Gui - Qt::Widgets -) diff --git a/tests/auto/widgets/kernel/qdesktopwidget/qdesktopwidget.pro b/tests/auto/widgets/kernel/qdesktopwidget/qdesktopwidget.pro deleted file mode 100644 index 1ab155f22e..0000000000 --- a/tests/auto/widgets/kernel/qdesktopwidget/qdesktopwidget.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdesktopwidget -QT += widgets testlib -SOURCES += tst_qdesktopwidget.cpp diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp deleted file mode 100644 index a29e8408a3..0000000000 --- a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp +++ /dev/null @@ -1,183 +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 <QtTest/QtTest> -#include <QtWidgets/QDesktopWidget> -#include <QtGui/QWindow> -#include <QDebug> - -// the complete class is deprecated -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -class tst_QDesktopWidget : public QObject -{ - Q_OBJECT - -private slots: - void cleanup(); - -#if QT_DEPRECATED_SINCE(5, 11) - void numScreens(); - void primaryScreen(); - void screenNumberForQPoint(); -#endif - void screenNumberForQWidget(); - void availableGeometry(); - void screenGeometry(); - void topLevels(); -}; - -void tst_QDesktopWidget::cleanup() -{ - QVERIFY(QApplication::topLevelWidgets().isEmpty()); -} - -#if QT_DEPRECATED_SINCE(5, 11) -void tst_QDesktopWidget::numScreens() -{ - QDesktopWidget desktop; - QVERIFY(desktop.numScreens() > 0); -} - -void tst_QDesktopWidget::primaryScreen() -{ - QDesktopWidget desktop; - QVERIFY(desktop.primaryScreen() >= 0); - QVERIFY(desktop.primaryScreen() < desktop.numScreens()); -} -#endif - -void tst_QDesktopWidget::availableGeometry() -{ - QDesktopWidget desktop; - QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt " - "to get the available geometry of a null widget"); - QRect r = desktop.availableGeometry(nullptr); - QVERIFY(r.isNull()); - -#if QT_DEPRECATED_SINCE(5, 11) - QRect total; - QRect available; - - for (int i = 0; i < desktop.screenCount(); ++i) { - total = desktop.screenGeometry(i); - available = desktop.availableGeometry(i); - QVERIFY(total.contains(available)); - } - - total = desktop.screenGeometry(); - available = desktop.availableGeometry(); - QVERIFY(total.contains(available)); - QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available); - QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total); -#endif -} - -void tst_QDesktopWidget::screenNumberForQWidget() -{ - QDesktopWidget desktop; - - QCOMPARE(desktop.screenNumber(nullptr), 0); - - QWidget widget; - widget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&widget)); - QVERIFY(widget.isVisible()); - - int widgetScreen = desktop.screenNumber(&widget); - QVERIFY(widgetScreen > -1); - QVERIFY(widgetScreen < QGuiApplication::screens().size()); -} - -#if QT_DEPRECATED_SINCE(5, 11) -void tst_QDesktopWidget::screenNumberForQPoint() -{ - // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen - QDesktopWidget *desktopWidget = QApplication::desktop(); - QRect allScreens; - for (int i = 0; i < desktopWidget->numScreens(); ++i) { - QRect screenGeometry = desktopWidget->screenGeometry(i); - QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i); - allScreens |= screenGeometry; - } - - // make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen - int screen; - screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1)); - - QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); - screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1)); - QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); - screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1)); - QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); - screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1)); - QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); -} -#endif - -void tst_QDesktopWidget::screenGeometry() -{ - QDesktopWidget *desktopWidget = QApplication::desktop(); - QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt " - "to get the screen geometry of a null widget"); - QRect r = desktopWidget->screenGeometry(nullptr); - QVERIFY(r.isNull()); - QWidget widget; - widget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&widget)); - r = desktopWidget->screenGeometry(&widget); - -#if QT_DEPRECATED_SINCE(5, 11) - QRect total; - QRect available; - for (int i = 0; i < desktopWidget->screenCount(); ++i) { - total = desktopWidget->screenGeometry(i); - available = desktopWidget->availableGeometry(i); - } -#endif -} - -void tst_QDesktopWidget::topLevels() -{ - // Desktop widgets/windows should not be listed as top-levels. - int topLevelDesktopWidgets = 0; - int topLevelDesktopWindows = 0; - foreach (const QWidget *w, QApplication::topLevelWidgets()) - if (w->windowType() == Qt::Desktop) - topLevelDesktopWidgets++; - foreach (const QWindow *w, QGuiApplication::topLevelWindows()) - if (w->type() == Qt::Desktop) - topLevelDesktopWindows++; - QCOMPARE(topLevelDesktopWidgets, 0); - QCOMPARE(topLevelDesktopWindows, 0); -} -QT_WARNING_POP - -QTEST_MAIN(tst_QDesktopWidget) -#include "tst_qdesktopwidget.moc" |