summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2013-05-15 09:35:50 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-20 15:20:26 +0200
commitc30a7ecce1a236514599825cc818323d8affd9dc (patch)
tree0909ee524752eef436c03d2f735f681cd36d60c4 /src
parent2b02d9b064c2fd14a138f99777043f157772ffd3 (diff)
iOS: fix bug when reporting the screen position of touch events
The way we reported screen position (and normalized position) for touch events was just wrong. The old implementation did not take into account that a view could be anything else than a direct child of the window, which fails for many cases (e.g when using QGLWidgets). Nor did it take into account the status bar, which made it hard to push small buttons since the touch would always be slightly offset. This patch calculates the screen pos by converting the touch pos to window pos, and then subtract the application frame (that contains the size of the status bar). Change-Id: Ib7f5f6dcea3a611e1ed75d57fb4a4718564752f0 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/ios/qioswindow.mm16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm
index cd2e5f9cb9..02ac413b3b 100644
--- a/src/plugins/platforms/ios/qioswindow.mm
+++ b/src/plugins/platforms/ios/qioswindow.mm
@@ -150,6 +150,8 @@
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
{
+ QRect applicationRect = fromCGRect(self.window.screen.applicationFrame);
+
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
if (![touches containsObject:uiTouch]) {
@@ -158,14 +160,12 @@
touchPoint.state = state;
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
- // Set position
- QRect viewGeometry = fromCGRect(self.frame);
- QPoint touchViewLocation = fromCGPoint([uiTouch locationInView:self]);
- QPoint touchScreenLocation = touchViewLocation + viewGeometry.topLeft();
- touchPoint.area = QRectF(touchScreenLocation , QSize(0, 0));
-
- CGSize fullscreenSize = self.window.rootViewController.view.bounds.size;
- touchPoint.normalPosition = QPointF(touchScreenLocation.x() / fullscreenSize.width, touchScreenLocation.y() / fullscreenSize.height);
+ // 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):
+ QPoint touchPos = fromCGPoint([uiTouch locationInView:nil]);
+ touchPoint.area = QRectF(touchPos - applicationRect.topLeft(), QSize(0, 0));
+ touchPoint.normalPosition = QPointF(touchPos.x() / applicationRect.width(), touchPos.y() / applicationRect.height());
}
}
}