From a2010048300809f16c4de7f8f8281902098413d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Mon, 19 Sep 2011 15:05:12 +0200 Subject: Mac: Adapt multitouch code for cocoa to QWindowSystemInterface. Change-Id: I4a80ed8a497dfb1b8b477e4a40ec91a16f1bb541 Reviewed-on: http://codereview.qt-project.org/5152 Reviewed-by: Qt Sanity Bot Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/cocoa/qmultitouch_mac.mm | 40 +++++++++++-------------- src/plugins/platforms/cocoa/qmultitouch_mac_p.h | 12 ++------ 2 files changed, 20 insertions(+), 32 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index 30b0acb388..c739497387 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -39,15 +39,13 @@ ** ****************************************************************************/ -#include +#include "qmultitouch_mac_p.h" #include #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 QT_BEGIN_NAMESPACE -#ifdef QT_MAC_USE_COCOA - QHash QCocoaTouch::_currentTouches; QPointF QCocoaTouch::_screenReferencePos; QPointF QCocoaTouch::_trackpadReferencePos; @@ -60,8 +58,8 @@ QCocoaTouch::QCocoaTouch(NSTouch *nstouch) if (_currentTouches.size() == 0) _idAssignmentCount = 0; - _touchPoint.setId(_idAssignmentCount++); - _touchPoint.setPressure(1.0); + _touchPoint.id = _idAssignmentCount++; + _touchPoint.pressure = 1.0; _identity = qint64([nstouch identity]); _currentTouches.insert(_identity, this); updateTouchData(nstouch, NSTouchPhaseBegan); @@ -74,19 +72,17 @@ QCocoaTouch::~QCocoaTouch() void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase) { - if (_touchCount == 1) - _touchPoint.setState(toTouchPointState(phase) | Qt::TouchPointPrimary); - else - _touchPoint.setState(toTouchPointState(phase)); + _touchPoint.state = toTouchPointState(phase); + _touchPoint.isPrimary = (_touchCount == 1); // From the normalized position on the trackpad, calculate // where on screen the touchpoint should be according to the // reference position: NSPoint npos = [nstouch normalizedPosition]; QPointF qnpos = QPointF(npos.x, 1 - npos.y); - _touchPoint.setNormalizedPos(qnpos); + _touchPoint.normalPosition = qnpos; - if (_touchPoint.id() == 0 && phase == NSTouchPhaseBegan) { + if (_touchPoint.id == 0 && phase == NSTouchPhaseBegan) { _trackpadReferencePos = qnpos; _screenReferencePos = QCursor::pos(); } @@ -95,7 +91,7 @@ void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase) float ppiX = (qnpos.x() - _trackpadReferencePos.x()) * dsize.width; float ppiY = (qnpos.y() - _trackpadReferencePos.y()) * dsize.height; QPointF relativePos = _trackpadReferencePos - QPointF(ppiX, ppiY); - _touchPoint.setScreenPos(_screenReferencePos - relativePos); + _touchPoint.area = QRectF(_screenReferencePos - relativePos, QSize(dsize.width, dsize.height)); } QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch) @@ -129,10 +125,10 @@ Qt::TouchPointState QCocoaTouch::toTouchPointState(NSTouchPhase nsState) return qtState; } -QList +QList QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) { - QMap touchPoints; + QMap touchPoints; NSSet *ended = [event touchesMatchingPhase:NSTouchPhaseEnded | NSTouchPhaseCancelled inView:nil]; NSSet *active = [event touchesMatchingPhase:NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary @@ -150,7 +146,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) if (qcocoaTouch) { qcocoaTouch->updateTouchData(touch, [touch phase]); if (!_updateInternalStateOnly) - touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); + touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); delete qcocoaTouch; } } @@ -170,7 +166,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) else qcocoaTouch->updateTouchData(touch, wasUpdateInternalStateOnly ? NSTouchPhaseBegan : [touch phase]); if (!_updateInternalStateOnly) - touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); + touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); } // Next: sadly, we need to check that our touch hash is in @@ -182,8 +178,8 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) touchPoints.clear(); foreach (QCocoaTouch *qcocoaTouch, _currentTouches.values()) { if (!_updateInternalStateOnly) { - qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased); - touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); + qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased; + touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); } delete qcocoaTouch; } @@ -198,20 +194,18 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) { QCocoaTouch *qcocoaTouch = _currentTouches.values().first(); - qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased); - touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); + qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased; + touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); // Since this last touch also will end up beeing the first // touch (if the user adds a second finger without lifting // the first), we promote it to be the primary touch: - qcocoaTouch->_touchPoint.setId(0); + qcocoaTouch->_touchPoint.id = 0; _idAssignmentCount = 1; } return touchPoints.values(); } -#endif - QT_END_NAMESPACE #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h index c69c49984a..75967aba26 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h +++ b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h @@ -53,11 +53,9 @@ #ifndef QMULTITOUCH_MAC_P_H #define QMULTITOUCH_MAC_P_H -#ifdef QT_MAC_USE_COCOA #import -#endif -#include +#include #include #include @@ -65,12 +63,10 @@ QT_BEGIN_NAMESPACE -#ifdef QT_MAC_USE_COCOA - class QCocoaTouch { public: - static QList getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch); + static QList getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch); static void setMouseInDraggingState(bool inDraggingState); private: @@ -81,7 +77,7 @@ class QCocoaTouch static int _touchCount; static bool _updateInternalStateOnly; - QTouchEvent::TouchPoint _touchPoint; + QWindowSystemInterface::TouchPoint _touchPoint; qint64 _identity; QCocoaTouch(NSTouch *nstouch); @@ -92,8 +88,6 @@ class QCocoaTouch static Qt::TouchPointState toTouchPointState(NSTouchPhase nsState); }; -#endif // QT_MAC_USE_COCOA - QT_END_NAMESPACE #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 -- cgit v1.2.3