From 8598ffab46a500b9077d437ffc72d0e6fc843712 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 27 May 2009 12:55:06 +0200 Subject: Remove friends from QTouchEvent and QTouchEvent::TouchPoint We'll use the \internal functions to modify it instead. This should make it easier for people to implement support for touch events outside of Qt itself (still need to somehow expose the logic for dispatching the touch points to the correct widgets though). --- src/gui/kernel/qapplication.cpp | 20 ++++++++--------- src/gui/kernel/qapplication_win.cpp | 43 ++++++++++++++++++------------------- src/gui/kernel/qevent.cpp | 7 ++++++ src/gui/kernel/qevent.h | 10 ++++----- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 307d0ad..f1c5f34 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4052,13 +4052,13 @@ bool QApplication::notify(QObject *receiver, QEvent *e) touchEvent->spont = false; if (res && eventAccepted) { // the first widget to accept the TouchBegin gets an implicit grab. - for (int i = 0; i < touchEvent->_touchPoints.count(); ++i) { - QTouchEvent::TouchPoint *touchPoint = touchEvent->_touchPoints.at(i); - d->widgetForTouchPointId[touchPoint->d->id] = widget; + for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { + QTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().at(i); + d->widgetForTouchPointId[touchPoint->id()] = widget; } if (origin != widget) d->widgetCurrentTouchPoints.remove(origin); - d->widgetCurrentTouchPoints[widget] = touchEvent->_touchPoints; + d->widgetCurrentTouchPoints[widget] = touchEvent->touchPoints(); break; } else if (widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) { break; @@ -5250,14 +5250,14 @@ int QApplication::eventDeliveryDelayForGestures() void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent) { - for (int i = 0; i < touchEvent->_touchPoints.count(); ++i) { - QTouchEvent::TouchPoint *touchPoint = touchEvent->_touchPoints.at(i); + for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { + QTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().at(i); // preserve the sub-pixel resolution - const QPointF delta = touchPoint->d->screenPos - touchPoint->d->screenPos.toPoint(); - touchPoint->d->pos = widget->mapFromGlobal(touchPoint->d->screenPos.toPoint()) + delta; - touchPoint->d->startPos = widget->mapFromGlobal(touchPoint->d->startScreenPos.toPoint()) + delta; - touchPoint->d->lastPos = widget->mapFromGlobal(touchPoint->d->lastScreenPos.toPoint()) + delta; + const QPointF delta = touchPoint->screenPos() - touchPoint->screenPos().toPoint(); + touchPoint->setPos(widget->mapFromGlobal(touchPoint->screenPos().toPoint()) + delta); + touchPoint->setStartPos(widget->mapFromGlobal(touchPoint->startScreenPos().toPoint()) + delta); + touchPoint->setLastPos(widget->mapFromGlobal(touchPoint->lastScreenPos().toPoint()) + delta); } } diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index f134e55..148988f 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -4002,7 +4002,7 @@ QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QList< qreal closestDistance; for (int i = 0; i < appActiveTouchPoints.count(); ++i) { QTouchEvent::TouchPoint *touchPoint = appActiveTouchPoints.at(i); - qreal distance = QLineF(screenPos, touchPoint->d->screenPos).length(); + qreal distance = QLineF(screenPos, touchPoint->screenPos()).length(); if (!closestTouchPoint || distance < closestDistance) { closestTouchPoint = touchPoint; closestDistance = distance; @@ -4094,7 +4094,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) // update state QWidget *widget = 0; - bool down = touchPoint->d->state != Qt::TouchPointReleased; + bool down = touchPoint->state() != Qt::TouchPointReleased; QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); QEvent::Type eventType = QEvent::None; @@ -4107,13 +4107,13 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) QTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(appActiveTouchPoints, screenPos); if (closestTouchPoint) { - QWidget *closestWidget = widgetForTouchPointId.value(closestTouchPoint->d->id); + QWidget *closestWidget = widgetForTouchPointId.value(closestTouchPoint->id()); if (closestWidget && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) widget = closestWidget; } - widgetForTouchPointId[touchPoint->d->id] = widget; + widgetForTouchPointId[touchPoint->id()] = widget; QList ¤tTouchPoints = widgetCurrentTouchPoints[widget]; eventType = appendTouchPoint(touchPoint, ¤tTouchPoints); @@ -4121,38 +4121,37 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) appActiveTouchPoints = appCurrentTouchPoints; activeTouchPoints = currentTouchPoints; - touchPoint->d->state = Qt::TouchPointPressed; - touchPoint->d->screenPos - = touchPoint->d->startScreenPos - = touchPoint->d->lastScreenPos - = screenPos; - touchPoint->d->pressure = qreal(1.); + touchPoint->setState(Qt::TouchPointPressed); + touchPoint->setScreenPos(screenPos); + touchPoint->setStartScreenPos(screenPos); + touchPoint->setLastScreenPos(screenPos); + touchPoint->setPressure(qreal(1.)); } else if (down && (touchInput.dwFlags & TOUCHEVENTF_UP)) { - widget = widgetForTouchPointId.take(touchPoint->d->id); + widget = widgetForTouchPointId.take(touchPoint->id()); QList ¤tTouchPoints = widgetCurrentTouchPoints[widget]; appActiveTouchPoints = appCurrentTouchPoints; activeTouchPoints = currentTouchPoints; eventType = removeTouchPoint(touchPoint, ¤tTouchPoints); - touchPoint->d->state = Qt::TouchPointReleased; - touchPoint->d->lastScreenPos = touchPoint->d->screenPos; - touchPoint->d->screenPos = screenPos; - touchPoint->d->pressure = qreal(0.); + touchPoint->setState(Qt::TouchPointReleased); + touchPoint->setLastScreenPos(touchPoint->screenPos()); + touchPoint->setScreenPos(screenPos); + touchPoint->setPressure(qreal(0.)); } else if (down) { - widget = widgetForTouchPointId.value(touchPoint->d->id); + widget = widgetForTouchPointId.value(touchPoint->id()); appActiveTouchPoints = appCurrentTouchPoints; activeTouchPoints = widgetCurrentTouchPoints.value(widget); eventType = QEvent::TouchUpdate; - touchPoint->d->state = screenPos == touchPoint->d->screenPos - ? Qt::TouchPointStationary - : Qt::TouchPointMoved; - touchPoint->d->lastScreenPos = touchPoint->d->screenPos; - touchPoint->d->screenPos = screenPos; + touchPoint->setState(screenPos == touchPoint->screenPos() + ? Qt::TouchPointStationary + : Qt::TouchPointMoved); + touchPoint->setLastScreenPos(touchPoint->screenPos()); + touchPoint->setScreenPos(screenPos); // pressure should still be 1. } Q_ASSERT(widget != 0 && eventType != QEvent::None); - if (touchPoint->d->state != Qt::TouchPointStationary) { + if (touchPoint->state() != Qt::TouchPointStationary) { widgetsNeedingEvents.insert(widget, QTouchEvent(eventType, q->keyboardModifiers(), activeTouchPoints)); } diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 53010e1..419107c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3742,6 +3742,13 @@ QTouchEvent::~QTouchEvent() Returns the list of touch points contained in the touch event. */ +/*! \fn void QTouchEvent::setTouchPoints(QList &touchPoints) + + \internal + + Sets the list of touch points for this event. +*/ + /*! \internal Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent. diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index ed4129c..75cfb9d 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -796,9 +796,6 @@ public: protected: QTouchEventTouchPointPrivate *d; - - friend class QApplication; - friend class QApplicationPrivate; }; QTouchEvent(QEvent::Type type, @@ -807,12 +804,13 @@ public: ~QTouchEvent(); inline const QList &touchPoints() const { return _touchPoints; } + inline void setTouchPoints(const QList &touchPoints) + { + _touchPoints = touchPoints; + } protected: QList _touchPoints; - - friend class QApplication; - friend class QApplicationPrivate; }; QT_END_NAMESPACE -- cgit v0.12