Cocoa: Add helper functions for NSPoint <-> QPoint(F) conversion.
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>
Tue, 20 Sep 2011 12:11:50 +0000 (14:11 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Sep 2011 15:37:34 +0000 (17:37 +0200)
... 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 <qt_sanity_bot@ovi.com>
Reviewed-by: Bjørn Erik Nilsen <bjorn.nilsen@nokia.com>
src/plugins/platforms/cocoa/qcocoahelpers.h
src/plugins/platforms/cocoa/qmultitouch_mac.mm

index 8e807cc..78904bc 100644 (file)
@@ -54,6 +54,8 @@
 //
 
 #include <private/qt_mac_p.h>
+#include <private/qguiapplication_p.h>
+#include <QtGui/qscreen.h>
 
 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
 
index f44c6a3..2f9aefc 100644 (file)
@@ -40,7 +40,7 @@
 ****************************************************************************/
 
 #include "qmultitouch_mac_p.h"
-#include <qcursor.h>
+#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];