summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2011-09-20 14:11:50 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-20 17:37:34 +0200
commitba654f80341448acf7345a0d2ee10d1c6ea459e7 (patch)
tree9c7921810e830e2dd8b6a952c3b1f1acd16c6fc9
parent252d1b34b26779cbc1ac269f4af7fdb1f27038ef (diff)
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 <qt_sanity_bot@ovi.com> Reviewed-by: Bjørn Erik Nilsen <bjorn.nilsen@nokia.com>
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.h17
-rw-r--r--src/plugins/platforms/cocoa/qmultitouch_mac.mm4
2 files changed, 19 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h
index 8e807cc288..78904bc7a7 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.h
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.h
@@ -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
diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm
index f44c6a301e..2f9aefca52 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 <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];