iOS: Don't use -1 as magic value for UIDeviceOrientationFaceUp/Down

The check in [QIOSOrientationListener orientationChanged] ensured we
never reported the two unsupported orientations through QPA, but we
were reporting back the orientation through QIOSScreen::orientation()
as well, and that didn't have a guard for -1. This resulted in crashes
in client code that assumed the range of QScreen::orientation() was
defined by the enum, such as the paintedwindow example.

The listener now ignores the two unsupported orientations, which leaves
us at the previous orientation. For the conversion function, we still
have to support all UIDeviceOrientations, so we fall back to portrait
for the two unsupported orientations. In the future we should consider
caching the previous value explicitly, or fall back to the interface
orientation.

Change-Id: Ic19d0ce86b4ddea250ea927d5e8664396b2b68fd
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
Tor Arne Vestbø 2013-04-30 13:29:54 +02:00 committed by The Qt Project
parent 02e406ac50
commit 130b579a16
2 changed files with 14 additions and 4 deletions

View File

@ -104,7 +104,8 @@ Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientat
break;
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
qtOrientation = static_cast<Qt::ScreenOrientation>(-1); // not supported ATM.
// FIXME: Use cached device orientation, or fall back to interface orientation
qtOrientation = Qt::PortraitOrientation;
break;
default:
qtOrientation = Qt::PortraitOrientation;

View File

@ -83,9 +83,18 @@
- (void) orientationChanged:(NSNotification *)notification
{
Q_UNUSED(notification);
Qt::ScreenOrientation orientation = toQtScreenOrientation([UIDevice currentDevice].orientation);
if (orientation != -1)
QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), orientation);
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
switch (deviceOrientation) {
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
// We ignore these events, as iOS will send events with the 'regular'
// orientations alongside these two orientations.
return;
default:
Qt::ScreenOrientation screenOrientation = toQtScreenOrientation(deviceOrientation);
QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), screenOrientation);
}
}
@end