darwin: Add Foundation conversion functions for QPoint/QPointF
The fromCGPoint function was left out for QPoint, as the foundation type is using CGFloats internally. Clients should use an explicit QPointF::toPoint() when potentially throwing away precision. Change-Id: I12a37e8f81c86b7ada56066cc18ee29709cc21e3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
parent
f862946c22
commit
197471beac
@ -458,5 +458,43 @@ QRectF QRectF::fromCGRect(CGRect rect) Q_DECL_NOTHROW
|
|||||||
return QRectF(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\since 5.8
|
||||||
|
|
||||||
|
Creates a CGPoint from a QPoint.
|
||||||
|
|
||||||
|
\sa fromCGPoint()
|
||||||
|
*/
|
||||||
|
CGPoint QPoint::toCGPoint() const Q_DECL_NOTHROW
|
||||||
|
{
|
||||||
|
return CGPointMake(x(), y());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\since 5.8
|
||||||
|
|
||||||
|
Creates a CGPoint from a QPointF.
|
||||||
|
|
||||||
|
\sa fromCGPoint()
|
||||||
|
*/
|
||||||
|
CGPoint QPointF::toCGPoint() const Q_DECL_NOTHROW
|
||||||
|
{
|
||||||
|
return CGPointMake(x(), y());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\since 5.8
|
||||||
|
|
||||||
|
Creates a QRectF from a CGPoint.
|
||||||
|
|
||||||
|
\sa toCGPoint()
|
||||||
|
*/
|
||||||
|
QPointF QPointF::fromCGPoint(CGPoint point) Q_DECL_NOTHROW
|
||||||
|
{
|
||||||
|
return QPointF(point.x, point.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
|
|
||||||
#include <QtCore/qnamespace.h>
|
#include <QtCore/qnamespace.h>
|
||||||
|
|
||||||
|
#if defined(Q_OS_DARWIN)
|
||||||
|
struct CGPoint;
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
@ -89,6 +93,10 @@ public:
|
|||||||
friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &);
|
friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &);
|
||||||
friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal);
|
friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal);
|
||||||
|
|
||||||
|
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
|
||||||
|
CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QTransform;
|
friend class QTransform;
|
||||||
int xp;
|
int xp;
|
||||||
@ -247,6 +255,11 @@ public:
|
|||||||
|
|
||||||
Q_DECL_CONSTEXPR QPoint toPoint() const;
|
Q_DECL_CONSTEXPR QPoint toPoint() const;
|
||||||
|
|
||||||
|
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
|
||||||
|
static QPointF fromCGPoint(CGPoint point) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
|
||||||
|
CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QMatrix;
|
friend class QMatrix;
|
||||||
friend class QTransform;
|
friend class QTransform;
|
||||||
|
@ -61,9 +61,6 @@ class QPlatformScreen;
|
|||||||
|
|
||||||
bool isQtApplication();
|
bool isQtApplication();
|
||||||
|
|
||||||
CGPoint toCGPoint(const QPointF &point);
|
|
||||||
QPointF fromCGPoint(const CGPoint &point);
|
|
||||||
|
|
||||||
#ifndef Q_OS_TVOS
|
#ifndef Q_OS_TVOS
|
||||||
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);
|
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);
|
||||||
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation);
|
UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation);
|
||||||
|
@ -58,16 +58,6 @@ bool isQtApplication()
|
|||||||
return isQt;
|
return isQt;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint toCGPoint(const QPointF &point)
|
|
||||||
{
|
|
||||||
return CGPointMake(point.x(), point.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF fromCGPoint(const CGPoint &point)
|
|
||||||
{
|
|
||||||
return QPointF(point.x, point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef Q_OS_TVOS
|
#ifndef Q_OS_TVOS
|
||||||
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
|
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation)
|
||||||
{
|
{
|
||||||
|
@ -496,12 +496,12 @@ static void executeBlockWithoutAnimation(Block block)
|
|||||||
QGuiApplication::styleHints()->setCursorFlashTime(0);
|
QGuiApplication::styleHints()->setCursorFlashTime(0);
|
||||||
if (!_loupeLayer)
|
if (!_loupeLayer)
|
||||||
[self createLoupe];
|
[self createLoupe];
|
||||||
[self updateFocalPoint:fromCGPoint(_lastTouchPoint)];
|
[self updateFocalPoint:QPointF::fromCGPoint(_lastTouchPoint)];
|
||||||
_loupeLayer.visible = YES;
|
_loupeLayer.visible = YES;
|
||||||
break;
|
break;
|
||||||
case UIGestureRecognizerStateChanged:
|
case UIGestureRecognizerStateChanged:
|
||||||
// Tell the sub class to move the loupe to the correct position
|
// Tell the sub class to move the loupe to the correct position
|
||||||
[self updateFocalPoint:fromCGPoint(_lastTouchPoint)];
|
[self updateFocalPoint:QPointF::fromCGPoint(_lastTouchPoint)];
|
||||||
break;
|
break;
|
||||||
case UIGestureRecognizerStateEnded:
|
case UIGestureRecognizerStateEnded:
|
||||||
// Restore cursor blinking, and hide the loupe
|
// Restore cursor blinking, and hide the loupe
|
||||||
@ -526,12 +526,12 @@ static void executeBlockWithoutAnimation(Block block)
|
|||||||
|
|
||||||
- (QPointF)focalPoint
|
- (QPointF)focalPoint
|
||||||
{
|
{
|
||||||
return fromCGPoint([_loupeLayer.targetView convertPoint:_loupeLayer.focalPoint toView:_focusView]);
|
return QPointF::fromCGPoint([_loupeLayer.targetView convertPoint:_loupeLayer.focalPoint toView:_focusView]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFocalPoint:(QPointF)point
|
- (void)setFocalPoint:(QPointF)point
|
||||||
{
|
{
|
||||||
_loupeLayer.focalPoint = [_loupeLayer.targetView convertPoint:toCGPoint(point) fromView:_focusView];
|
_loupeLayer.focalPoint = [_loupeLayer.targetView convertPoint:point.toCGPoint() fromView:_focusView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
@ -548,7 +548,7 @@ static void executeBlockWithoutAnimation(Block block)
|
|||||||
|
|
||||||
// If the touch point is accepted by the sub class (e.g touch on cursor), we start a
|
// If the touch point is accepted by the sub class (e.g touch on cursor), we start a
|
||||||
// press'n'hold timer that eventually will move the state to UIGestureRecognizerStateBegan.
|
// press'n'hold timer that eventually will move the state to UIGestureRecognizerStateBegan.
|
||||||
if ([self acceptTouchesBegan:fromCGPoint(_firstTouchPoint)])
|
if ([self acceptTouchesBegan:QPointF::fromCGPoint(_firstTouchPoint)])
|
||||||
_triggerStateBeganTimer.start();
|
_triggerStateBeganTimer.start();
|
||||||
else
|
else
|
||||||
self.state = UIGestureRecognizerStateFailed;
|
self.state = UIGestureRecognizerStateFailed;
|
||||||
@ -934,7 +934,7 @@ static void executeBlockWithoutAnimation(Block block)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
|
QRectF inputRect = QGuiApplication::inputMethod()->inputItemClipRectangle();
|
||||||
QPointF touchPos = fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
||||||
if (!inputRect.contains(touchPos))
|
if (!inputRect.contains(touchPos))
|
||||||
self.state = UIGestureRecognizerStateFailed;
|
self.state = UIGestureRecognizerStateFailed;
|
||||||
|
|
||||||
@ -943,7 +943,7 @@ static void executeBlockWithoutAnimation(Block block)
|
|||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
QPointF touchPos = fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
QPointF touchPos = QPointF::fromCGPoint([static_cast<UITouch *>([touches anyObject]) locationInView:_focusView]);
|
||||||
const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
|
const QTransform mapToLocal = QGuiApplication::inputMethod()->inputItemTransform().inverted();
|
||||||
int cursorPosOnRelease = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPos * mapToLocal).toInt();
|
int cursorPosOnRelease = QInputMethod::queryFocusObject(Qt::ImCursorPosition, touchPos * mapToLocal).toInt();
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@
|
|||||||
// as we already have the QWindow positioned at the right place, we can
|
// as we already have the QWindow positioned at the right place, we can
|
||||||
// just map from the local view position to global coordinates.
|
// just map from the local view position to global coordinates.
|
||||||
// tvOS: all touches start at the center of the screen and move from there.
|
// tvOS: all touches start at the center of the screen and move from there.
|
||||||
QPoint localViewPosition = fromCGPoint([uiTouch locationInView:self]).toPoint();
|
QPoint localViewPosition = QPointF::fromCGPoint([uiTouch locationInView:self]).toPoint();
|
||||||
QPoint globalScreenPosition = m_qioswindow->mapToGlobal(localViewPosition);
|
QPoint globalScreenPosition = m_qioswindow->mapToGlobal(localViewPosition);
|
||||||
|
|
||||||
touchPoint.area = QRectF(globalScreenPosition, QSize(0, 0));
|
touchPoint.area = QRectF(globalScreenPosition, QSize(0, 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user