From d9c2a93e1dc1ea0248d72fdc7f1bb863f8847658 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 12 May 2009 14:51:44 +0200 Subject: Don't store the current list of touch points for a widget in QWidgetPrivate This is information that's maintained by QApplication, so it belongs there instead. --- src/gui/kernel/qapplication.cpp | 4 ++-- src/gui/kernel/qapplication_p.h | 7 ++++-- src/gui/kernel/qapplication_win.cpp | 45 +++++++++++++++++++++---------------- src/gui/kernel/qwidget_p.h | 2 -- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index e9a113e..2fb6e91 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4048,8 +4048,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e) touchPoint->d->widget = widget; } if (origin != widget) - origin->d_func()->currentTouchPoints.clear(); - widget->d_func()->currentTouchPoints = touchEvent->_touchPoints; + d->widgetCurrentTouchPoints.remove(origin); + d->widgetCurrentTouchPoints[widget] = touchEvent->_touchPoints; break; } else if (widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) { break; diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index a375933..e44e7aa 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -433,6 +433,7 @@ public: // map number of widget subscribed to it> QMap grabbedGestures; + QMap > widgetCurrentTouchPoints; static void updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent); #if defined(Q_WS_WIN) @@ -447,8 +448,10 @@ public: void initializeMultitouch(); static QTouchEvent::TouchPoint *findClosestTouchPoint(const QList &activeTouchPoints, const QPointF &pos); - QEvent::Type appendTouchPoint(QTouchEvent::TouchPoint *touchPoint); - QEvent::Type removeTouchPoint(QTouchEvent::TouchPoint *touchPoint); + QEvent::Type appendTouchPoint(QTouchEvent::TouchPoint *touchPoint, + QList *currentTouchPoints); + QEvent::Type removeTouchPoint(QTouchEvent::TouchPoint *touchPoint, + QList *currentTouchPoints); bool translateTouchEvent(const MSG &msg); #endif diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 723a3b4..ef49ac6 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -4008,8 +4008,10 @@ void QApplicationPrivate::initializeMultitouch() GetTouchInputInfo = static_cast(library.resolve("GetTouchInputInfo")); CloseTouchInputHandle = static_cast(library.resolve("CloseTouchInputHandle")); + widgetCurrentTouchPoints.clear(); touchInputIDToTouchPointID.clear(); appAllTouchPoints.clear(); + appCurrentTouchPoints.clear(); } QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QList &appActiveTouchPoints, @@ -4028,10 +4030,10 @@ QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QList< return closestTouchPoint; } -QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touchPoint) +QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touchPoint, + QList *currentTouchPoints) { - QWidget *widget = touchPoint->d->widget; - QEvent::Type eventType = widget->d_func()->currentTouchPoints.isEmpty() + QEvent::Type eventType = currentTouchPoints->isEmpty() ? QEvent::TouchBegin : QEvent::TouchUpdate; @@ -4043,11 +4045,11 @@ QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touc } appCurrentTouchPoints.insert(at, touchPoint); // again, for the widget's currentTouchPoints - for (at = 0; at < widget->d_func()->currentTouchPoints.count(); ++at) { - if (widget->d_func()->currentTouchPoints.at(at)->id() > touchPoint->id()) + for (at = 0; at < currentTouchPoints->count(); ++at) { + if (currentTouchPoints->at(at)->id() > touchPoint->id()) break; } - widget->d_func()->currentTouchPoints.insert(at, touchPoint); + currentTouchPoints->insert(at, touchPoint); if (appCurrentTouchPoints.count() > appAllTouchPoints.count()) { qFatal("Qt: INTERNAL ERROR: appCurrentTouchPoints.count() (%d) > appAllTouchPoints.count() (%d)", @@ -4058,10 +4060,9 @@ QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touc return eventType; } -QEvent::Type QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touchPoint) +QEvent::Type QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touchPoint, + QList *currentTouchPoints) { - QWidget *widget = touchPoint->d->widget; - // remove touch point from all known touch points for (int i = qMin(appCurrentTouchPoints.count() - 1, touchPoint->id()); i >= 0; --i) { if (appCurrentTouchPoints.at(i) == touchPoint) { @@ -4070,14 +4071,14 @@ QEvent::Type QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touc } } // again, for the widget's currentTouchPoints - for (int i = qMin(widget->d_func()->currentTouchPoints.count() - 1, touchPoint->id()); i >= 0; --i) { - if (widget->d_func()->currentTouchPoints.at(i) == touchPoint) { - widget->d_func()->currentTouchPoints.removeAt(i); + for (int i = qMin(currentTouchPoints->count() - 1, touchPoint->id()); i >= 0; --i) { + if (currentTouchPoints->at(i) == touchPoint) { + currentTouchPoints->removeAt(i); break; } } - return widget->d_func()->currentTouchPoints.isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate; + return currentTouchPoints->isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate; } bool QApplicationPrivate::translateTouchEvent(const MSG &msg) @@ -4114,6 +4115,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) bool down = touchPoint->d->state != Qt::TouchPointReleased; QPointF globalPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); QEvent::Type eventType = QEvent::None; + QList activeTouchPoints; if (!down && (touchInput.dwFlags & TOUCHEVENTF_DOWN)) { // determine which widget this event will go to @@ -4129,10 +4131,11 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) } touchPoint->d->widget = w; - eventType = appendTouchPoint(touchPoint); + QList ¤tTouchPoints = widgetCurrentTouchPoints[w]; + eventType = appendTouchPoint(touchPoint, ¤tTouchPoints); // make sure new points are added to activeTouchPoints as well appActiveTouchPoints = appCurrentTouchPoints; - activeTouchPoints = w->d_func()->currentTouchPoints; + activeTouchPoints = currentTouchPoints; touchPoint->d->state = Qt::TouchPointPressed; touchPoint->d->globalPos @@ -4142,9 +4145,10 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) touchPoint->d->pressure = qreal(1.); } else if (down && (touchInput.dwFlags & TOUCHEVENTF_UP)) { QWidget *w = touchPoint->d->widget; + QList ¤tTouchPoints = widgetCurrentTouchPoints[w]; appActiveTouchPoints = appCurrentTouchPoints; - activeTouchPoints = w->d_func()->currentTouchPoints; - eventType = removeTouchPoint(touchPoint); + activeTouchPoints = currentTouchPoints; + eventType = removeTouchPoint(touchPoint, ¤tTouchPoints); touchPoint->d->state = Qt::TouchPointReleased; touchPoint->d->lastGlobalPos = touchPoint->d->globalPos; @@ -4153,7 +4157,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) } else if (down) { QWidget *w = touchPoint->d->widget; appActiveTouchPoints = appCurrentTouchPoints; - activeTouchPoints = w->d_func()->currentTouchPoints; + activeTouchPoints = widgetCurrentTouchPoints.value(w); eventType = QEvent::TouchUpdate; touchPoint->d->state = globalPos == touchPoint->d->globalPos ? Qt::TouchPointStationary @@ -4199,10 +4203,13 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) break; } case QEvent::TouchEnd: - if (!widget->d_func()->currentTouchPoints.isEmpty()) { + { + QList currentTouchPoints = widgetCurrentTouchPoints.take(widget); + if (!currentTouchPoints.isEmpty()) { qFatal("Qt: INTERNAL ERROR, the widget's currentTouchPoints should be empty!"); } // fall-through intended + } default: if (widget->testAttribute(Qt::WA_AcceptedTouchBeginEvent)) { (void) QApplication::sendSpontaneousEvent(widget, &touchEvent); diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 1ab31e4..d1f3acb 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -670,8 +670,6 @@ public: } QSize adjustedSize() const; - - QList currentTouchPoints; }; inline QWExtra *QWidgetPrivate::extraData() const -- cgit v0.12