summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-12-11 19:00:36 +0100
committerTor Arne Vestbø <tor.arne.vestbo@digia.com>2014-09-24 11:53:09 +0200
commitf1970c89169ed04250f789bec589deb2813c955d (patch)
tree5995f972890b5fb1274073e6fde00cb097278a7d /src
parent0cd3416136210397ef4843224181445a81bdf0f9 (diff)
iOS: Fix touch point translation when root view controller is offset
Instead of doing manual translation of the local touch point to global screen (QScreen) coordinates we take advantage of the fact that QWindow already has a position that's adjusted for all of the view-controller offsets in its parent hierarchy. Change-Id: Ib34173db5ac053c20712dfff469c4a1286f2a324 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/ios/quiview.mm29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm
index 444017f4c7..4e720941f9 100644
--- a/src/plugins/platforms/ios/quiview.mm
+++ b/src/plugins/platforms/ios/quiview.mm
@@ -223,26 +223,29 @@
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
{
- // We deliver touch events in global coordinates. But global in this respect
- // means the same coordinate system that we use for describing the geometry
- // of the top level QWindow we're inside. And that would be the coordinate
- // system of the superview of the UIView that backs that window:
- QPlatformWindow *topLevel = m_qioswindow;
- while (QPlatformWindow *topLevelParent = topLevel->parent())
- topLevel = topLevelParent;
- UIView *rootView = reinterpret_cast<UIView *>(topLevel->winId()).superview;
- CGSize rootViewSize = rootView.frame.size;
-
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
if (![touches containsObject:uiTouch]) {
touchPoint.state = Qt::TouchPointStationary;
} else {
touchPoint.state = state;
+
+ // Touch positions are expected to be in QScreen global coordinates, and
+ // as we already have the QWindow positioned at the right place, we can
+ // just map from the local view position to global coordinates.
+ QPoint localViewPosition = fromCGPoint([uiTouch locationInView:self]).toPoint();
+ QPoint globalScreenPosition = m_qioswindow->mapToGlobal(localViewPosition);
+
+ touchPoint.area = QRectF(globalScreenPosition, QSize(0, 0));
+
+ // FIXME: Do we really need to support QTouchDevice::NormalizedPosition?
+ QSize screenSize = m_qioswindow->screen()->geometry().size();
+ touchPoint.normalPosition = QPointF(globalScreenPosition.x() / screenSize.width(),
+ globalScreenPosition.y() / screenSize.height());
+
+ // We don't claim that our touch device supports QTouchDevice::Pressure,
+ // but fill in a meaningfull value in case clients use it anyways.
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
- QPoint touchPos = fromCGPoint([uiTouch locationInView:rootView]).toPoint();
- touchPoint.area = QRectF(touchPos, QSize(0, 0));
- touchPoint.normalPosition = QPointF(touchPos.x() / rootViewSize.width, touchPos.y() / rootViewSize.height);
}
}
}