#include <QGuiApplication>
#include <QRect>
-#include <QScreen>
#include "paintedwindow.h"
{
QGuiApplication app(argc, argv);
- QScreen *screen = QGuiApplication::primaryScreen();
-
- QRect screenGeometry = screen->availableGeometry();
-
- QPoint center = screenGeometry.center();
- QRect windowRect(0, 0, 480, 640);
-
PaintedWindow window;
- window.setGeometry(QRect(center - windowRect.center(), windowRect.size()));
window.show();
app.exec();
m_animation->setEndValue(qreal(1));
m_animation->setDuration(500);
- setOrientation(QGuiApplication::primaryScreen()->primaryOrientation());
+ requestWindowOrientation(Qt::PortraitOrientation);
+
+ QRect screenGeometry = screen()->availableGeometry();
+
+ QPoint center = screenGeometry.center();
+ QRect windowRect = screen()->isLandscape(windowOrientation()) ? QRect(0, 0, 640, 480) : QRect(0, 0, 480, 640);
+ setGeometry(QRect(center - windowRect.center(), windowRect.size()));
+
m_rotation = 0;
- m_targetOrientation = orientation();
- m_nextTargetOrientation = Qt::UnknownOrientation;
+ reportContentOrientationChange(screen()->orientation());
- connect(screen(), SIGNAL(currentOrientationChanged(Qt::ScreenOrientation)), this, SLOT(orientationChanged(Qt::ScreenOrientation)));
+ m_targetOrientation = contentOrientation();
+ m_nextTargetOrientation = Qt::PrimaryOrientation;
+
+ connect(screen(), SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SLOT(orientationChanged(Qt::ScreenOrientation)));
connect(m_animation, SIGNAL(finished()), this, SLOT(rotationDone()));
connect(this, SIGNAL(rotationChanged(qreal)), this, SLOT(paint()));
}
void PaintedWindow::mousePressEvent(QMouseEvent *)
{
- Qt::ScreenOrientation o = orientation();
+ Qt::ScreenOrientation o = contentOrientation();
switch (o) {
case Qt::LandscapeOrientation:
orientationChanged(Qt::PortraitOrientation);
void PaintedWindow::orientationChanged(Qt::ScreenOrientation newOrientation)
{
- if (orientation() == newOrientation)
+ if (contentOrientation() == newOrientation)
return;
if (m_animation->state() == QAbstractAnimation::Running) {
return;
}
- Qt::ScreenOrientation screenOrientation = screen()->primaryOrientation();
-
QRect rect(0, 0, width(), height());
m_prevImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
QPainter p;
p.begin(&m_prevImage);
- p.setTransform(QScreen::transformBetween(orientation(), screenOrientation, rect));
- paint(&p, QScreen::mapBetween(orientation(), screenOrientation, rect));
+ p.setTransform(screen()->transformBetween(contentOrientation(), windowOrientation(), rect));
+ paint(&p, screen()->mapBetween(contentOrientation(), windowOrientation(), rect));
p.end();
p.begin(&m_nextImage);
- p.setTransform(QScreen::transformBetween(newOrientation, screenOrientation, rect));
- paint(&p, QScreen::mapBetween(newOrientation, screenOrientation, rect));
+ p.setTransform(screen()->transformBetween(newOrientation, windowOrientation(), rect));
+ paint(&p, screen()->mapBetween(newOrientation, windowOrientation(), rect));
p.end();
- m_deltaRotation = QScreen::angleBetween(newOrientation, orientation());
+ m_deltaRotation = screen()->angleBetween(newOrientation, contentOrientation());
if (m_deltaRotation > 180)
m_deltaRotation = 180 - m_deltaRotation;
void PaintedWindow::rotationDone()
{
- setOrientation(m_targetOrientation);
- if (m_nextTargetOrientation != Qt::UnknownOrientation) {
+ reportContentOrientationChange(m_targetOrientation);
+ if (m_nextTargetOrientation != Qt::PrimaryOrientation) {
Q_ASSERT(m_animation->state() != QAbstractAnimation::Running);
orientationChanged(m_nextTargetOrientation);
- m_nextTargetOrientation = Qt::UnknownOrientation;
+ m_nextTargetOrientation = Qt::PrimaryOrientation;
}
}
{
m_context->makeCurrent(this);
- Qt::ScreenOrientation screenOrientation = screen()->primaryOrientation();
- Qt::ScreenOrientation appOrientation = orientation();
-
QRect rect(0, 0, width(), height());
QOpenGLPaintDevice device(size());
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.fillPath(path, Qt::blue);
- if (orientation() != m_targetOrientation) {
+ if (contentOrientation() != m_targetOrientation) {
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.save();
painter.translate(width() / 2, height() / 2);
painter.setOpacity(m_rotation);
painter.drawImage(0, 0, m_nextImage);
} else {
- QRect mapped = QScreen::mapBetween(appOrientation, screenOrientation, rect);
+ QRect mapped = screen()->mapBetween(contentOrientation(), windowOrientation(), rect);
- painter.setTransform(QScreen::transformBetween(appOrientation, screenOrientation, rect));
+ painter.setTransform(screen()->transformBetween(contentOrientation(), windowOrientation(), rect));
paint(&painter, mapped);
painter.end();
}
Q_DECLARE_FLAGS(WindowStates, WindowState)
enum ScreenOrientation {
- UnknownOrientation = 0x00000000,
+ PrimaryOrientation = 0x00000000,
PortraitOrientation = 0x00000001,
LandscapeOrientation = 0x00000002,
InvertedPortraitOrientation = 0x00000004,
This enum type specifies the various orientations a screen might have.
- \value UnknownOrientation The orientation is unknown or the platform doesn't support orientations.
+ \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 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.
return;
QScreen *s = e->screen.data();
- s->d_func()->currentOrientation = e->orientation;
+ s->d_func()->orientation = e->orientation;
- emit s->currentOrientationChanged(s->currentOrientation());
+ reportScreenOrientationChange(s);
+}
+
+void QGuiApplicationPrivate::reportScreenOrientationChange(QScreen *s)
+{
+ emit s->orientationChanged(s->orientation());
- QScreenOrientationChangeEvent event(s, s->currentOrientation());
+ QScreenOrientationChangeEvent event(s, s->orientation());
QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
}
QScreen *s = e->screen.data();
s->d_func()->geometry = e->geometry;
+ Qt::ScreenOrientation primaryOrientation = s->primaryOrientation();
+ Qt::ScreenOrientation orientation = s->orientation();
+ s->d_func()->updatePrimaryOrientation();
+
emit s->sizeChanged(s->size());
emit s->geometryChanged(s->geometry());
emit s->physicalDotsPerInchXChanged(s->physicalDotsPerInchX());
emit s->physicalDotsPerInchChanged(s->physicalDotsPerInch());
emit s->availableSizeChanged(s->availableSize());
emit s->availableGeometryChanged(s->availableGeometry());
+
+ if (s->primaryOrientation() != primaryOrientation)
+ emit s->primaryOrientationChanged(s->primaryOrientation());
+
+ if (s->orientation() != orientation)
+ reportScreenOrientationChange(s);
}
void QGuiApplicationPrivate::reportAvailableGeometryChange(
static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
+ static void reportScreenOrientationChange(QScreen *screen);
static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e);
}
/*!
- Reimplement this function in subclass to return the primary orientation
- of the screen, i.e. the orientation the display controller or equivalent
- expects.
-
- The default implementation returns Qt::PortraitOrientation if the
- geometry's height is greater or Qt::LandscapeOrientation if the geometry's
- width is greater.
-*/
-Qt::ScreenOrientation QPlatformScreen::primaryOrientation() const
-{
- return geometry().height() > geometry().width() ? Qt::PortraitOrientation :
- Qt::LandscapeOrientation;
-}
-
-/*!
Reimplement this function in subclass to return the current orientation
of the screen, for example based on accelerometer data to determine
- the physical screen orientation.
-
- The current orientation is only a hint to the application saying
- what the preferred application orientation should be, the application
- is free to limit itself to a certain set of supported orientations.
-
- The default implementation returns the same as primaryOrientation().
+ the device orientation.
- \sa primaryOrientation()
+ The default implementation returns Qt::PrimaryOrientation.
*/
-Qt::ScreenOrientation QPlatformScreen::currentOrientation() const
+Qt::ScreenOrientation QPlatformScreen::orientation() const
{
- return primaryOrientation();
+ return Qt::PrimaryOrientation;
}
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
- virtual Qt::ScreenOrientation currentOrientation() const;
- virtual Qt::ScreenOrientation primaryOrientation() const;
+ virtual Qt::ScreenOrientation orientation() const;
virtual QWindow *topLevelAt(const QPoint &point) const;
virtual QList<QPlatformScreen *> virtualSiblings() const;
}
/*!
- Set the orientation of the platform window's contents.
+ Handle changes to the orientation of the platform window's contents.
This is a hint to the window manager in case it needs to display
additional content like popups, dialogs, status bars, or similar
in relation to the window.
- \sa QWindow::setOrientation()
+ \sa QWindow::reportContentOrientationChange()
*/
-void QPlatformWindow::setOrientation(Qt::ScreenOrientation orientation)
+void QPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation)
{
Q_UNUSED(orientation);
}
+/*!
+ Request a different orientation of the platform window.
+
+ This tells the window manager how the window wants to be rotated in order
+ to be displayed, and how input events should be translated.
+
+ As an example, a portrait compositor might rotate the window by 90 degrees,
+ if the window is in landscape. It will also rotate input coordinates from
+ portrait to landscape such that top right in portrait gets mapped to top
+ left in landscape.
+
+ If the implementation doesn't support the requested orientation it should
+ signal this by returning an actual supported orientation.
+
+ If the implementation doesn't support rotating the window at all it should
+ return Qt::PrimaryOrientation, this is also the default value.
+
+ \sa QWindow::requestWindowOrientation()
+*/
+Qt::ScreenOrientation QPlatformWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
+{
+ Q_UNUSED(orientation);
+ return Qt::PrimaryOrientation;
+}
+
bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
{
Q_UNUSED(grab);
virtual void setOpacity(qreal level);
virtual void requestActivateWindow();
- virtual void setOrientation(Qt::ScreenOrientation orientation);
+ virtual void handleContentOrientationChange(Qt::ScreenOrientation orientation);
+ virtual Qt::ScreenOrientation requestWindowOrientation(Qt::ScreenOrientation orientation);
virtual bool setKeyboardGrabEnabled(bool grab);
virtual bool setMouseGrabEnabled(bool grab);
}
/*!
- \property QScreen::primaryOrientation
- \brief the primary screen orientation
+ \property QScreen::orientation
+ \brief the screen orientation
+
+ The screen orientation represents the physical orientation
+ of the display. For example, the screen orientation of a mobile device
+ will change based on the device is being held, and a desktop display
+ might be rotated so that it's in portrait mode.
- The primary screen orientation is the orientation that corresponds
- to an un-rotated screen buffer. When the current orientation is equal
- to the primary orientation no rotation needs to be done by the
- application.
+ \sa primaryOrientation(), orientationChanged()
*/
-Qt::ScreenOrientation QScreen::primaryOrientation() const
+Qt::ScreenOrientation QScreen::orientation() const
{
Q_D(const QScreen);
- return d->platformScreen->primaryOrientation();
+ return d->orientation == Qt::PrimaryOrientation ? primaryOrientation() : d->orientation;
}
/*!
\property QScreen::primaryOrientation
- \brief the current screen orientation
+ \brief the primary screen orientation
- The current orientation is a hint to the application saying
- what the preferred application orientation should be, based on the
- current orientation of the physical display and / or other factors.
+ The primary screen orientation is Qt::LandscapeOrientation
+ if the screen geometry's width is greater than or equal to its
+ height, or Qt::PortraitOrientation otherwise.
- \sa primaryOrientation()
- \sa currentOrientationChanged()
+ \sa primaryOrientationChanged()
*/
-Qt::ScreenOrientation QScreen::currentOrientation() const
+Qt::ScreenOrientation QScreen::primaryOrientation() const
{
Q_D(const QScreen);
- return d->currentOrientation;
+ return d->primaryOrientation;
}
// i must be power of two
rotation \a a to rotation \a b.
The result will be 0, 90, 180, or 270.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return 0;
int ia = log2(uint(a));
the resulting transform will be such that the point QPoint(0, 0) is mapped to QPoint(0, w),
and QPoint(h, w) is mapped to QPoint(0, h). Thus, the landscape coordinate system QRect(0, 0, h, w)
is mapped (with a 90 degree rotation) into the portrait coordinate system QRect(0, 0, w, h).
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return QTransform();
int angle = angleBetween(a, b);
This will flip the x and y dimensions of the rectangle if orientation \a is
Qt::PortraitOrientation or Qt::InvertedPortraitOrientation and orientation \b is
Qt::LandscapeOrientation or Qt::InvertedLandscapeOrientation, or vice versa.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return rect;
if ((a == Qt::PortraitOrientation || a == Qt::InvertedPortraitOrientation)
}
/*!
- \fn QScreen::currentOrientationChanged(Qt::ScreenOrientation orientation)
+ Convenience function to check if a screen orientation is either portrait
+ or inverted portrait.
- This signal is emitted when the current orientation of the screen
- changes. The current orientation is a hint to the application saying
- what the preferred application orientation should be, based on the
- current orientation of the physical display and / or other factors.
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
+*/
+bool QScreen::isPortrait(Qt::ScreenOrientation o)
+{
+ return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
+ || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
+}
- \sa currentOrientation()
+/*!
+ Convenience function to check if a screen orientation is either landscape
+ or inverted landscape.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
+*/
+bool QScreen::isLandscape(Qt::ScreenOrientation o)
+{
+ return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
+ || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
+}
+
+/*!
+ \fn QScreen::orientationChanged(Qt::ScreenOrientation orientation)
+
+ This signal is emitted when the orientation of the screen
+ changes.
+
+ \sa orientation()
*/
+/*!
+ \fn QScreen::primaryOrientationChanged(Qt::ScreenOrientation orientation)
+
+ This signal is emitted when the primary orientation of the screen
+ changes.
+
+ \sa primaryOrientation()
+*/
+
+void QScreenPrivate::updatePrimaryOrientation()
+{
+ primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
+}
+
QT_END_NAMESPACE
Q_PROPERTY(qreal logicalDotsPerInch READ logicalDotsPerInch NOTIFY logicalDotsPerInchChanged)
Q_PROPERTY(QSize availableSize READ availableSize NOTIFY availableSizeChanged)
Q_PROPERTY(QRect availableGeometry READ availableGeometry NOTIFY availableGeometryChanged)
- Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation CONSTANT)
- Q_PROPERTY(Qt::ScreenOrientation currentOrientation READ currentOrientation NOTIFY currentOrientationChanged)
+ Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ orientation NOTIFY primaryOrientationChanged)
+ Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
public:
QPlatformScreen *handle() const;
QRect availableVirtualGeometry() const;
Qt::ScreenOrientation primaryOrientation() const;
- Qt::ScreenOrientation currentOrientation() const;
+ Qt::ScreenOrientation orientation() const;
- static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b);
- static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
- static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
+ int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b);
+ QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
+ QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
+
+ bool isPortrait(Qt::ScreenOrientation orientation);
+ bool isLandscape(Qt::ScreenOrientation orientation);
Q_SIGNALS:
void sizeChanged(const QSize &size);
void logicalDotsPerInchChanged(qreal dpi);
void availableSizeChanged(const QSize &size);
void availableGeometryChanged(const QRect &rect);
- void currentOrientationChanged(Qt::ScreenOrientation orientation);
+ void primaryOrientationChanged(Qt::ScreenOrientation orientation);
+ void orientationChanged(Qt::ScreenOrientation orientation);
private:
QScreen(QPlatformScreen *screen);
QScreenPrivate(QPlatformScreen *screen)
: platformScreen(screen)
{
- currentOrientation = screen->currentOrientation();
+ orientation = screen->orientation();
geometry = screen->geometry();
availableGeometry = screen->availableGeometry();
logicalDpi = screen->logicalDpi();
+
+ updatePrimaryOrientation();
}
- Qt::ScreenOrientation currentOrientation;
+ void updatePrimaryOrientation();
+
+ Qt::ScreenOrientation orientation;
+ Qt::ScreenOrientation primaryOrientation;
QRect geometry;
QRect availableGeometry;
QDpi logicalDpi;
to support double and triple buffering. To release a windows memory
resources, the destroy() function.
- */
-
+ \section1 Window and content orientation
+
+ QWindow has reportContentOrientationChange() and
+ requestWindowOrientation() that can be used to specify the
+ layout of the window contents in relation to the screen. The
+ window orientation determines the actual buffer layout of the
+ window, and the windowing system uses this value to rotate the
+ window before it ends up on the display, and to ensure that input
+ coordinates are in the correct coordinate space relative to the
+ application.
+
+ On the other hand, the content orientation is simply a hint to the
+ windowing system about which orientation the window contents are in.
+ It's useful when you wish to keep the same buffer layout, but rotate
+ the contents instead, especially when doing rotation animations
+ between different orientations. The windowing system might use this
+ value to determine the layout of system popups or dialogs.
+*/
QWindow::QWindow(QScreen *targetScreen)
: QObject(*new QWindowPrivate(), 0)
, QSurface(QSurface::Window)
}
/*!
- Returns the window's currently set orientation.
+ Reports that the orientation of the window's contents have changed.
+
+ This is a hint to the window manager in case it needs to display
+ additional content like popups, dialogs, status bars, or similar
+ in relation to the window.
+
+ The recommended orientation is QScreen::orientation() but
+ an application doesn't have to support all possible orientations,
+ and thus can opt to ignore the current screen orientation.
+
+ The difference between the window and the content orientation
+ determines how much to rotate the content by. QScreen::angleBetween(),
+ QScreen::transformBetween(), and QScreen::mapBetween() can be used
+ to compute the necessary transform.
+
+ \sa requestWindowOrientation(), QScreen::orientation()
+*/
+void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
+{
+ Q_D(QWindow);
+ if (!d->platformWindow)
+ create();
+ Q_ASSERT(d->platformWindow);
+ d->contentOrientation = orientation;
+ d->platformWindow->handleContentOrientationChange(orientation);
+}
- The default value is Qt::UnknownOrientation.
+/*!
+ Returns the actual content orientation.
- \sa setOrientation(), QScreen::currentOrientation()
+ This is the last value set with reportContentOrientationChange(),
+ except Qt::PrimaryOrientation gets converted to the screen's
+ primary orientation.
*/
-Qt::ScreenOrientation QWindow::orientation() const
+Qt::ScreenOrientation QWindow::contentOrientation() const
{
Q_D(const QWindow);
- return d->orientation;
+ return d->contentOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->contentOrientation;
}
/*!
- Set the orientation of the window's contents.
+ Requests the given window orientation.
- This is a hint to the window manager in case it needs to display
- additional content like popups, dialogs, status bars, or similar
- in relation to the window.
+ The window orientation specifies how the window should be rotated
+ by the window manager in order to be displayed. Input events will
+ be correctly mapped to the given orientation.
- The recommended orientation is QScreen::currentOrientation() but
- an application doesn't have to support all possible orientations,
- and thus can opt to ignore the current screen orientation.
+ The return value is false if the system doesn't support the given
+ orientation (for example when requesting a portrait orientation
+ on a device that only handles landscape buffers, typically a desktop
+ system).
+
+ If the return value is false, call windowOrientation() to get the actual
+ supported orientation.
- \sa QScreen::currentOrientation()
+ \sa windowOrientation(), reportContentOrientationChange(), QScreen::orientation()
*/
-void QWindow::setOrientation(Qt::ScreenOrientation orientation)
+bool QWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
{
Q_D(QWindow);
- if (orientation == d->orientation)
- return;
+ if (!d->platformWindow)
+ create();
+ Q_ASSERT(d->platformWindow);
+ d->windowOrientation = d->platformWindow->requestWindowOrientation(orientation);
+ return d->windowOrientation == orientation;
+}
- d->orientation = orientation;
- if (d->platformWindow) {
- d->platformWindow->setOrientation(orientation);
- }
- emit orientationChanged(orientation);
+/*!
+ Returns the actual window orientation.
+
+ \sa requestWindowOrientation()
+*/
+Qt::ScreenOrientation QWindow::windowOrientation() const
+{
+ Q_D(const QWindow);
+ return d->windowOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : 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 orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
public:
enum SurfaceType { RasterSurface, OpenGLSurface };
bool isActive() const;
- Qt::ScreenOrientation orientation() const;
- void setOrientation(Qt::ScreenOrientation orientation);
+ void reportContentOrientationChange(Qt::ScreenOrientation orientation);
+ Qt::ScreenOrientation contentOrientation() const;
+
+ bool requestWindowOrientation(Qt::ScreenOrientation orientation);
+ Qt::ScreenOrientation windowOrientation() const;
Qt::WindowState windowState() const;
void setWindowState(Qt::WindowState state);
void screenChanged(QScreen *screen);
void xChanged(int arg);
-
void yChanged(int arg);
void widthChanged(int arg);
-
void heightChanged(int arg);
void visibleChanged(bool arg);
- void orientationChanged(Qt::ScreenOrientation arg);
-
private Q_SLOTS:
void screenDestroyed(QObject *screen);
, windowState(Qt::WindowNoState)
, resizeEventPending(true)
, positionPolicy(WindowFrameExclusive)
- , orientation(Qt::UnknownOrientation)
+ , contentOrientation(Qt::PrimaryOrientation)
+ , windowOrientation(Qt::PrimaryOrientation)
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
, transientParent(0)
Qt::WindowState windowState;
bool resizeEventPending;
PositionPolicy positionPolicy;
- Qt::ScreenOrientation orientation;
+ Qt::ScreenOrientation contentOrientation;
+ Qt::ScreenOrientation windowOrientation;
QSize minimumSize;
QSize maximumSize;
// ### react to orientation changes, too
if (window)
- d->server->appOrientationChanged(orientationAngle(window->screen()->currentOrientation()));
+ d->server->appOrientationChanged(orientationAngle(window->screen()->orientation()));
}
}
d->sendStateUpdate(/*focusChanged*/true);
<< uint(Qt::InvertedLandscapeOrientation)
<< uint(Qt::LandscapeOrientation)
<< 180;
+
+ QTest::newRow("Landscape Primary")
+ << uint(Qt::LandscapeOrientation)
+ << uint(Qt::PrimaryOrientation)
+ << QGuiApplication::primaryScreen()->angleBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation());
}
void tst_QScreen::angleBetween()
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
- QCOMPARE(QScreen::angleBetween(a, b), expected);
- QCOMPARE(QScreen::angleBetween(b, a), (360 - expected) % 360);
+ QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(a, b), expected);
+ QCOMPARE(QGuiApplication::primaryScreen()->angleBetween(b, a), (360 - expected) % 360);
}
void tst_QScreen::transformBetween_data()
<< uint(Qt::LandscapeOrientation)
<< rect
<< QTransform(-1, 0, 0, -1, rect.width(), rect.height());
+
+ QTest::newRow("Landscape Primary")
+ << uint(Qt::LandscapeOrientation)
+ << uint(Qt::PrimaryOrientation)
+ << rect
+ << QGuiApplication::primaryScreen()->transformBetween(Qt::LandscapeOrientation, QGuiApplication::primaryScreen()->primaryOrientation(), rect);
}
void tst_QScreen::transformBetween()
Qt::ScreenOrientation a = Qt::ScreenOrientation(oa);
Qt::ScreenOrientation b = Qt::ScreenOrientation(ob);
- QCOMPARE(QScreen::transformBetween(a, b, rect), expected);
+ QCOMPARE(QGuiApplication::primaryScreen()->transformBetween(a, b, rect), expected);
}
void tst_QScreen::orientationChange()
QScreen *screen = QGuiApplication::primaryScreen();
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
- QTRY_COMPARE(screen->currentOrientation(), Qt::LandscapeOrientation);
+ QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
- QTRY_COMPARE(screen->currentOrientation(), Qt::PortraitOrientation);
+ QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
}
#include <tst_qscreen.moc>
void touchToMouseTranslation();
void mouseToTouchTranslation();
void mouseToTouchLoop();
+ void orientation();
void initTestCase()
{
touchDevice = new QTouchDevice;
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false);
}
+void tst_QWindow::orientation()
+{
+ QWindow window;
+ window.setGeometry(80, 80, 40, 40);
+ window.create();
+
+ window.reportContentOrientationChange(Qt::PortraitOrientation);
+ QCOMPARE(window.contentOrientation(), Qt::PortraitOrientation);
+
+ window.reportContentOrientationChange(Qt::PrimaryOrientation);
+ QCOMPARE(window.contentOrientation(), window.screen()->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());
+}
+
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow);