44
47
m_targetItem = target;
45
48
if (m_status != NoActiveTouch) {
46
49
qWarning("[TouchDispatcher] Changing target item in the middle of a touch stream");
47
m_status = TargetRejectedTouches;
50
setStatus(TargetRejectedTouches);
52
void TouchDispatcher::dispatch(QEvent::Type eventType,
55
void TouchDispatcher::dispatch(QTouchDevice *device,
54
56
Qt::KeyboardModifiers modifiers,
55
57
const QList<QTouchEvent::TouchPoint> &touchPoints,
72
76
dispatchAsMouse(device, modifiers, touchPoints, timestamp);
74
78
Q_ASSERT(m_status == TargetRejectedTouches);
75
#if TOUCHDISPATCHER_DEBUG
76
qDebug() << "[TouchDispatcher] Not dispatching touch event to" << m_targetItem.data()
77
<< "because it already rejected the touch stream.";
79
ugDebug("Not dispatching touch event to " << m_targetItem.data()
80
<< "because it already rejected the touch stream.");
82
84
if (eventType == QEvent::TouchEnd) {
83
m_status = NoActiveTouch;
85
setStatus(NoActiveTouch);
84
86
m_touchMouseId = -1;
118
117
createQTouchEvent(QEvent::TouchBegin, device, modifiers, targetTouchPoints, window, timestamp));
121
#if TOUCHDISPATCHER_DEBUG
122
qDebug() << "[TouchDispatcher] dispatching" << qPrintable(touchEventToString(touchEvent.data()))
123
<< "to" << targetItem;
120
ugDebug("dispatching " << qPrintable(touchEventToString(touchEvent.data()))
121
<< " to " << targetItem);
125
122
QCoreApplication::sendEvent(targetItem, touchEvent.data());
128
125
if (touchEvent->isAccepted()) {
129
#if TOUCHDISPATCHER_DEBUG
130
qDebug() << "[TouchDispatcher] Item accepted the touch event.";
132
m_status = DeliveringTouchEvents;
126
ugDebug("Item accepted the touch event.");
127
setStatus(DeliveringTouchEvents);
133
128
} else if (targetItem->acceptedMouseButtons() & Qt::LeftButton) {
134
#if TOUCHDISPATCHER_DEBUG
135
qDebug() << "[TouchDispatcher] Item rejected the touch event. Trying a QMouseEvent";
129
ugDebug("Item rejected the touch event. Trying a QMouseEvent");
137
130
// NB: Arbitrarily chose the first touch point to emulate the mouse pointer
138
131
QScopedPointer<QMouseEvent> mouseEvent(
139
132
touchToMouseEvent(QEvent::MouseButtonPress, targetTouchPoints.at(0), timestamp,
140
133
modifiers, false /* transformNeeded */));
141
134
Q_ASSERT(targetTouchPoints.at(0).state() == Qt::TouchPointPressed);
143
#if TOUCHDISPATCHER_DEBUG
144
qDebug() << "[TouchDispatcher] dispatching" << qPrintable(mouseEventToString(mouseEvent.data()))
145
<< "to" << m_targetItem.data();
136
ugDebug("dispatching " << qPrintable(mouseEventToString(mouseEvent.data()))
137
<< " to " << m_targetItem.data());
147
138
QCoreApplication::sendEvent(targetItem, mouseEvent.data());
148
139
if (mouseEvent->isAccepted()) {
149
#if TOUCHDISPATCHER_DEBUG
150
qDebug() << "[TouchDispatcher] Item accepted the QMouseEvent.";
152
m_status = DeliveringMouseEvents;
140
ugDebug("Item accepted the QMouseEvent.");
141
setStatus(DeliveringMouseEvents);
153
142
m_touchMouseId = targetTouchPoints.at(0).id();
155
144
if (checkIfDoubleClicked(timestamp)) {
156
145
QScopedPointer<QMouseEvent> doubleClickEvent(
157
146
touchToMouseEvent(QEvent::MouseButtonDblClick, targetTouchPoints.at(0), timestamp,
158
147
modifiers, false /* transformNeeded */));
159
#if TOUCHDISPATCHER_DEBUG
160
qDebug() << "[TouchDispatcher] dispatching" << qPrintable(mouseEventToString(doubleClickEvent.data()))
161
<< "to" << m_targetItem.data();
148
ugDebug("dispatching " << qPrintable(mouseEventToString(doubleClickEvent.data()))
149
<< " to " << m_targetItem.data());
163
150
QCoreApplication::sendEvent(targetItem, doubleClickEvent.data());
167
#if TOUCHDISPATCHER_DEBUG
168
qDebug() << "[TouchDispatcher] Item rejected the QMouseEvent.";
170
m_status = TargetRejectedTouches;
154
ugDebug("Item rejected the QMouseEvent.");
155
setStatus(TargetRejectedTouches);
173
#if TOUCHDISPATCHER_DEBUG
174
qDebug() << "[TouchDispatcher] Item rejected the touch event and does not accept mouse buttons.";
176
m_status = TargetRejectedTouches;
158
ugDebug("Item rejected the touch event and does not accept mouse buttons.");
159
setStatus(TargetRejectedTouches);
254
235
QScopedPointer<QMouseEvent> mouseEvent(touchToMouseEvent(eventType, *touchMouse, timestamp, modifiers,
255
236
true /* transformNeeded */));
257
#if TOUCHDISPATCHER_DEBUG
258
qDebug() << "[TouchDispatcher] dispatching" << qPrintable(mouseEventToString(mouseEvent.data()))
259
<< "to" << m_targetItem.data();
238
ugDebug("dispatching " << qPrintable(mouseEventToString(mouseEvent.data()))
239
<< " to " << m_targetItem.data());
261
240
QCoreApplication::sendEvent(m_targetItem.data(), mouseEvent.data());
366
345
return doubleClicked;
348
void TouchDispatcher::setStatus(Status status)
350
if (status != m_status) {
351
#if TOUCHDISPATCHER_DEBUG
354
ugDebug("status = NoActiveTouch");
356
case DeliveringTouchEvents:
357
ugDebug("status = DeliveringTouchEvents");
359
case DeliveringMouseEvents:
360
ugDebug("status = DeliveringMouseEvents");
362
case TargetRejectedTouches:
363
ugDebug("status = TargetRejectedTouches");
366
ugDebug("status = " << status);
374
void TouchDispatcher::reset()
376
setStatus(NoActiveTouch);
378
m_touchMousePressTimestamp =0;
381
QEvent::Type TouchDispatcher::resolveEventType(const QList<QTouchEvent::TouchPoint> &touchPoints)
383
QEvent::Type eventType;
385
Qt::TouchPointStates eventStates = 0;
386
for (int i = 0; i < touchPoints.count(); i++)
387
eventStates |= touchPoints[i].state();
389
switch (eventStates) {
390
case Qt::TouchPointPressed:
391
eventType = QEvent::TouchBegin;
393
case Qt::TouchPointReleased:
394
eventType = QEvent::TouchEnd;
397
eventType = QEvent::TouchUpdate;