42 #include <private/qmultitouch_mac_p.h> 45 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 49 #ifdef QT_MAC_USE_COCOA 52 QPointF QCocoaTouch::_screenReferencePos;
53 QPointF QCocoaTouch::_trackpadReferencePos;
54 int QCocoaTouch::_idAssignmentCount = 0;
55 int QCocoaTouch::_touchCount = 0;
56 bool QCocoaTouch::_updateInternalStateOnly =
true;
58 QCocoaTouch::QCocoaTouch(NSTouch *nstouch)
60 if (_currentTouches.size() == 0)
61 _idAssignmentCount = 0;
63 _touchPoint.setId(_idAssignmentCount++);
64 _touchPoint.setPressure(1.0);
65 _identity =
qint64([nstouch identity]);
66 _currentTouches.insert(_identity,
this);
67 updateTouchData(nstouch, NSTouchPhaseBegan);
70 QCocoaTouch::~QCocoaTouch()
72 _currentTouches.remove(_identity);
75 void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase)
80 _touchPoint.setState(toTouchPointState(phase));
85 NSPoint npos = [nstouch normalizedPosition];
87 _touchPoint.setNormalizedPos(qnpos);
89 if (_touchPoint.id() == 0 && phase == NSTouchPhaseBegan) {
90 _trackpadReferencePos = qnpos;
94 NSSize dsize = [nstouch deviceSize];
95 float ppiX = (qnpos.
x() - _trackpadReferencePos.x()) * dsize.width;
96 float ppiY = (qnpos.
y() - _trackpadReferencePos.y()) * dsize.height;
98 _touchPoint.setScreenPos(_screenReferencePos - relativePos);
101 QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch)
104 if (_currentTouches.contains(identity))
105 return _currentTouches.value(identity);
113 case NSTouchPhaseBegan:
116 case NSTouchPhaseMoved:
119 case NSTouchPhaseStationary:
122 case NSTouchPhaseEnded:
123 case NSTouchPhaseCancelled:
133 QCocoaTouch::getCurrentTouchPointList(NSEvent *
event,
bool acceptSingleTouch)
136 NSSet *ended = [
event touchesMatchingPhase:NSTouchPhaseEnded | NSTouchPhaseCancelled inView:nil];
137 NSSet *active = [
event 138 touchesMatchingPhase:NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary
140 _touchCount = [active count];
147 for (
int i=0; i<int([ended count]); ++i) {
148 NSTouch *touch = [[ended allObjects] objectAtIndex:i];
149 QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch);
151 qcocoaTouch->updateTouchData(touch, [touch phase]);
152 if (!_updateInternalStateOnly)
153 touchPoints.
insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
158 bool wasUpdateInternalStateOnly = _updateInternalStateOnly;
159 _updateInternalStateOnly = !acceptSingleTouch && _touchCount < 2;
165 for (
int i=0; i<int([active count]); ++i) {
166 NSTouch *touch = [[active allObjects] objectAtIndex:i];
167 QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch);
169 qcocoaTouch =
new QCocoaTouch(touch);
171 qcocoaTouch->updateTouchData(touch, wasUpdateInternalStateOnly ? NSTouchPhaseBegan : [touch phase]);
172 if (!_updateInternalStateOnly)
173 touchPoints.
insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
180 if (_touchCount != _currentTouches.size()) {
183 foreach (QCocoaTouch *qcocoaTouch, _currentTouches.values()) {
184 if (!_updateInternalStateOnly) {
186 touchPoints.
insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
190 _currentTouches.clear();
191 _updateInternalStateOnly = !acceptSingleTouch;
192 return touchPoints.
values();
199 if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) {
200 QCocoaTouch *qcocoaTouch = _currentTouches.values().
first();
202 touchPoints.
insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
206 qcocoaTouch->_touchPoint.setId(0);
207 _idAssignmentCount = 1;
210 return touchPoints.
values();
217 #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
#define QT_END_NAMESPACE
This macro expands to.
QList< T > values() const
Returns a list containing all the values in the map, in ascending order of their keys.
The QPointF class defines a point in the plane using floating point precision.
The QHash class is a template class that provides a hash-table-based dictionary.
qreal x() const
Returns the x-coordinate of this point.
void setState(Qt::TouchPointStates state)
#define QT_BEGIN_NAMESPACE
This macro expands to.
T & first()
Returns a reference to the first item in the list.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
TouchPointState
This enum represents the state of a touch point at the time the QTouchEvent occurred.
qreal y() const
Returns the y-coordinate of this point.
void clear()
Removes all items from the map.
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.