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>
This commit is contained in:
Tor Arne Vestbø 2013-12-11 19:00:36 +01:00
parent 0cd3416136
commit f1970c8916

View File

@ -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);
}
}
}