From: Bjørn Erik Nilsen Date: Tue, 20 Sep 2011 12:11:50 +0000 (+0200) Subject: Cocoa: Add helper functions for NSPoint <-> QPoint(F) conversion. X-Git-Tag: qt-v5.0.0-alpha1~3525 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba654f80341448acf7345a0d2ee10d1c6ea459e7;p=profile%2Fivi%2Fqtbase.git Cocoa: Add helper functions for NSPoint <-> QPoint(F) conversion. ... and use [NSEvent mouseLocation] as global mouse position rather than relying on QCursor::pos() (which is buggy at the moment). Change-Id: Ieb8000089d0d824bed89abd8b2add9e28273f227 Reviewed-on: http://codereview.qt-project.org/5254 Reviewed-by: Qt Sanity Bot Reviewed-by: Bjørn Erik Nilsen --- diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 8e807cc..78904bc 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -54,6 +54,8 @@ // #include +#include +#include class QPixmap; class QString; @@ -85,6 +87,21 @@ CGColorSpaceRef qt_mac_genericColorSpace(); CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget); QString qt_mac_applicationName(); +inline int qt_mac_flipYCoordinate(int y) +{ return QGuiApplication::primaryScreen()->geometry().height() - y; } + +inline qreal qt_mac_flipYCoordinate(qreal y) +{ return QGuiApplication::primaryScreen()->geometry().height() - y; } + +inline QPointF qt_mac_flipPoint(const NSPoint &p) +{ return QPointF(p.x, qt_mac_flipYCoordinate(p.y)); } + +inline NSPoint qt_mac_flipPoint(const QPoint &p) +{ return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); } + +inline NSPoint qt_mac_flipPoint(const QPointF &p) +{ return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); } + #endif //QCOCOAHELPERS_H diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index f44c6a3..2f9aefc 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qmultitouch_mac_p.h" -#include +#include "qcocoahelpers.h" #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 @@ -84,7 +84,7 @@ void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase) if (_touchPoint.id == 0 && phase == NSTouchPhaseBegan) { _trackpadReferencePos = qnpos; - _screenReferencePos = QCursor::pos(); + _screenReferencePos = qt_mac_flipPoint([NSEvent mouseLocation]); } NSSize dsize = [nstouch deviceSize];