1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
43
#include <QtTest/QtTest>
44
#include <QtWidgets/QDesktopWidget>
47
class tst_QDesktopWidget : public QObject
53
virtual ~tst_QDesktopWidget();
62
void screenNumberForQWidget();
63
void screenNumberForQPoint();
64
void availableGeometry();
65
void screenGeometry();
68
tst_QDesktopWidget::tst_QDesktopWidget()
72
tst_QDesktopWidget::~tst_QDesktopWidget()
76
void tst_QDesktopWidget::init()
80
void tst_QDesktopWidget::cleanup()
84
void tst_QDesktopWidget::numScreens()
86
QDesktopWidget desktop;
87
QVERIFY(desktop.numScreens() > 0);
90
void tst_QDesktopWidget::primaryScreen()
92
QDesktopWidget desktop;
93
QVERIFY(desktop.primaryScreen() >= 0);
94
QVERIFY(desktop.primaryScreen() < desktop.numScreens());
97
void tst_QDesktopWidget::availableGeometry()
99
QDesktopWidget desktop;
100
QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt "
101
"to get the available geometry of a null widget");
102
desktop.availableGeometry((QWidget *)0);
107
for (int i = 0; i < desktop.screenCount(); ++i) {
108
total = desktop.screenGeometry(i);
109
available = desktop.availableGeometry(i);
110
QVERIFY(total.contains(available));
113
total = desktop.screenGeometry();
114
available = desktop.availableGeometry();
115
QVERIFY(total.contains(available));
116
QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available);
117
QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total);
120
void tst_QDesktopWidget::screenNumberForQWidget()
122
QDesktopWidget desktop;
124
QCOMPARE(desktop.screenNumber(0), 0);
128
QVERIFY(QTest::qWaitForWindowExposed(&widget));
129
QVERIFY(widget.isVisible());
131
int widgetScreen = desktop.screenNumber(&widget);
132
QVERIFY(widgetScreen > -1);
133
QVERIFY(widgetScreen < desktop.numScreens());
136
void tst_QDesktopWidget::screenNumberForQPoint()
138
// make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen
139
QDesktopWidget *desktopWidget = QApplication::desktop();
141
for (int i = 0; i < desktopWidget->numScreens(); ++i) {
142
QRect screenGeometry = desktopWidget->screenGeometry(i);
143
QCOMPARE(desktopWidget->screenNumber(screenGeometry.center()), i);
144
allScreens |= screenGeometry;
147
// make sure QDesktopWidget::screenNumber(QPoint) returns a valid screen for points that aren't on any screen
149
screen = desktopWidget->screenNumber(allScreens.topLeft() - QPoint(1, 1));
151
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
152
screen = desktopWidget->screenNumber(allScreens.topRight() + QPoint(1, 1));
153
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
154
screen = desktopWidget->screenNumber(allScreens.bottomLeft() - QPoint(1, 1));
155
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
156
screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1));
157
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
160
void tst_QDesktopWidget::screenGeometry()
162
QDesktopWidget *desktopWidget = QApplication::desktop();
163
QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt "
164
"to get the screen geometry of a null widget");
165
QRect r = desktopWidget->screenGeometry((QWidget *)0);
169
QVERIFY(QTest::qWaitForWindowExposed(&widget));
170
r = desktopWidget->screenGeometry(&widget);
174
for (int i = 0; i < desktopWidget->screenCount(); ++i) {
175
total = desktopWidget->screenGeometry(i);
176
available = desktopWidget->availableGeometry(i);
180
QTEST_MAIN(tst_QDesktopWidget)
181
#include "tst_qdesktopwidget.moc"