diff options
author | Andrew Knight <andrew.knight@digia.com> | 2013-10-06 15:11:36 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-12 01:13:59 +0200 |
commit | 63348f43adc93d1c497cb86631d6b7765cc376b2 (patch) | |
tree | 2fb43ee9c799712474134286c17c8da6961d305a /src/plugins/platforms/winrt | |
parent | 6719307a891e3e935e5a589aaceeefb884772378 (diff) |
WinRT: Improve orientation handling
Support setting the update mask.
Change-Id: I88f4dddd9af5203ec47c70ad3381436caf140fef
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtscreen.cpp | 48 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtscreen.h | 1 |
2 files changed, 33 insertions, 16 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 59182ca183..8bc778ef11 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -84,21 +84,32 @@ typedef ITypedEventHandler<CoreWindow*, AutomationProviderRequestedEventArgs*> A QT_BEGIN_NAMESPACE -static inline Qt::ScreenOrientation qOrientationFromNative(DisplayOrientations orientation) +static inline Qt::ScreenOrientations qtOrientationsFromNative(DisplayOrientations native) { - switch (orientation) { - default: - case DisplayOrientations_None: - return Qt::PrimaryOrientation; - case DisplayOrientations_Landscape: - return Qt::LandscapeOrientation; - case DisplayOrientations_LandscapeFlipped: - return Qt::InvertedLandscapeOrientation; - case DisplayOrientations_Portrait: - return Qt::PortraitOrientation; - case DisplayOrientations_PortraitFlipped: - return Qt::InvertedPortraitOrientation; - } + Qt::ScreenOrientations orientations = Qt::PrimaryOrientation; + if (native & DisplayOrientations_Portrait) + orientations |= Qt::PortraitOrientation; + if (native & DisplayOrientations_PortraitFlipped) + orientations |= Qt::InvertedPortraitOrientation; + if (native & DisplayOrientations_Landscape) + orientations |= Qt::LandscapeOrientation; + if (native & DisplayOrientations_LandscapeFlipped) + orientations |= Qt::InvertedLandscapeOrientation; + return orientations; +} + +static inline DisplayOrientations nativeOrientationsFromQt(Qt::ScreenOrientations orientation) +{ + DisplayOrientations native = DisplayOrientations_None; + if (orientation & Qt::PortraitOrientation) + native |= DisplayOrientations_Portrait; + if (orientation & Qt::InvertedPortraitOrientation) + native |= DisplayOrientations_PortraitFlipped; + if (orientation & Qt::LandscapeOrientation) + native |= DisplayOrientations_Landscape; + if (orientation & Qt::InvertedLandscapeOrientation) + native |= DisplayOrientations_LandscapeFlipped; + return native; } static inline Qt::KeyboardModifiers qKeyModifiers(ICoreWindow *window) @@ -533,7 +544,7 @@ QWinRTScreen::QWinRTScreen(ICoreWindow *window) // Set native orientation DisplayOrientations displayOrientation; m_displayProperties->get_NativeOrientation(&displayOrientation); - m_nativeOrientation = qOrientationFromNative(displayOrientation); + m_nativeOrientation = static_cast<Qt::ScreenOrientation>(static_cast<int>(qtOrientationsFromNative(displayOrientation))); // Set initial orientation onOrientationChanged(0); @@ -588,6 +599,11 @@ Qt::ScreenOrientation QWinRTScreen::orientation() const return m_orientation; } +void QWinRTScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) +{ + m_displayProperties->put_AutoRotationPreferences(nativeOrientationsFromQt(mask)); +} + ICoreWindow *QWinRTScreen::coreWindow() const { return m_coreWindow; @@ -1004,7 +1020,7 @@ HRESULT QWinRTScreen::onOrientationChanged(IInspectable *) { DisplayOrientations displayOrientation; m_displayProperties->get_CurrentOrientation(&displayOrientation); - Qt::ScreenOrientation newOrientation = qOrientationFromNative(displayOrientation); + Qt::ScreenOrientation newOrientation = static_cast<Qt::ScreenOrientation>(static_cast<int>(qtOrientationsFromNative(displayOrientation))); if (m_orientation != newOrientation) { m_orientation = newOrientation; QWindowSystemInterface::handleScreenOrientationChange(screen(), m_orientation); diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h index d0ac53d56d..83f359ce6d 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.h +++ b/src/plugins/platforms/winrt/qwinrtscreen.h @@ -105,6 +105,7 @@ public: Qt::ScreenOrientation nativeOrientation() const; Qt::ScreenOrientation orientation() const; + void setOrientationUpdateMask(Qt::ScreenOrientations mask); QWindow *topWindow() const; void addWindow(QWindow *window); |