iOS: don't loose precision when converting CG types

CGRect and CGPoint consist of CGFloat variables. So
we should convert to QRectF and QPointF rather than
QRect and QPoint.

Change-Id: I76f180e4064f54d5810c49b88fdbbcd914bdb686
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2013-11-22 17:41:39 +01:00 committed by The Qt Project
parent 0bfc1c8647
commit 99474206f4
4 changed files with 16 additions and 15 deletions

View File

@ -53,10 +53,11 @@ class QPlatformScreen;
bool isQtApplication();
CGRect toCGRect(const QRect &rect);
QRect fromCGRect(const CGRect &rect);
CGPoint toCGPoint(const QPoint &point);
QPoint fromCGPoint(const CGPoint &point);
CGRect toCGRect(const QRectF &rect);
QRectF fromCGRect(const CGRect &rect);
CGPoint toCGPoint(const QPointF &point);
QPointF fromCGPoint(const CGPoint &point);
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation);
QRect fromPortraitToPrimary(const QRect &rect, QPlatformScreen *screen);

View File

@ -58,24 +58,24 @@ bool isQtApplication()
return isQt;
}
CGRect toCGRect(const QRect &rect)
CGRect toCGRect(const QRectF &rect)
{
return CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
}
QRect fromCGRect(const CGRect &rect)
QRectF fromCGRect(const CGRect &rect)
{
return QRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
return QRectF(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
CGPoint toCGPoint(const QPoint &point)
CGPoint toCGPoint(const QPointF &point)
{
return CGPointMake(point.x(), point.y());
}
QPoint fromCGPoint(const CGPoint &point)
QPointF fromCGPoint(const CGPoint &point)
{
return QPoint(point.x, point.y);
return QPointF(point.x, point.y);
}
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)

View File

@ -158,7 +158,7 @@ void QIOSScreen::updateProperties()
}
bool inPortrait = UIInterfaceOrientationIsPortrait(uiWindow.rootViewController.interfaceOrientation);
QRect geometry = inPortrait ? fromCGRect(m_uiScreen.bounds)
QRect geometry = inPortrait ? fromCGRect(m_uiScreen.bounds).toRect()
: QRect(m_uiScreen.bounds.origin.x, m_uiScreen.bounds.origin.y,
m_uiScreen.bounds.size.height, m_uiScreen.bounds.size.width);

View File

@ -188,9 +188,9 @@
actualGeometry = fromCGRect(CGRectOffset([self.superview convertRect:self.frame toView:rootView],
-rootViewPositionInRelationToRootViewController.origin.x,
-rootViewPositionInRelationToRootViewController.origin.y
+ rootView.bounds.origin.y));
+ rootView.bounds.origin.y)).toRect();
} else {
actualGeometry = fromCGRect(self.frame);
actualGeometry = fromCGRect(self.frame).toRect();
}
// Persist the actual/new geometry so that QWindow::geometry() can
@ -214,7 +214,7 @@
- (void)displayLayer:(CALayer *)layer
{
QRect geometry = fromCGRect(layer.frame);
QRect geometry = fromCGRect(layer.frame).toRect();
Q_ASSERT(m_qioswindow->geometry() == geometry);
Q_ASSERT(self.hidden == !m_qioswindow->window()->isVisible());
@ -242,7 +242,7 @@
} else {
touchPoint.state = state;
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
QPoint touchPos = fromCGPoint([uiTouch locationInView:rootView]);
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);
}