summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosscreen.mm
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2012-12-17 10:59:45 +0100
committerTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-02-27 23:55:54 +0100
commit70774d021a4ddb6437646ab09bde0928e30c8a90 (patch)
tree882585d10a3db42b426694de7dbe89c0c834fdc9 /src/plugins/platforms/ios/qiosscreen.mm
parentd5d3f5ea8e6620e1ae06488a9e35a36550367726 (diff)
iOS: refactor QIOSOrientationListener into QIOSScreen
Clean up a bit. The orientation conversion functions belongs to QIOSScreen more than QIOSOrientationListener. And rename them in the same go to follow toQRect/fromQRect standard. The orientation listener itself is tightly coupled to QIOSScreen, and does not make much sense on its own, so move it into QIOSScreen to follow the same patteren already implemented for QIOSInputContext. Change-Id: I8b6b4d08a42349b4232749d59d46748297083536 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qiosscreen.mm')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm90
1 files changed, 89 insertions, 1 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index f4cade2e6d..02d719eaf1 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -45,8 +45,96 @@
#include <sys/sysctl.h>
+@interface QIOSOrientationListener : NSObject {
+ @public
+ QIOSScreen *m_screen;
+}
+- (id) initWithQIOSScreen:(QIOSScreen *)screen;
+@end
+
+@implementation QIOSOrientationListener
+
+- (id) initWithQIOSScreen:(QIOSScreen *)screen
+{
+ self = [super init];
+ if (self) {
+ m_screen = screen;
+ [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(orientationChanged:)
+ name:@"UIDeviceOrientationDidChangeNotification" object:nil];
+ }
+ return self;
+}
+
+- (void) dealloc
+{
+ [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
+ [[NSNotificationCenter defaultCenter]
+ removeObserver:self
+ name:@"UIDeviceOrientationDidChangeNotification" object:nil];
+ [super dealloc];
+}
+
+- (void) orientationChanged:(NSNotification *)notification
+{
+ Q_UNUSED(notification);
+ Qt::ScreenOrientation orientation = toQtScreenOrientation([UIDevice currentDevice].orientation);
+ if (orientation != -1)
+ QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), orientation);
+}
+
+@end
+
QT_BEGIN_NAMESPACE
+Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
+{
+ Qt::ScreenOrientation qtOrientation;
+ switch (uiDeviceOrientation) {
+ case UIDeviceOrientationPortraitUpsideDown:
+ qtOrientation = Qt::InvertedPortraitOrientation;
+ break;
+ case UIDeviceOrientationLandscapeLeft:
+ qtOrientation = Qt::InvertedLandscapeOrientation;
+ break;
+ case UIDeviceOrientationLandscapeRight:
+ qtOrientation = Qt::LandscapeOrientation;
+ break;
+ case UIDeviceOrientationFaceUp:
+ case UIDeviceOrientationFaceDown:
+ qtOrientation = static_cast<Qt::ScreenOrientation>(-1); // not supported ATM.
+ break;
+ default:
+ qtOrientation = Qt::PortraitOrientation;
+ break;
+ }
+ return qtOrientation;
+}
+
+UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation)
+{
+ UIDeviceOrientation uiOrientation;
+ switch (qtOrientation) {
+ case Qt::LandscapeOrientation:
+ uiOrientation = UIDeviceOrientationLandscapeRight;
+ break;
+ case Qt::InvertedLandscapeOrientation:
+ uiOrientation = UIDeviceOrientationLandscapeLeft;
+ break;
+ case Qt::InvertedPortraitOrientation:
+ uiOrientation = UIDeviceOrientationPortraitUpsideDown;
+ break;
+ case Qt::PrimaryOrientation:
+ case Qt::PortraitOrientation:
+ default:
+ uiOrientation = UIDeviceOrientationPortrait;
+ break;
+ }
+ return uiOrientation;
+}
+
/*!
Returns the model identifier of the device.
@@ -137,7 +225,7 @@ Qt::ScreenOrientation QIOSScreen::nativeOrientation() const
Qt::ScreenOrientation QIOSScreen::orientation() const
{
- return m_orientationListener ? m_orientationListener->m_orientation : nativeOrientation();
+ return toQtScreenOrientation([UIDevice currentDevice].orientation);
}
void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)