iOS: Set touch point position in screen coords.

Previously the position was set in window coordinates,
which would break for non-fullscreen windows.

Change-Id: Iefa2f590c6d62b09fc3e7fe60a882c1acd33e029
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Morten Johan Sørvig 2013-02-14 13:09:08 +01:00 committed by Tor Arne Vestbø
parent 3eeb388b42
commit 11d50be6dd
3 changed files with 19 additions and 4 deletions

View File

@ -54,6 +54,8 @@ QIOSViewController *rootViewController();
CGRect toCGRect(const QRect &rect);
QRect fromCGRect(const CGRect &rect);
CGPoint toCGPoint(const QPoint &point);
QPoint fromCGPoint(const CGPoint &point);
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation);
QRect fromPortraitToPrimary(const QRect &rect);

View File

@ -75,6 +75,16 @@ QRect fromCGRect(const CGRect &rect)
return QRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
CGPoint toCGPoint(const QPoint &point)
{
return CGPointMake(point.x(), point.y());
}
QPoint fromCGPoint(const CGPoint &point)
{
return QPoint(point.x, point.y);
}
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
{
Qt::ScreenOrientation qtOrientation;

View File

@ -177,10 +177,13 @@
touchPoint.pressure = 0.0;
// Set position
CGPoint location = [touch locationInView:self];
touchPoint.area = QRectF(location.x, location.y, 0, 0);
QSize viewSize = fromCGRect(self.frame).size();
touchPoint.normalPosition = QPointF(location.x / viewSize.width(), location.y / viewSize.height());
QRect viewGeometry = fromCGRect(self.frame);
QPoint touchViewLocation = fromCGPoint([touch 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);
}
}