@@ -125,23 +125,18 @@ void TouchGate::storeTouchEvent(const QTouchEvent *event)
125 qDebug() << "[TouchGate] Storing" << qPrintable(touchEventToString(event));
125 qDebug() << "[TouchGate] Storing" << qPrintable(touchEventToString(event));
128− QTouchEvent *clonedEvent = new QTouchEvent(event->type(),
128+ TouchEvent clonedEvent(event);
131− event->touchPointStates(),
132− event->touchPoints());
134− m_storedEvents.append(clonedEvent);
129+ m_storedEvents.append(std::move(clonedEvent));
137void TouchGate::removeTouchFromStoredEvents(int touchId)
132void TouchGate::removeTouchFromStoredEvents(int touchId)
139 int i = 0;
134 int i = 0;
140 while (i < m_storedEvents.count()) {
135 while (i < m_storedEvents.count()) {
141− QTouchEvent *event = m_storedEvents[i];
136+ TouchEvent &event = m_storedEvents[i];
142− bool removed = removeTouchFromEvent(touchId, event);
137+ bool removed = event.removeTouch(touchId);
144− if (removed && event->touchPoints().isEmpty()) {
139+ if (removed && event.touchPoints.isEmpty()) {
145 m_storedEvents.removeAt(i);
140 m_storedEvents.removeAt(i);
@@ -149,33 +144,11 @@ void TouchGate::removeTouchFromStoredEvents(int touchId)
152−bool TouchGate::removeTouchFromEvent(int touchId, QTouchEvent *event)
154− const QList<QTouchEvent::TouchPoint> &eventTouchPoints = event->touchPoints();
156− int indexToRemove = -1;
157− for (int i = 0; i < eventTouchPoints.count() && indexToRemove < 0; ++i) {
158− if (eventTouchPoints[i].id() == touchId) {
163− if (indexToRemove >= 0) {
164− QList<QTouchEvent::TouchPoint> newTouchPointsList = eventTouchPoints;
165− newTouchPointsList.removeAt(indexToRemove);
166− event->setTouchPoints(newTouchPointsList);
173void TouchGate::dispatchFullyOwnedEvents()
147void TouchGate::dispatchFullyOwnedEvents()
175 while (!m_storedEvents.isEmpty() && eventIsFullyOwned(m_storedEvents.first())) {
149 while (!m_storedEvents.isEmpty() && eventIsFullyOwned(m_storedEvents.first())) {
176− QTouchEvent *event = m_storedEvents.takeFirst();
150+ TouchEvent event = m_storedEvents.takeFirst();
177 dispatchTouchEventToTarget(event);
151 dispatchTouchEventToTarget(event);
@@ -200,11 +173,10 @@ QString TouchGate::oldestPendingTouchIdsString()
203−bool TouchGate::eventIsFullyOwned(const QTouchEvent *event) const
176+bool TouchGate::eventIsFullyOwned(const TouchGate::TouchEvent &event) const
205− auto touchPoints = event->touchPoints();
206− for (int i = 0; i < touchPoints.count(); ++i) {
178+ for (int i = 0; i < event.touchPoints.count(); ++i) {
207− if (!isTouchPointOwned(touchPoints[i].id())) {
179+ if (!isTouchPointOwned(event.touchPoints[i].id())) {
208 return false;
180 return false;
@@ -224,9 +196,37 @@ void TouchGate::setTargetItem(QQuickItem *item)
224 Q_EMIT targetItemChanged(item);
196 Q_EMIT targetItemChanged(item);
199+void TouchGate::dispatchTouchEventToTarget(const TouchEvent &event)
201+ dispatchTouchEventToTarget(event.eventType,
227void TouchGate::dispatchTouchEventToTarget(QTouchEvent* event)
210void TouchGate::dispatchTouchEventToTarget(QTouchEvent* event)
212+ dispatchTouchEventToTarget(event->type(),
215+ event->touchPoints(),
218+ event->timestamp());
221+void TouchGate::dispatchTouchEventToTarget(QEvent::Type eventType,
222+ QTouchDevice *device,
223+ Qt::KeyboardModifiers modifiers,
224+ const QList<QTouchEvent::TouchPoint> &touchPoints,
229− removeTouchInfoForEndedTouches(event);
229+ removeTouchInfoForEndedTouches(touchPoints);
231 if (m_targetItem.isNull()) {
231 if (m_targetItem.isNull()) {
232 qWarning("[TouchGate] Cannot dispatch touch event because target item is null");
232 qWarning("[TouchGate] Cannot dispatch touch event because target item is null");
@@ -244,9 +244,10 @@ void TouchGate::dispatchTouchEventToTarget(QTouchEvent* event)
246 // Map touch points to targetItem coordinates
246 // Map touch points to targetItem coordinates
247− QList<QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
247+ QList<QTouchEvent::TouchPoint> targetTouchPoints = touchPoints;
248− transformTouchPoints(touchPoints, QQuickItemPrivate::get(targetItem)->windowToItemTransform());
248+ transformTouchPoints(targetTouchPoints, QQuickItemPrivate::get(targetItem)->windowToItemTransform());
249− QTouchEvent *eventForTargetItem = touchEventWithPoints(*event, touchPoints);
249+ QTouchEvent *eventForTargetItem = createQTouchEvent(eventType, device, modifiers, targetTouchPoints,
250+ target, window, timestamp);
251 #if TOUCHGATE_DEBUG
252 #if TOUCHGATE_DEBUG
252 qDebug() << "[TouchGate] dispatching" << qPrintable(touchEventToString(eventForTargetItem))
253 qDebug() << "[TouchGate] dispatching" << qPrintable(touchEventToString(eventForTargetItem))
@@ -271,15 +272,18 @@ void TouchGate::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints
274−// NB: From QQuickWindow
275+QTouchEvent *TouchGate::createQTouchEvent(QEvent::Type eventType,
275−QTouchEvent *TouchGate::touchEventWithPoints(const QTouchEvent &event,
276+ QTouchDevice *device,
277+ Qt::KeyboardModifiers modifiers,
276− const QList<QTouchEvent::TouchPoint> &newPoints)
278+ const QList<QTouchEvent::TouchPoint> &touchPoints,
278 Qt::TouchPointStates eventStates = 0;
283 Qt::TouchPointStates eventStates = 0;
279− for (int i=0; i<newPoints.count(); i++)
284+ for (int i = 0; i < touchPoints.count(); i++)
280− eventStates |= newPoints[i].state();
285+ eventStates |= touchPoints[i].state();
281 // if all points have the same state, set the event type accordingly
286 // if all points have the same state, set the event type accordingly
282− QEvent::Type eventType = event.type();
283 switch (eventStates) {
287 switch (eventStates) {
284 case Qt::TouchPointPressed:
288 case Qt::TouchPointPressed:
285 eventType = QEvent::TouchBegin;
289 eventType = QEvent::TouchBegin;
@@ -293,21 +297,19 @@ QTouchEvent *TouchGate::touchEventWithPoints(const QTouchEvent &event,
295 QTouchEvent *touchEvent = new QTouchEvent(eventType);
299 QTouchEvent *touchEvent = new QTouchEvent(eventType);
296− touchEvent->setWindow(event.window());
300+ touchEvent->setWindow(window);
297− touchEvent->setTarget(event.target());
301+ touchEvent->setTarget(target);
298− touchEvent->setDevice(event.device());
302+ touchEvent->setDevice(device);
299− touchEvent->setModifiers(event.modifiers());
303+ touchEvent->setModifiers(modifiers);
300− touchEvent->setTouchPoints(newPoints);
304+ touchEvent->setTouchPoints(touchPoints);
301 touchEvent->setTouchPointStates(eventStates);
305 touchEvent->setTouchPointStates(eventStates);
302− touchEvent->setTimestamp(event.timestamp());
306+ touchEvent->setTimestamp(timestamp);
303 touchEvent->accept();
307 touchEvent->accept();
304 return touchEvent;
308 return touchEvent;
307−void TouchGate::removeTouchInfoForEndedTouches(QTouchEvent *event)
311+void TouchGate::removeTouchInfoForEndedTouches(const QList<QTouchEvent::TouchPoint> &touchPoints)
309− const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
311 for (int i = 0; i < touchPoints.size(); ++i) {\
313 for (int i = 0; i < touchPoints.size(); ++i) {\
312 const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
314 const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
@@ -319,3 +321,27 @@ void TouchGate::removeTouchInfoForEndedTouches(QTouchEvent *event)
325+TouchGate::TouchEvent::TouchEvent(const QTouchEvent *event)
326+ : eventType(event->type())
327+ , device(event->device())
328+ , modifiers(event->modifiers())
329+ , touchPoints(event->touchPoints())
330+ , target(event->target())
331+ , window(event->window())
332+ , timestamp(event->timestamp())
336+bool TouchGate::TouchEvent::removeTouch(int touchId)
338+ bool removed = false;
339+ for (int i = 0; i < touchPoints.count() && !removed; ++i) {
340+ if (touchPoints[i].id() == touchId) {
341+ touchPoints.removeAt(i);