summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-16 20:43:34 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-06-08 20:29:49 +0200
commit44fb925f50471ebc23dcccfaa4e9d9873b05d205 (patch)
treee4e212052b66242ff94aa98f6df7b15dbeb945f7 /tests/manual
parenta061a646429c6e9d695458fc0ecb0021a30e12ee (diff)
Phase 2 of removing QDesktopWidget
Remove QDestopWidget public header, simplify the implementation that maintains a Qt::Desktop type QWidget for each QScreen, and turn QWidget's initial target screen into a QScreen pointer. QApplication::desktop() now takes an optional QScreen pointer, and returns a QWidget pointer, so that applications and widgets can get access to the root widget for a specific screen without having to resort to private APIs. QDesktopWidgetPrivate implementations to look up a screen for an index, widget, or point are now all inline functions that thinly wrap QGuiApplication::screens/screenAt calls. We should consider adding those as convenience APIs to QScreen instead. Note that QWidget::screen is assumed to return a valid pointer; there is code that handles the case that it returns nullptr (but also code that trusts that it never is nullptr), so this needs to be defined, verified with tests, and asserted. We can then simplify the code further. Change-Id: Ifc89be65a0dce265b6729feaf54121c35137cb94 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/diaglib/qwidgetdump.cpp2
-rw-r--r--tests/manual/dialogs/printdialogpanel.cpp1
-rw-r--r--tests/manual/foreignwindows/main.cpp1
-rw-r--r--tests/manual/qcursor/qcursorhighdpi/main.cpp10
-rw-r--r--tests/manual/qdesktopwidget/CMakeLists.txt17
-rw-r--r--tests/manual/qdesktopwidget/main.cpp212
-rw-r--r--tests/manual/qdesktopwidget/qdesktopwidget.pro3
-rw-r--r--tests/manual/qscreen/main.cpp14
-rw-r--r--tests/manual/qtabbar/main.cpp1
9 files changed, 7 insertions, 254 deletions
diff --git a/tests/manual/diaglib/qwidgetdump.cpp b/tests/manual/diaglib/qwidgetdump.cpp
index 371f3e2311..21007e8df9 100644
--- a/tests/manual/diaglib/qwidgetdump.cpp
+++ b/tests/manual/diaglib/qwidgetdump.cpp
@@ -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",
diff --git a/tests/manual/dialogs/printdialogpanel.cpp b/tests/manual/dialogs/printdialogpanel.cpp
index dcd8b43bf3..7f834399e4 100644
--- a/tests/manual/dialogs/printdialogpanel.cpp
+++ b/tests/manual/dialogs/printdialogpanel.cpp
@@ -37,7 +37,6 @@
#include <QPrintPreviewDialog>
#include <QPageSetupDialog>
#include <QApplication>
-#include <QDesktopWidget>
#include <QGroupBox>
#include <QCheckBox>
#include <QLabel>
diff --git a/tests/manual/foreignwindows/main.cpp b/tests/manual/foreignwindows/main.cpp
index 843f4e39ef..436538df70 100644
--- a/tests/manual/foreignwindows/main.cpp
+++ b/tests/manual/foreignwindows/main.cpp
@@ -28,7 +28,6 @@
#include <QtGui/QAction>
#include <QtWidgets/QApplication>
-#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
diff --git a/tests/manual/qcursor/qcursorhighdpi/main.cpp b/tests/manual/qcursor/qcursorhighdpi/main.cpp
index e70be333fd..5a8bc542b9 100644
--- a/tests/manual/qcursor/qcursorhighdpi/main.cpp
+++ b/tests/manual/qcursor/qcursorhighdpi/main.cpp
@@ -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
diff --git a/tests/manual/qdesktopwidget/CMakeLists.txt b/tests/manual/qdesktopwidget/CMakeLists.txt
deleted file mode 100644
index 2034e3c368..0000000000
--- a/tests/manual/qdesktopwidget/CMakeLists.txt
+++ /dev/null
@@ -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"
diff --git a/tests/manual/qdesktopwidget/main.cpp b/tests/manual/qdesktopwidget/main.cpp
deleted file mode 100644
index 978dc62b0e..0000000000
--- a/tests/manual/qdesktopwidget/main.cpp
+++ /dev/null
@@ -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();
-}
diff --git a/tests/manual/qdesktopwidget/qdesktopwidget.pro b/tests/manual/qdesktopwidget/qdesktopwidget.pro
deleted file mode 100644
index 8979e7ef35..0000000000
--- a/tests/manual/qdesktopwidget/qdesktopwidget.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = app
-QT += widgets
-SOURCES += main.cpp
diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp
index d2c9842365..e6f0dc9fd7 100644
--- a/tests/manual/qscreen/main.cpp
+++ b/tests/manual/qscreen/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();
diff --git a/tests/manual/qtabbar/main.cpp b/tests/manual/qtabbar/main.cpp
index 82bcd838e6..6af80958cd 100644
--- a/tests/manual/qtabbar/main.cpp
+++ b/tests/manual/qtabbar/main.cpp
@@ -54,7 +54,6 @@
#include <QTabBar>
#include <QLabel>
#include <QLayout>
-#include <QDesktopWidget>
#include <QTabWidget>
#include <QProxyStyle>
#include <qdebug.h>