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>
This commit is contained in:
Bjørn Erik Nilsen 2011-09-20 14:11:50 +02:00 committed by Qt by Nokia
parent 252d1b34b2
commit ba654f8034
2 changed files with 19 additions and 2 deletions

View 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

View 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];