summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-11-18 18:25:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-20 14:10:18 +0100
commit2e2c7327dd26678d26fd7fc431a78c1d05d94411 (patch)
tree2265b1fd04d5033129bce853116dc8978bb73877 /src/plugins/platforms/ios
parentc3e949ac7dd9ddfc3c089061908000c5b4d9dc4c (diff)
iOS: Prepare platform screen for reacting to dynamic updates to properties
Change-Id: Idb378416da2b559ed88eb5a764cacff149264f70 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.h3
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm78
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.mm9
3 files changed, 45 insertions, 45 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.h b/src/plugins/platforms/ios/qiosscreen.h
index 40c7a3ccf7..e70ff4b1a9 100644
--- a/src/plugins/platforms/ios/qiosscreen.h
+++ b/src/plugins/platforms/ios/qiosscreen.h
@@ -72,13 +72,14 @@ public:
UIScreen *uiScreen() const;
- void setPrimaryOrientation(Qt::ScreenOrientation orientation);
+ void updateProperties();
private:
UIScreen *m_uiScreen;
QRect m_geometry;
QRect m_availableGeometry;
int m_depth;
+ uint m_unscaledDpi;
QSizeF m_physicalSize;
QIOSOrientationListener *m_orientationListener;
};
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index 9d01053548..2d8ff7d8e1 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -132,25 +132,14 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
m_depth = 24;
}
- int unscaledDpi = 163; // Regular iPhone DPI
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad
&& !deviceIdentifier.contains(QRegularExpression("^iPad2,[567]$")) /* excluding iPad Mini */) {
- unscaledDpi = 132;
- };
-
- 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;
-
- if (isQtApplication()) {
- // When in a non-mixed environment, let QScreen follow the current interface orientation:
- setPrimaryOrientation(toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation)));
+ m_unscaledDpi = 132;
+ } else {
+ m_unscaledDpi = 163; // Regular iPhone DPI
}
+
+ updateProperties();
}
QIOSScreen::~QIOSScreen()
@@ -158,6 +147,41 @@ QIOSScreen::~QIOSScreen()
[m_orientationListener release];
}
+void QIOSScreen::updateProperties()
+{
+ UIWindow *uiWindow = 0;
+ for (uiWindow in [[UIApplication sharedApplication] windows]) {
+ if (uiWindow.screen == m_uiScreen)
+ break;
+ }
+
+ bool inPortrait = UIInterfaceOrientationIsPortrait(uiWindow.rootViewController.interfaceOrientation);
+ QRect geometry = inPortrait ? fromCGRect(m_uiScreen.bounds)
+ : QRect(m_uiScreen.bounds.origin.x, m_uiScreen.bounds.origin.y,
+ m_uiScreen.bounds.size.height, m_uiScreen.bounds.size.width);
+
+ if (geometry != m_geometry) {
+ m_geometry = geometry;
+
+ const qreal millimetersPerInch = 25.4;
+ m_physicalSize = QSizeF(m_geometry.size()) / m_unscaledDpi * millimetersPerInch;
+
+ QWindowSystemInterface::handleScreenGeometryChange(screen(), m_geometry);
+ }
+
+ QRect availableGeometry = geometry;
+
+ CGSize applicationFrameSize = m_uiScreen.applicationFrame.size;
+ int statusBarHeight = geometry.height() - (inPortrait ? applicationFrameSize.height : applicationFrameSize.width);
+
+ availableGeometry.adjust(0, statusBarHeight, 0, 0);
+
+ if (availableGeometry != m_availableGeometry) {
+ m_availableGeometry = availableGeometry;
+ QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), m_availableGeometry);
+ }
+}
+
QRect QIOSScreen::geometry() const
{
return m_geometry;
@@ -213,28 +237,6 @@ 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):
- m_geometry = QRect(0, 0, m_geometry.height(), m_geometry.width());
- m_physicalSize = QSizeF(m_physicalSize.height(), m_physicalSize.width());
- m_availableGeometry = fromPortraitToPrimary(fromCGRect(m_uiScreen.applicationFrame), this);
-
- 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.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm
index 656a86027d..1d5e69beac 100644
--- a/src/plugins/platforms/ios/qiosviewcontroller.mm
+++ b/src/plugins/platforms/ios/qiosviewcontroller.mm
@@ -62,19 +62,16 @@
return UIInterfaceOrientationMaskAll;
}
-- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
Q_UNUSED(duration);
+ Q_UNUSED(interfaceOrientation);
if (!QCoreApplication::instance())
return; // FIXME: Store orientation for later (?)
- Qt::ScreenOrientation orientation = toQtScreenOrientation(UIDeviceOrientation(toInterfaceOrientation));
- if (orientation == -1)
- return;
-
QIOSScreen *qiosScreen = static_cast<QIOSScreen *>(QGuiApplication::primaryScreen()->handle());
- qiosScreen->setPrimaryOrientation(orientation);
+ qiosScreen->updateProperties();
}
@end