diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-11-23 11:39:20 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-11-27 22:49:59 +0000 |
commit | e5ca416e2f2f17d6a4213094b547ccb6d44d4e56 (patch) | |
tree | d17fa117822dccfa73658dfe83070da630376e51 /src/plugins/platforms/windows/qwindowsscreen.cpp | |
parent | 4aedfcc4b949bd0ae0e361738e142051e1ba9b21 (diff) |
Windows QPA: Add API for setting the application orientation preference.
Dynamically load the Win32 API functions for setting the rotation
preference and map this to static functions taking a
Qt::ScreenOrientation in QWindowsScreen.
Task-number: QTBUG-49541
Change-Id: I1c81cf6274d79a023a2ee755dd7c085ffd7cc015
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsscreen.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index e69665e4a9..02696c87cd 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -325,6 +325,74 @@ void QWindowsScreen::handleChanges(const QWindowsScreenData &newData) } } +enum OrientationPreference // matching Win32 API ORIENTATION_PREFERENCE +#if defined(Q_COMPILER_CLASS_ENUM) || defined(Q_CC_MSVC) + : DWORD +#endif +{ + orientationPreferenceNone = 0, + orientationPreferenceLandscape = 0x1, + orientationPreferencePortrait = 0x2, + orientationPreferenceLandscapeFlipped = 0x4, + orientationPreferencePortraitFlipped = 0x8 +}; + +bool QWindowsScreen::setOrientationPreference(Qt::ScreenOrientation o) +{ + bool result = false; +#ifndef Q_OS_WINCE + if (QWindowsContext::user32dll.setDisplayAutoRotationPreferences) { + DWORD orientationPreference = 0; + switch (o) { + case Qt::PrimaryOrientation: + orientationPreference = orientationPreferenceNone; + break; + case Qt::PortraitOrientation: + orientationPreference = orientationPreferencePortrait; + break; + case Qt::LandscapeOrientation: + orientationPreference = orientationPreferenceLandscape; + break; + case Qt::InvertedPortraitOrientation: + orientationPreference = orientationPreferencePortraitFlipped; + break; + case Qt::InvertedLandscapeOrientation: + orientationPreference = orientationPreferenceLandscapeFlipped; + break; + } + result = QWindowsContext::user32dll.setDisplayAutoRotationPreferences(orientationPreference); + } +#endif // !Q_OS_WINCE + return result; +} + +Qt::ScreenOrientation QWindowsScreen::orientationPreference() +{ + Qt::ScreenOrientation result = Qt::PrimaryOrientation; +#ifndef Q_OS_WINCE + if (QWindowsContext::user32dll.getDisplayAutoRotationPreferences) { + DWORD orientationPreference = 0; + if (QWindowsContext::user32dll.getDisplayAutoRotationPreferences(&orientationPreference)) { + switch (orientationPreference) { + case orientationPreferenceLandscape: + result = Qt::LandscapeOrientation; + break; + case orientationPreferencePortrait: + result = Qt::PortraitOrientation; + break; + case orientationPreferenceLandscapeFlipped: + result = Qt::InvertedLandscapeOrientation; + break; + case orientationPreferencePortraitFlipped: + result = Qt::InvertedPortraitOrientation; + break; + } + } + } +#endif // !Q_OS_WINCE + return result; +} + /*! \brief Queries ClearType settings to check the pixel layout */ |