summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-10-13 21:00:21 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-10-14 06:38:43 +0200
commit1c76aa077e9c9d74fa2314752948896f9da381ee (patch)
treeef979f532d759c9ae061c400415afd974d3edd26
parent772a10391eead51e2c7c9b50473ef0f8096cef82 (diff)
downloadqtbase-1c76aa077e9c9d74fa2314752948896f9da381ee.tar.gz
Get rid of all usage of QApplication:desktop
Use QScreen APIs instead. Change-Id: Ie99af94fe4292223dbb165b3f5c1b74e8fe0498b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--examples/opengl/hellogl2/main.cpp5
-rw-r--r--examples/opengl/hellogl2/window.cpp4
-rw-r--r--src/widgets/kernel/qapplication.cpp3
-rw-r--r--tests/auto/other/languagechange/tst_languagechange.cpp2
-rw-r--r--tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp4
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp2
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp1
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp10
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp2
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp14
-rw-r--r--tests/benchmarks/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp10
-rw-r--r--tests/manual/qscreen/main.cpp7
-rw-r--r--tests/manual/widgets/kernel/setscreen/main.cpp23
14 files changed, 28 insertions, 63 deletions
diff --git a/examples/opengl/hellogl2/main.cpp b/examples/opengl/hellogl2/main.cpp
index e0cffaf4c2..96b96e77ee 100644
--- a/examples/opengl/hellogl2/main.cpp
+++ b/examples/opengl/hellogl2/main.cpp
@@ -50,6 +50,7 @@
#include <QApplication>
#include <QSurfaceFormat>
+#include <QScreen>
#include <QCommandLineParser>
#include <QCommandLineOption>
@@ -94,8 +95,8 @@ int main(int argc, char *argv[])
mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
}
mainWindow.resize(mainWindow.sizeHint());
- int desktopArea = QApplication::desktop()->width() *
- QApplication::desktop()->height();
+ int desktopArea = QGuiApplication::primaryScreen()->size().width() *
+ QGuiApplication::primaryScreen()->size().height();
int widgetArea = mainWindow.width() * mainWindow.height();
if (((float)widgetArea / (float)desktopArea) < 0.75f)
mainWindow.show();
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index 169f5e59c5..59570c83ca 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -122,8 +122,8 @@ void Window::dockUndock()
if (parent()) {
setParent(nullptr);
setAttribute(Qt::WA_DeleteOnClose);
- move(QApplication::desktop()->width() / 2 - width() / 2,
- QApplication::desktop()->height() / 2 - height() / 2);
+ move(QGuiApplication::primaryScreen()->size().width() / 2 - width() / 2,
+ QGuiApplication::primaryScreen()->size().height() / 2 - height() / 2);
dockBtn->setText(tr("Dock"));
show();
} else {
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index a980bcad37..bb43812619 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -220,8 +220,7 @@ void QApplicationPrivate::createEventDispatcher()
\li It provides localization of strings that are visible to the
user via translate().
- \li It provides some magical objects like the desktop() and the
- clipboard().
+ \li It provides some magical objects like the clipboard().
\li It knows about the application's windows. You can ask which
widget is at a certain position using widgetAt(), get a list of
diff --git a/tests/auto/other/languagechange/tst_languagechange.cpp b/tests/auto/other/languagechange/tst_languagechange.cpp
index 44eaa2e46f..79e05cb8a1 100644
--- a/tests/auto/other/languagechange/tst_languagechange.cpp
+++ b/tests/auto/other/languagechange/tst_languagechange.cpp
@@ -285,7 +285,7 @@ void tst_languageChange::retranslatability()
// In case we use a Color dialog, we do not want to test for
// strings non existing in the dialog and which do not get
// translated.
- const QSize desktopSize = QApplication::desktop()->size();
+ const QSize desktopSize = QGuiApplication::primaryScreen()->size();
if (dialogType == ColorDialog && (desktopSize.width() < 480 || desktopSize.height() < 350)) {
expected.remove("QColorDialog::&Basic colors");
expected.remove("QColorDialog::&Custom colors");
diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp
index 0aead57d11..16c4ba6058 100644
--- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp
+++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp
@@ -409,7 +409,7 @@ void tst_QGraphicsEffect::opacity()
void tst_QGraphicsEffect::grayscale()
{
- if (qApp->desktop()->depth() < 24)
+ if (QGuiApplication::primaryScreen()->depth() < 24)
QSKIP("Test only works on 32 bit displays");
QGraphicsScene scene(0, 0, 100, 100);
@@ -456,7 +456,7 @@ void tst_QGraphicsEffect::grayscale()
void tst_QGraphicsEffect::colorize()
{
- if (qApp->desktop()->depth() < 24)
+ if (QGuiApplication::primaryScreen()->depth() < 24)
QSKIP("Test only works on 32 bit displays");
QGraphicsScene scene(0, 0, 100, 100);
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index ff76ddc39c..9b11bcdec1 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -3433,14 +3433,14 @@ void tst_QHeaderView::statusTips()
QtTestModel model(5, 5);
headerView.setModel(&model);
headerView.viewport()->setMouseTracking(true);
- headerView.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
+ headerView.setGeometry(QRect(QPoint(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
headerView.show();
QApplication::setActiveWindow(&headerView);
QVERIFY(QTest::qWaitForWindowActive(&headerView));
// Ensure it is moved away first and then moved to the relevant section
- QTest::mouseMove(QApplication::desktop(),
+ QTest::mouseMove(&headerView,
headerView.rect().bottomLeft() + QPoint(20, 20));
QPoint centerPoint = QRect(headerView.sectionPosition(0), 0,
headerView.sectionSize(0), headerView.height()).center();
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 844c9260bf..d1adc7a29f 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -4787,7 +4787,7 @@ void tst_QTreeView::statusTip()
mw.setCentralWidget(view);
}
mw.statusBar();
- mw.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
+ mw.setGeometry(QRect(QPoint(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
mw.show();
QApplication::setActiveWindow(&mw);
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index 54a9499fbf..6c6793b26b 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -2415,7 +2415,6 @@ void tst_QApplication::staticFunctions()
QApplication::setStyle(QStringLiteral("blub"));
QApplication::allWidgets();
QApplication::topLevelWidgets();
- QApplication::desktop();
QApplication::activePopupWidget();
QApplication::activeModalWidget();
QApplication::focusWidget();
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 98cba63e6f..dbeebfa523 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -6513,7 +6513,7 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
if (m_platform != QStringLiteral("xcb"))
QSKIP("This test is for X11 only.");
// Same size as in QWidgetPrivate::create.
- const QSize desktopSize = QApplication::desktop()->size();
+ const QSize desktopSize = QGuiApplication::primaryScreen()->size();
const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10);
{ // Maximum size.
@@ -9262,13 +9262,11 @@ void tst_QWidget::translucentWidget()
label.show();
QVERIFY(QTest::qWaitForWindowExposed(&label));
- QPixmap widgetSnapshot;
-
+ QPixmap widgetSnapshot =
#ifdef Q_OS_WIN
- QWidget *desktopWidget = QApplication::desktop();
- widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
+ QGuiApplication::primaryScreen()->grabWindow(0, labelPos.x(), labelPos.y(), label.width(), label.height());
#else
- widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
+ label.grab(QRect(QPoint(0, 0), label.size()));
#endif
const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
QImage expected = pm.toImage().scaled(label.devicePixelRatio() * pm.size());
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
index 12593298e8..4914caf788 100644
--- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
@@ -901,7 +901,7 @@ void tst_QMdiArea::sizeHint()
{
QMdiArea workspace;
workspace.show();
- QSize desktopSize = QApplication::desktop()->size();
+ QSize desktopSize = QGuiApplication::primaryScreen()->size();
QSize expectedSize(desktopSize.width() * 2/3, desktopSize.height() * 2/3);
QCOMPARE(workspace.sizeHint(), expectedSize);
diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
index a18fd0299a..1e99bb4074 100644
--- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
+++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
@@ -504,23 +504,19 @@ static inline QString msgRgbMismatch(unsigned actual, unsigned expected)
static QPixmap grabWidgetWithoutRepaint(const QWidget *widget, QRect clipArea)
{
- const QWidget *targetWidget = widget;
+ const QWindow *window = widget->window()->windowHandle();
+ Q_ASSERT(window);
+ WId windowId = window->winId();
+
#ifdef Q_OS_WIN
// OpenGL content is not properly grabbed on Windows when passing a top level widget window,
// 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.
- QWidget *desktopWidget = QApplication::desktop(QGuiApplication::primaryScreen());
- const QWidget *mainScreenWidget = desktopWidget;
- targetWidget = mainScreenWidget;
+ windowId = 0;
clipArea = QRect(widget->mapToGlobal(clipArea.topLeft()),
widget->mapToGlobal(clipArea.bottomRight()));
#endif
-
- const QWindow *window = targetWidget->window()->windowHandle();
- Q_ASSERT(window);
- WId windowId = window->winId();
-
QScreen *screen = window->screen();
Q_ASSERT(screen);
diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 54bc3a0115..7be7f3f90d 100644
--- a/tests/benchmarks/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/benchmarks/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -68,11 +68,11 @@ public:
void tryResize(int width, int height)
{
- QWidget *desktop = QApplication::desktop();
- if (desktop->width() < width)
- width = desktop->width();
- if (desktop->height() < height)
- height = desktop->height();
+ const QSize desktopSize = QGuiApplication::primaryScreen()->size();
+ if (desktopSize.width() < width)
+ width = desktopSize.width();
+ if (desktopSize.height() < height)
+ height = desktopSize.height();
if (size() != QSize(width, height)) {
resize(width, height);
QTest::qWait(250);
diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp
index fced21f307..ec2203e1f1 100644
--- a/tests/manual/qscreen/main.cpp
+++ b/tests/manual/qscreen/main.cpp
@@ -228,12 +228,7 @@ void screenAdded(QScreen* screen)
(screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
ScreenWatcherMainWindow *w = new ScreenWatcherMainWindow(screen);
- // 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->setScreen(screen);
w->show();
// Position the windows so that they end up at the center of the corresponding screen.
diff --git a/tests/manual/widgets/kernel/setscreen/main.cpp b/tests/manual/widgets/kernel/setscreen/main.cpp
index 70ec067d3d..a8b9a6585a 100644
--- a/tests/manual/widgets/kernel/setscreen/main.cpp
+++ b/tests/manual/widgets/kernel/setscreen/main.cpp
@@ -68,18 +68,12 @@ public:
screenButton->setEnabled(false);
connect(screenButton, &QAbstractButton::clicked, this, &Controller::setScreen);
- QPushButton *desktopButton = new QPushButton;
- desktopButton->setText("Show on Desktop");
- desktopButton->setEnabled(false);
- connect(desktopButton, &QAbstractButton::clicked, this, &Controller::setDesktop);
-
QPushButton *exitButton = new QPushButton;
exitButton->setText("E&xit");
connect(exitButton, &QAbstractButton::clicked, QApplication::instance(), &QCoreApplication::quit);
QHBoxLayout *actionLayout = new QHBoxLayout;
actionLayout->addWidget(screenButton);
- actionLayout->addWidget(desktopButton);
actionLayout->addWidget(exitButton);
QGroupBox *radioGroup = new QGroupBox;
@@ -95,7 +89,6 @@ public:
if (on)
targetScreen = count;
screenButton->setEnabled(targetScreen != -1);
- desktopButton->setEnabled(targetScreen != -1);
});
groupLayout->addWidget(choice);
++count;
@@ -122,24 +115,8 @@ private slots:
widget->updateText();
}
- void setDesktop()
- {
- QScreen *screen = QGuiApplication::screens().at(targetScreen);
- QWidget *desktop = QApplication::desktop(screen);
- if (!desktopChild) {
- desktopChild = new ScreenWidget(desktop);
- desktopChild->setAttribute(Qt::WA_DeleteOnClose);
- desktopChild->setWindowTitle("Child of a Desktop");
- } else {
- desktopChild->setParent(desktop);
- }
- desktopChild->show();
- desktopChild->updateText();
- }
-
private:
QPointer<ScreenWidget> widget = nullptr;
- QPointer<ScreenWidget> desktopChild = nullptr;
int targetScreen = -1;
};