iOS: bugfix touch events to also work in inverted portrait/landscape

This patch simplifies the implementation of touch events to use a
views superview for calculating global touch coordinates rather than
the screen. This removes the need for taking orientation
into account, and will also play better along in a mixed environment.
This will also fix touch events reported for inverted orientations.

Change-Id: I0c8fd8745a1f65f0f4a97447a5676a38165ed032
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2013-09-24 13:41:15 +02:00 committed by The Qt Project
parent 413ec67fc4
commit d25eead30f

View File

@ -150,9 +150,9 @@
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
{
QPlatformScreen *screen = QGuiApplication::primaryScreen()->handle();
QRect applicationRect = fromPortraitToPrimary(fromCGRect(self.window.screen.applicationFrame), screen);
// We deliver touch events with global coordinates. But global in this respect means
// the coordinate system where this QWindow lives. And that is our superview.
CGSize parentSize = self.superview.frame.size;
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
if (![touches containsObject:uiTouch]) {
@ -160,15 +160,9 @@
} else {
touchPoint.state = state;
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
// Find the touch position relative to the window. Then calculate the screen
// position by subtracting the position of the applicationRect (since UIWindow
// does not take that into account when reporting its own frame):
QRect touchInWindow = QRect(fromCGPoint([uiTouch locationInView:nil]), QSize(0, 0));
QRect touchInScreen = fromPortraitToPrimary(touchInWindow, screen);
QPoint touchPos = touchInScreen.topLeft() - applicationRect.topLeft();
QPoint touchPos = fromCGPoint([uiTouch locationInView:self.superview]);
touchPoint.area = QRectF(touchPos, QSize(0, 0));
touchPoint.normalPosition = QPointF(touchPos.x() / applicationRect.width(), touchPos.y() / applicationRect.height());
touchPoint.normalPosition = QPointF(touchPos.x() / parentSize.width, touchPos.y() / parentSize.height);
}
}
}