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 <qpa/qwindowsysteminterface.h>
45
#include <QtTest/QtTest>
47
class tst_QScreen: public QObject
52
void angleBetween_data();
54
void transformBetween_data();
55
void transformBetween();
56
void orientationChange();
59
void tst_QScreen::angleBetween_data()
61
QTest::addColumn<uint>("oa");
62
QTest::addColumn<uint>("ob");
63
QTest::addColumn<int>("expected");
65
QTest::newRow("Portrait Portrait")
66
<< uint(Qt::PortraitOrientation)
67
<< uint(Qt::PortraitOrientation)
70
QTest::newRow("Portrait Landscape")
71
<< uint(Qt::PortraitOrientation)
72
<< uint(Qt::LandscapeOrientation)
75
QTest::newRow("Portrait InvertedPortrait")
76
<< uint(Qt::PortraitOrientation)
77
<< uint(Qt::InvertedPortraitOrientation)
80
QTest::newRow("Portrait InvertedLandscape")
81
<< uint(Qt::PortraitOrientation)
82
<< uint(Qt::InvertedLandscapeOrientation)
85
QTest::newRow("InvertedLandscape InvertedPortrait")
86
<< uint(Qt::InvertedLandscapeOrientation)
87
<< uint(Qt::InvertedPortraitOrientation)
90
QTest::newRow("InvertedLandscape Landscape")
91
<< uint(Qt::InvertedLandscapeOrientation)
92
<< uint(Qt::LandscapeOrientation)
95
QTest::newRow("Landscape Primary")
96
<< uint(Qt::LandscapeOrientation)
97
<< uint(Qt::PrimaryOrientation)
98
<< QGuiApplication::primaryScreen()->angleBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation());
101
void tst_QScreen::angleBetween()
105
QFETCH( int, expected );
107
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
108
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
110
QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(a, b), expected);
111
QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(b, a), (360 - expected) % 360);
114
void tst_QScreen::transformBetween_data()
116
QTest::addColumn<uint>("oa");
117
QTest::addColumn<uint>("ob");
118
QTest::addColumn<QRect>("rect");
119
QTest::addColumn<QTransform>("expected");
121
QRect rect(0, 0, 480, 640);
123
QTest::newRow("Portrait Portrait")
124
<< uint(Qt::PortraitOrientation)
125
<< uint(Qt::PortraitOrientation)
129
QTest::newRow("Portrait Landscape")
130
<< uint(Qt::PortraitOrientation)
131
<< uint(Qt::LandscapeOrientation)
133
<< QTransform(0, -1, 1, 0, 0, rect.height());
135
QTest::newRow("Portrait InvertedPortrait")
136
<< uint(Qt::PortraitOrientation)
137
<< uint(Qt::InvertedPortraitOrientation)
139
<< QTransform(-1, 0, 0, -1, rect.width(), rect.height());
141
QTest::newRow("Portrait InvertedLandscape")
142
<< uint(Qt::PortraitOrientation)
143
<< uint(Qt::InvertedLandscapeOrientation)
145
<< QTransform(0, 1, -1, 0, rect.width(), 0);
147
QTest::newRow("InvertedLandscape InvertedPortrait")
148
<< uint(Qt::InvertedLandscapeOrientation)
149
<< uint(Qt::InvertedPortraitOrientation)
151
<< QTransform(0, 1, -1, 0, rect.width(), 0);
153
QTest::newRow("InvertedLandscape Landscape")
154
<< uint(Qt::InvertedLandscapeOrientation)
155
<< uint(Qt::LandscapeOrientation)
157
<< QTransform(-1, 0, 0, -1, rect.width(), rect.height());
159
QTest::newRow("Landscape Primary")
160
<< uint(Qt::LandscapeOrientation)
161
<< uint(Qt::PrimaryOrientation)
163
<< QGuiApplication::primaryScreen()->transformBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation(), rect);
166
void tst_QScreen::transformBetween()
170
QFETCH( QRect, rect );
171
QFETCH( QTransform, expected );
173
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
174
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
176
QCOMPARE(QGuiApplication::primaryScreen()->transformBetween(a, b, rect), expected);
179
void tst_QScreen::orientationChange()
181
qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
183
QScreen *screen = QGuiApplication::primaryScreen();
185
screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation);
187
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
188
QWindowSystemInterface::flushWindowSystemEvents();
189
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
191
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
192
QWindowSystemInterface::flushWindowSystemEvents();
193
QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
195
QSignalSpy spy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
197
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
198
QWindowSystemInterface::flushWindowSystemEvents();
199
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
200
QWindowSystemInterface::flushWindowSystemEvents();
201
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
202
QWindowSystemInterface::flushWindowSystemEvents();
204
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
205
QCOMPARE(spy.count(), 1);
208
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
209
QWindowSystemInterface::flushWindowSystemEvents();
210
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
211
QCOMPARE(spy.count(), 0);
213
screen->setOrientationUpdateMask(screen->orientationUpdateMask() | Qt::InvertedLandscapeOrientation);
214
QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation);
215
QCOMPARE(spy.count(), 1);
218
#include <tst_qscreen.moc>
219
QTEST_MAIN(tst_QScreen);