diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2013-09-24 13:41:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-24 14:33:00 +0200 |
commit | d25eead30f08ccc0763d63bffdc83ba1e1a6cb91 (patch) | |
tree | b2274e1afe32db56036a93c8818ccd3264802025 /src/plugins/platforms | |
parent | 413ec67fc46ad7049f870cdb8ead35149b215d45 (diff) |
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>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/ios/qioswindow.mm | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index c8d0f823f6..dbeec5f5f2 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); } } } |