This enum type specifies the various orientations a screen might have.
- \value PrimaryOrientation The display's primary orientation. The QWindow and QScreen APIs never return this value,
- instead it will be mapped to the corresponding QScreen's QScreen::primaryOrientation().
+ \value PrimaryOrientation The display's primary orientation.
\value LandscapeOrientation Landscape orientation, display width is greater than display height.
\value PortraitOrientation Portrait orientation, display height is greater than display width,
rotated 90 degree clockwise relative to landscape.
will change based on the device is being held, and a desktop display
might be rotated so that it's in portrait mode.
+ Qt::PrimaryOrientation is never returned.
+
\sa primaryOrientation(), orientationChanged()
*/
Qt::ScreenOrientation QScreen::orientation() const
void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
{
Q_D(QWindow);
+ if (d->contentOrientation == orientation)
+ return;
if (!d->platformWindow)
create();
Q_ASSERT(d->platformWindow);
d->contentOrientation = orientation;
d->platformWindow->handleContentOrientationChange(orientation);
+ emit contentOrientationChanged(orientation);
}
/*!
Returns the actual content orientation.
- This is the last value set with reportContentOrientationChange(),
- except Qt::PrimaryOrientation gets converted to the screen's
- primary orientation.
+ This is the last value set with reportContentOrientationChange(). It defaults
+ to Qt::PrimaryOrientation.
*/
Qt::ScreenOrientation QWindow::contentOrientation() const
{
Q_D(const QWindow);
- return d->contentOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->contentOrientation;
+ return d->contentOrientation;
}
/*!
/*!
Returns the actual window orientation.
+ The default value is Qt::PrimaryOrientation.
+
\sa requestWindowOrientation()
*/
Qt::ScreenOrientation QWindow::windowOrientation() const
{
Q_D(const QWindow);
- return d->windowOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->windowOrientation;
+ return d->windowOrientation;
}
Qt::WindowState QWindow::windowState() const
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
+ Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
public:
enum SurfaceType { RasterSurface, OpenGLSurface };
void heightChanged(int arg);
void visibleChanged(bool arg);
+ void contentOrientationChanged(Qt::ScreenOrientation orientation);
private Q_SLOTS:
void screenDestroyed(QObject *screen);
QCOMPARE(window.contentOrientation(), Qt::PortraitOrientation);
window.reportContentOrientationChange(Qt::PrimaryOrientation);
- QCOMPARE(window.contentOrientation(), window.screen()->primaryOrientation());
+ QCOMPARE(window.contentOrientation(), Qt::PrimaryOrientation);
QVERIFY(!window.requestWindowOrientation(Qt::LandscapeOrientation) || window.windowOrientation() == Qt::LandscapeOrientation);
QVERIFY(!window.requestWindowOrientation(Qt::PortraitOrientation) || window.windowOrientation() == Qt::PortraitOrientation);
- QVERIFY(!window.requestWindowOrientation(Qt::PrimaryOrientation) || window.windowOrientation() == window.screen()->primaryOrientation());
+ QVERIFY(!window.requestWindowOrientation(Qt::PrimaryOrientation) || window.windowOrientation() == Qt::PrimaryOrientation);
+
+ QSignalSpy spy(&window, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)));
+ window.reportContentOrientationChange(Qt::LandscapeOrientation);
+ QCOMPARE(spy.count(), 1);
}
#include <tst_qwindow.moc>