From d25eead30f08ccc0763d63bffdc83ba1e1a6cb91 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 24 Sep 2013 13:41:15 +0200 Subject: [PATCH] iOS: bugfix touch events to also work in inverted portrait/landscape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/plugins/platforms/ios/qioswindow.mm | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index c8d0f823f67..dbeec5f5f29 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -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); } } }