diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosscreen.mm | 32 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosviewcontroller.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosviewcontroller.mm | 12 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qtmain.pro | 2 |
5 files changed, 45 insertions, 5 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.h b/src/plugins/platforms/ios/qiosscreen.h index ed21e54f4a..e05a6cd6a1 100644 --- a/src/plugins/platforms/ios/qiosscreen.h +++ b/src/plugins/platforms/ios/qiosscreen.h @@ -69,9 +69,12 @@ public: UIScreen *uiScreen() const; + void setPrimaryOrientation(Qt::ScreenOrientation orientation); + private: UIScreen *m_uiScreen; QRect m_geometry; + QRect m_availableGeometry; int m_depth; QSizeF m_physicalSize; QIOSOrientationListener *m_orientationListener; diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 00deaa2fc0..f4cade2e6d 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -88,11 +88,12 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex) unscaledDpi = 132; }; - // UIScreen does not report different bounds for different orientations. We - // match this behavior by staying with a fixed QScreen geometry. CGRect bounds = [m_uiScreen bounds]; m_geometry = QRect(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); + CGRect frame = m_uiScreen.applicationFrame; + m_availableGeometry = QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); + const qreal millimetersPerInch = 25.4; m_physicalSize = QSizeF(m_geometry.size()) / unscaledDpi * millimetersPerInch; @@ -111,8 +112,7 @@ QRect QIOSScreen::geometry() const QRect QIOSScreen::availableGeometry() const { - CGRect frame = m_uiScreen.applicationFrame; - return QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); + return m_availableGeometry; } int QIOSScreen::depth() const @@ -150,6 +150,30 @@ void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) } } +void QIOSScreen::setPrimaryOrientation(Qt::ScreenOrientation orientation) +{ + // Note that UIScreen never changes orientation, but QScreen should. To work around + // this, we let QIOSViewController call us whenever interface orientation changes, and + // use that as primary orientation. After all, the viewcontrollers geometry is what we + // place QWindows on top of. A problem with this approach is that QIOSViewController is + // not in use in a mixed environment, which results in no change to primary orientation. + // We see that as acceptable since Qt should most likely not interfere with orientation + // for that case anyway. + bool portrait = screen()->isPortrait(orientation); + if (portrait && m_geometry.width() < m_geometry.height()) + return; + + // Switching portrait/landscape means swapping width/height (and adjusting x/y): + CGRect frame = m_uiScreen.applicationFrame; + m_availableGeometry = portrait ? QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height) + : QRect(frame.origin.y, m_geometry.width() - frame.size.width - frame.origin.x, frame.size.height, frame.size.width); + m_geometry = QRect(0, 0, m_geometry.height(), m_geometry.width()); + m_physicalSize = QSizeF(m_physicalSize.height(), m_physicalSize.width()); + + QWindowSystemInterface::handleScreenGeometryChange(screen(), m_geometry); + QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), m_availableGeometry); +} + UIScreen *QIOSScreen::uiScreen() const { return m_uiScreen; diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index 605f0f5b4c..d5a61cb3f4 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -40,7 +40,6 @@ ****************************************************************************/ #import <UIKit/UIKit.h> -#import <QtCore/qnamespace.h> @interface QIOSViewController : UIViewController @end diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index 3121597dba..fe9e02666f 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -43,6 +43,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/QScreen> +#include "qiosscreen.h" @implementation QIOSViewController @@ -65,5 +66,16 @@ return UIInterfaceOrientationMaskAll; } +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +{ + Q_UNUSED(fromInterfaceOrientation); + Qt::ScreenOrientation orientation = convertToQtOrientation(self.interfaceOrientation); + if (orientation == -1) + return; + + QIOSScreen *qiosScreen = static_cast<QIOSScreen *>(QGuiApplication::primaryScreen()->handle()); + qiosScreen->setPrimaryOrientation(orientation); +} + @end diff --git a/src/plugins/platforms/ios/qtmain.pro b/src/plugins/platforms/ios/qtmain.pro index 7c4c4ab398..5c290b6c00 100644 --- a/src/plugins/platforms/ios/qtmain.pro +++ b/src/plugins/platforms/ios/qtmain.pro @@ -3,6 +3,8 @@ TARGET = qiosmain PLUGIN_TYPE = platforms load(qt_plugin) +QT += gui-private + OBJECTIVE_SOURCES = qtmain.mm \ qiosviewcontroller.mm |