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>
This commit is contained in:
parent
772a10391e
commit
1c76aa077e
@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSurfaceFormat>
|
#include <QSurfaceFormat>
|
||||||
|
#include <QScreen>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
|
|
||||||
@ -94,8 +95,8 @@ int main(int argc, char *argv[])
|
|||||||
mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
|
mainWindow.setAttribute(Qt::WA_NoSystemBackground, false);
|
||||||
}
|
}
|
||||||
mainWindow.resize(mainWindow.sizeHint());
|
mainWindow.resize(mainWindow.sizeHint());
|
||||||
int desktopArea = QApplication::desktop()->width() *
|
int desktopArea = QGuiApplication::primaryScreen()->size().width() *
|
||||||
QApplication::desktop()->height();
|
QGuiApplication::primaryScreen()->size().height();
|
||||||
int widgetArea = mainWindow.width() * mainWindow.height();
|
int widgetArea = mainWindow.width() * mainWindow.height();
|
||||||
if (((float)widgetArea / (float)desktopArea) < 0.75f)
|
if (((float)widgetArea / (float)desktopArea) < 0.75f)
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
@ -122,8 +122,8 @@ void Window::dockUndock()
|
|||||||
if (parent()) {
|
if (parent()) {
|
||||||
setParent(nullptr);
|
setParent(nullptr);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
move(QApplication::desktop()->width() / 2 - width() / 2,
|
move(QGuiApplication::primaryScreen()->size().width() / 2 - width() / 2,
|
||||||
QApplication::desktop()->height() / 2 - height() / 2);
|
QGuiApplication::primaryScreen()->size().height() / 2 - height() / 2);
|
||||||
dockBtn->setText(tr("Dock"));
|
dockBtn->setText(tr("Dock"));
|
||||||
show();
|
show();
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,8 +220,7 @@ void QApplicationPrivate::createEventDispatcher()
|
|||||||
\li It provides localization of strings that are visible to the
|
\li It provides localization of strings that are visible to the
|
||||||
user via translate().
|
user via translate().
|
||||||
|
|
||||||
\li It provides some magical objects like the desktop() and the
|
\li It provides some magical objects like the clipboard().
|
||||||
clipboard().
|
|
||||||
|
|
||||||
\li It knows about the application's windows. You can ask which
|
\li It knows about the application's windows. You can ask which
|
||||||
widget is at a certain position using widgetAt(), get a list of
|
widget is at a certain position using widgetAt(), get a list of
|
||||||
|
@ -285,7 +285,7 @@ void tst_languageChange::retranslatability()
|
|||||||
// In case we use a Color dialog, we do not want to test for
|
// 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
|
// strings non existing in the dialog and which do not get
|
||||||
// translated.
|
// translated.
|
||||||
const QSize desktopSize = QApplication::desktop()->size();
|
const QSize desktopSize = QGuiApplication::primaryScreen()->size();
|
||||||
if (dialogType == ColorDialog && (desktopSize.width() < 480 || desktopSize.height() < 350)) {
|
if (dialogType == ColorDialog && (desktopSize.width() < 480 || desktopSize.height() < 350)) {
|
||||||
expected.remove("QColorDialog::&Basic colors");
|
expected.remove("QColorDialog::&Basic colors");
|
||||||
expected.remove("QColorDialog::&Custom colors");
|
expected.remove("QColorDialog::&Custom colors");
|
||||||
|
@ -409,7 +409,7 @@ void tst_QGraphicsEffect::opacity()
|
|||||||
|
|
||||||
void tst_QGraphicsEffect::grayscale()
|
void tst_QGraphicsEffect::grayscale()
|
||||||
{
|
{
|
||||||
if (qApp->desktop()->depth() < 24)
|
if (QGuiApplication::primaryScreen()->depth() < 24)
|
||||||
QSKIP("Test only works on 32 bit displays");
|
QSKIP("Test only works on 32 bit displays");
|
||||||
|
|
||||||
QGraphicsScene scene(0, 0, 100, 100);
|
QGraphicsScene scene(0, 0, 100, 100);
|
||||||
@ -456,7 +456,7 @@ void tst_QGraphicsEffect::grayscale()
|
|||||||
|
|
||||||
void tst_QGraphicsEffect::colorize()
|
void tst_QGraphicsEffect::colorize()
|
||||||
{
|
{
|
||||||
if (qApp->desktop()->depth() < 24)
|
if (QGuiApplication::primaryScreen()->depth() < 24)
|
||||||
QSKIP("Test only works on 32 bit displays");
|
QSKIP("Test only works on 32 bit displays");
|
||||||
|
|
||||||
QGraphicsScene scene(0, 0, 100, 100);
|
QGraphicsScene scene(0, 0, 100, 100);
|
||||||
|
@ -3433,14 +3433,14 @@ void tst_QHeaderView::statusTips()
|
|||||||
QtTestModel model(5, 5);
|
QtTestModel model(5, 5);
|
||||||
headerView.setModel(&model);
|
headerView.setModel(&model);
|
||||||
headerView.viewport()->setMouseTracking(true);
|
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)));
|
QSize(500, 500)));
|
||||||
headerView.show();
|
headerView.show();
|
||||||
QApplication::setActiveWindow(&headerView);
|
QApplication::setActiveWindow(&headerView);
|
||||||
QVERIFY(QTest::qWaitForWindowActive(&headerView));
|
QVERIFY(QTest::qWaitForWindowActive(&headerView));
|
||||||
|
|
||||||
// Ensure it is moved away first and then moved to the relevant section
|
// 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));
|
headerView.rect().bottomLeft() + QPoint(20, 20));
|
||||||
QPoint centerPoint = QRect(headerView.sectionPosition(0), 0,
|
QPoint centerPoint = QRect(headerView.sectionPosition(0), 0,
|
||||||
headerView.sectionSize(0), headerView.height()).center();
|
headerView.sectionSize(0), headerView.height()).center();
|
||||||
|
@ -4787,7 +4787,7 @@ void tst_QTreeView::statusTip()
|
|||||||
mw.setCentralWidget(view);
|
mw.setCentralWidget(view);
|
||||||
}
|
}
|
||||||
mw.statusBar();
|
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)));
|
QSize(500, 500)));
|
||||||
mw.show();
|
mw.show();
|
||||||
QApplication::setActiveWindow(&mw);
|
QApplication::setActiveWindow(&mw);
|
||||||
|
@ -2415,7 +2415,6 @@ void tst_QApplication::staticFunctions()
|
|||||||
QApplication::setStyle(QStringLiteral("blub"));
|
QApplication::setStyle(QStringLiteral("blub"));
|
||||||
QApplication::allWidgets();
|
QApplication::allWidgets();
|
||||||
QApplication::topLevelWidgets();
|
QApplication::topLevelWidgets();
|
||||||
QApplication::desktop();
|
|
||||||
QApplication::activePopupWidget();
|
QApplication::activePopupWidget();
|
||||||
QApplication::activeModalWidget();
|
QApplication::activeModalWidget();
|
||||||
QApplication::focusWidget();
|
QApplication::focusWidget();
|
||||||
|
@ -6513,7 +6513,7 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
|
|||||||
if (m_platform != QStringLiteral("xcb"))
|
if (m_platform != QStringLiteral("xcb"))
|
||||||
QSKIP("This test is for X11 only.");
|
QSKIP("This test is for X11 only.");
|
||||||
// Same size as in QWidgetPrivate::create.
|
// 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);
|
const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10);
|
||||||
|
|
||||||
{ // Maximum size.
|
{ // Maximum size.
|
||||||
@ -9262,13 +9262,11 @@ void tst_QWidget::translucentWidget()
|
|||||||
label.show();
|
label.show();
|
||||||
QVERIFY(QTest::qWaitForWindowExposed(&label));
|
QVERIFY(QTest::qWaitForWindowExposed(&label));
|
||||||
|
|
||||||
QPixmap widgetSnapshot;
|
QPixmap widgetSnapshot =
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QWidget *desktopWidget = QApplication::desktop();
|
QGuiApplication::primaryScreen()->grabWindow(0, labelPos.x(), labelPos.y(), label.width(), label.height());
|
||||||
widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
|
|
||||||
#else
|
#else
|
||||||
widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
|
label.grab(QRect(QPoint(0, 0), label.size()));
|
||||||
#endif
|
#endif
|
||||||
const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
|
const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
|
||||||
QImage expected = pm.toImage().scaled(label.devicePixelRatio() * pm.size());
|
QImage expected = pm.toImage().scaled(label.devicePixelRatio() * pm.size());
|
||||||
|
@ -901,7 +901,7 @@ void tst_QMdiArea::sizeHint()
|
|||||||
{
|
{
|
||||||
QMdiArea workspace;
|
QMdiArea workspace;
|
||||||
workspace.show();
|
workspace.show();
|
||||||
QSize desktopSize = QApplication::desktop()->size();
|
QSize desktopSize = QGuiApplication::primaryScreen()->size();
|
||||||
QSize expectedSize(desktopSize.width() * 2/3, desktopSize.height() * 2/3);
|
QSize expectedSize(desktopSize.width() * 2/3, desktopSize.height() * 2/3);
|
||||||
QCOMPARE(workspace.sizeHint(), expectedSize);
|
QCOMPARE(workspace.sizeHint(), expectedSize);
|
||||||
|
|
||||||
|
@ -504,23 +504,19 @@ static inline QString msgRgbMismatch(unsigned actual, unsigned expected)
|
|||||||
|
|
||||||
static QPixmap grabWidgetWithoutRepaint(const QWidget *widget, QRect clipArea)
|
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
|
#ifdef Q_OS_WIN
|
||||||
// OpenGL content is not properly grabbed on Windows when passing a top level widget window,
|
// OpenGL content is not properly grabbed on Windows when passing a top level widget window,
|
||||||
// because GDI functions can't grab OpenGL layer content.
|
// because GDI functions can't grab OpenGL layer content.
|
||||||
// Instead the whole screen should be captured, with an adjusted clip area, which contains
|
// Instead the whole screen should be captured, with an adjusted clip area, which contains
|
||||||
// the final composited content.
|
// the final composited content.
|
||||||
QWidget *desktopWidget = QApplication::desktop(QGuiApplication::primaryScreen());
|
windowId = 0;
|
||||||
const QWidget *mainScreenWidget = desktopWidget;
|
|
||||||
targetWidget = mainScreenWidget;
|
|
||||||
clipArea = QRect(widget->mapToGlobal(clipArea.topLeft()),
|
clipArea = QRect(widget->mapToGlobal(clipArea.topLeft()),
|
||||||
widget->mapToGlobal(clipArea.bottomRight()));
|
widget->mapToGlobal(clipArea.bottomRight()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const QWindow *window = targetWidget->window()->windowHandle();
|
|
||||||
Q_ASSERT(window);
|
|
||||||
WId windowId = window->winId();
|
|
||||||
|
|
||||||
QScreen *screen = window->screen();
|
QScreen *screen = window->screen();
|
||||||
Q_ASSERT(screen);
|
Q_ASSERT(screen);
|
||||||
|
|
||||||
|
@ -68,11 +68,11 @@ public:
|
|||||||
|
|
||||||
void tryResize(int width, int height)
|
void tryResize(int width, int height)
|
||||||
{
|
{
|
||||||
QWidget *desktop = QApplication::desktop();
|
const QSize desktopSize = QGuiApplication::primaryScreen()->size();
|
||||||
if (desktop->width() < width)
|
if (desktopSize.width() < width)
|
||||||
width = desktop->width();
|
width = desktopSize.width();
|
||||||
if (desktop->height() < height)
|
if (desktopSize.height() < height)
|
||||||
height = desktop->height();
|
height = desktopSize.height();
|
||||||
if (size() != QSize(width, height)) {
|
if (size() != QSize(width, height)) {
|
||||||
resize(width, height);
|
resize(width, height);
|
||||||
QTest::qWait(250);
|
QTest::qWait(250);
|
||||||
|
@ -228,12 +228,7 @@ void screenAdded(QScreen* screen)
|
|||||||
(screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
|
(screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
|
||||||
ScreenWatcherMainWindow *w = new ScreenWatcherMainWindow(screen);
|
ScreenWatcherMainWindow *w = new ScreenWatcherMainWindow(screen);
|
||||||
|
|
||||||
// Set the screen; this corresponds to setScreen() for the underlying
|
w->setScreen(screen);
|
||||||
// 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();
|
w->show();
|
||||||
|
|
||||||
// Position the windows so that they end up at the center of the corresponding screen.
|
// Position the windows so that they end up at the center of the corresponding screen.
|
||||||
|
@ -68,18 +68,12 @@ public:
|
|||||||
screenButton->setEnabled(false);
|
screenButton->setEnabled(false);
|
||||||
connect(screenButton, &QAbstractButton::clicked, this, &Controller::setScreen);
|
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;
|
QPushButton *exitButton = new QPushButton;
|
||||||
exitButton->setText("E&xit");
|
exitButton->setText("E&xit");
|
||||||
connect(exitButton, &QAbstractButton::clicked, QApplication::instance(), &QCoreApplication::quit);
|
connect(exitButton, &QAbstractButton::clicked, QApplication::instance(), &QCoreApplication::quit);
|
||||||
|
|
||||||
QHBoxLayout *actionLayout = new QHBoxLayout;
|
QHBoxLayout *actionLayout = new QHBoxLayout;
|
||||||
actionLayout->addWidget(screenButton);
|
actionLayout->addWidget(screenButton);
|
||||||
actionLayout->addWidget(desktopButton);
|
|
||||||
actionLayout->addWidget(exitButton);
|
actionLayout->addWidget(exitButton);
|
||||||
|
|
||||||
QGroupBox *radioGroup = new QGroupBox;
|
QGroupBox *radioGroup = new QGroupBox;
|
||||||
@ -95,7 +89,6 @@ public:
|
|||||||
if (on)
|
if (on)
|
||||||
targetScreen = count;
|
targetScreen = count;
|
||||||
screenButton->setEnabled(targetScreen != -1);
|
screenButton->setEnabled(targetScreen != -1);
|
||||||
desktopButton->setEnabled(targetScreen != -1);
|
|
||||||
});
|
});
|
||||||
groupLayout->addWidget(choice);
|
groupLayout->addWidget(choice);
|
||||||
++count;
|
++count;
|
||||||
@ -122,24 +115,8 @@ private slots:
|
|||||||
widget->updateText();
|
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:
|
private:
|
||||||
QPointer<ScreenWidget> widget = nullptr;
|
QPointer<ScreenWidget> widget = nullptr;
|
||||||
QPointer<ScreenWidget> desktopChild = nullptr;
|
|
||||||
int targetScreen = -1;
|
int targetScreen = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user