summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2012-11-15 13:06:22 +0100
committerTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-02-27 23:55:45 +0100
commit92252bcb93b2e8ba8cefeadf8cc0330c8ff1c47b (patch)
treec52f107429a9f0d6ec0135bebda63050dd74dadf /src/plugins/platforms/ios
parentb3eccb0c15a3d4c9bee236c82c9a155c8752b66c (diff)
iOS: let QIOSScreen start/stop listening for device orientation
From the qpa docs, we only need to listen for device orientation if orientationUpdateMask is non-zero Change-Id: Id5e828cdff9a08794c8a029e11763cc037e1b959 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.h7
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm27
2 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.h b/src/plugins/platforms/ios/qiosscreen.h
index f17f1c1d70..ed21e54f4a 100644
--- a/src/plugins/platforms/ios/qiosscreen.h
+++ b/src/plugins/platforms/ios/qiosscreen.h
@@ -45,6 +45,7 @@
#include <UIKit/UIKit.h>
#include <qpa/qplatformscreen.h>
+#include <qiosorientationlistener.h>
QT_BEGIN_NAMESPACE
@@ -52,6 +53,7 @@ class QIOSScreen : public QPlatformScreen
{
public:
QIOSScreen(unsigned int screenIndex);
+ ~QIOSScreen();
enum ScreenIndex { MainScreen = 0 };
@@ -61,6 +63,10 @@ public:
QImage::Format format() const;
QSizeF physicalSize() const;
+ Qt::ScreenOrientation nativeOrientation() const;
+ Qt::ScreenOrientation orientation() const;
+ void setOrientationUpdateMask(Qt::ScreenOrientations mask);
+
UIScreen *uiScreen() const;
private:
@@ -68,6 +74,7 @@ private:
QRect m_geometry;
int m_depth;
QSizeF m_physicalSize;
+ QIOSOrientationListener *m_orientationListener;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index efeacb8cb6..00deaa2fc0 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -41,6 +41,7 @@
#include "qiosscreen.h"
#include "qioswindow.h"
+#include <qpa/qwindowsysteminterface.h>
#include <sys/sysctl.h>
@@ -68,6 +69,7 @@ static QString deviceModelIdentifier()
QIOSScreen::QIOSScreen(unsigned int screenIndex)
: QPlatformScreen()
, m_uiScreen([[UIScreen screens] objectAtIndex:qMin(screenIndex, [[UIScreen screens] count] - 1)])
+ , m_orientationListener(0)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -97,6 +99,11 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
[pool release];
}
+QIOSScreen::~QIOSScreen()
+{
+ [m_orientationListener release];
+}
+
QRect QIOSScreen::geometry() const
{
return m_geometry;
@@ -123,6 +130,26 @@ QSizeF QIOSScreen::physicalSize() const
return m_physicalSize;
}
+Qt::ScreenOrientation QIOSScreen::nativeOrientation() const
+{
+ return Qt::PortraitOrientation;
+}
+
+Qt::ScreenOrientation QIOSScreen::orientation() const
+{
+ return m_orientationListener ? m_orientationListener->m_orientation : nativeOrientation();
+}
+
+void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
+{
+ if (m_orientationListener && mask == Qt::PrimaryOrientation) {
+ [m_orientationListener release];
+ m_orientationListener = 0;
+ } else if (!m_orientationListener) {
+ m_orientationListener = [[QIOSOrientationListener alloc] initWithQIOSScreen:this];
+ }
+}
+
UIScreen *QIOSScreen::uiScreen() const
{
return m_uiScreen;