diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 1 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 276 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene_p.h | 17 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicssceneevent.cpp | 178 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicssceneevent.h | 45 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsview.cpp | 130 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsview_p.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 10 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 5 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 62 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 90 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 35 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 4 |
13 files changed, 356 insertions, 500 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index f6daa49..1d3a316 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -331,6 +331,7 @@ public: quint32 inSetPosHelper : 1; quint32 allChildrenCombineOpacity : 1; quint32 acceptTouchEvents : 1; + quint32 acceptedTouchBeginEvent : 1; // Optional stacking order int globalStackingOrder; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 7bac21c..8140fea 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3798,9 +3798,6 @@ bool QGraphicsScene::event(QEvent *event) case QEvent::GraphicsSceneHoverEnter: case QEvent::GraphicsSceneHoverLeave: case QEvent::GraphicsSceneHoverMove: - case QEvent::GraphicsSceneTouchBegin: - case QEvent::GraphicsSceneTouchUpdate: - case QEvent::GraphicsSceneTouchEnd: // Reset the under-mouse list to ensure that this event gets fresh // item-under-mouse data. Be careful about this list; if people delete // items from inside event handlers, this list can quickly end up @@ -3990,13 +3987,9 @@ bool QGraphicsScene::event(QEvent *event) } break; case QEvent::GraphicsSceneTouchBegin: - d->touchBeginEvent(static_cast<QGraphicsSceneTouchEvent *>(event)); - break; case QEvent::GraphicsSceneTouchUpdate: - d->touchUpdateEvent(static_cast<QGraphicsSceneTouchEvent *>(event)); - break; case QEvent::GraphicsSceneTouchEnd: - d->touchEndEvent(static_cast<QGraphicsSceneTouchEvent *>(event)); + d->touchEventHandler(static_cast<QGraphicsSceneTouchEvent *>(event)); break; case QEvent::Timer: if (d->indexTimerId && static_cast<QTimerEvent *>(event)->timerId() == d->indexTimerId) { @@ -5654,18 +5647,9 @@ void QGraphicsScenePrivate::releaseGesture(QGraphicsItem *item, int gestureId) //### } -// ### FIXME: the code for touch event support is mosly copied from -// ### QGraphicsScenePrivate::mousePressEventHandler() and friends, need to -// ### refactor to reduce code duplication - -void QGraphicsScenePrivate::sendTouchEvent(QGraphicsSceneTouchEvent *touchEvent) +void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, + QGraphicsSceneTouchEvent *touchEvent) { - if (touchEvent->type() == QEvent::GraphicsSceneTouchEnd && lastMouseGrabberItemHasImplicitMouseGrab) { - clearMouseGrabber(); - return; - } - - QGraphicsItem *item = mouseGrabberItems.last(); QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints = touchEvent->touchPoints(); for (int i = 0; i < touchPoints.count(); ++i) { QGraphicsSceneTouchEvent::TouchPoint *touchPoint = touchPoints.at(i); @@ -5673,139 +5657,181 @@ void QGraphicsScenePrivate::sendTouchEvent(QGraphicsSceneTouchEvent *touchEvent) touchPoint->setStartPos(item->d_ptr->genericMapFromScene(touchPoint->startScenePos(), touchEvent->widget())); touchPoint->setLastPos(item->d_ptr->genericMapFromScene(touchPoint->lastScenePos(), touchEvent->widget())); } - sendEvent(item, touchEvent); } -void QGraphicsScenePrivate::touchBeginEvent(QGraphicsSceneTouchEvent *touchEvent) +QGraphicsSceneTouchEvent::TouchPoint *QGraphicsScenePrivate::findClosestTouchPoint(const QList<QGraphicsSceneTouchEvent::TouchPoint *> &sceneActiveTouchPoints, + const QPointF &scenePos) { - Q_Q(QGraphicsScene); + QGraphicsSceneTouchEvent::TouchPoint *closestTouchPoint = 0; + qreal closestDistance; + for (int i = 0; i < sceneActiveTouchPoints.count(); ++i) { + QGraphicsSceneTouchEvent::TouchPoint *touchPoint = sceneActiveTouchPoints.at(i); + qreal distance = QLineF(scenePos, touchPoint->scenePos()).length(); + if (!closestTouchPoint || distance < closestDistance) { + closestTouchPoint = touchPoint; + closestDistance = distance; + } + } + return closestTouchPoint; +} - // Ignore by default, unless we find a mouse grabber that accepts it. - touchEvent->ignore(); +QEvent::Type QGraphicsScenePrivate::appendTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint, + QList<QGraphicsSceneTouchEvent::TouchPoint *> *currentTouchPoints) +{ + QEvent::Type eventType = currentTouchPoints->isEmpty() + ? QEvent::GraphicsSceneTouchBegin + : QEvent::GraphicsSceneTouchUpdate; - // Deliver to any existing mouse grabber. - if (!mouseGrabberItems.isEmpty()) { - // The event is ignored by default, but we disregard the event's - // accepted state after delivery; the mouse is grabbed, after all. - sendTouchEvent(touchEvent); - return; + // insort touch point (for the app) + int at = 0; + for (; at < sceneCurrentTouchPoints.count(); ++at) { + if (sceneCurrentTouchPoints.at(at)->id() > touchPoint->id()) + break; } - - // Start by determining the number of items at the current position. - // Reuse value from earlier calculations if possible. - if (cachedItemsUnderMouse.isEmpty()) { - QGraphicsSceneTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().first(); - // ### FIXME: should the itemsAtPosition() function support sub-pixel screenPos? - cachedItemsUnderMouse = itemsAtPosition(touchPoint->screenPos().toPoint(), - touchPoint->scenePos(), - touchEvent->widget()); + sceneCurrentTouchPoints.insert(at, touchPoint); + // again, for the items's currentTouchPoints + for (at = 0; at < currentTouchPoints->count(); ++at) { + if (currentTouchPoints->at(at)->id() > touchPoint->id()) + break; } + currentTouchPoints->insert(at, touchPoint); - // Update window activation. - QGraphicsWidget *newActiveWindow = windowForItem(cachedItemsUnderMouse.value(0)); - if (newActiveWindow != activeWindow) - q->setActiveWindow(newActiveWindow); + return eventType; +} - // Set focus on the topmost enabled item that can take focus. - bool setFocus = false; - foreach (QGraphicsItem *item, cachedItemsUnderMouse) { - if (item->isEnabled() && (item->flags() & QGraphicsItem::ItemIsFocusable)) { - if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) { - setFocus = true; - if (item != q->focusItem()) - q->setFocusItem(item, Qt::MouseFocusReason); - break; - } +QEvent::Type QGraphicsScenePrivate::removeTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint, + QList<QGraphicsSceneTouchEvent::TouchPoint *> *currentTouchPoints) +{ + // remove touch point from all known touch points + for (int i = qMin(sceneCurrentTouchPoints.count() - 1, touchPoint->id()); i >= 0; --i) { + if (sceneCurrentTouchPoints.at(i) == touchPoint) { + sceneCurrentTouchPoints.removeAt(i); + break; } } - - // If nobody could take focus, clear it. - if (!stickyFocus && !setFocus) - q->setFocusItem(0, Qt::MouseFocusReason); - - // Find a mouse grabber by sending touch events to all mouse grabber - // candidates one at a time, until the event is accepted. It's accepted by - // default, so the receiver has to explicitly ignore it for it to pass - // through. - foreach (QGraphicsItem *item, cachedItemsUnderMouse) { - if (!item->acceptTouchEvents()) { - // Skip items that don't accept the touch events - continue; + // again, for the items's currentTouchPoints + for (int i = qMin(currentTouchPoints->count() - 1, touchPoint->id()); i >= 0; --i) { + if (currentTouchPoints->at(i) == touchPoint) { + currentTouchPoints->removeAt(i); + break; } + } - grabMouse(item, /* implicit = */ true); - touchEvent->accept(); + return currentTouchPoints->isEmpty() ? QEvent::GraphicsSceneTouchEnd : QEvent::GraphicsSceneTouchUpdate; +} - // check if the item we are sending to are disabled (before we send the event) - bool disabled = !item->isEnabled(); - bool isWindow = item->isWindow(); - sendTouchEvent(touchEvent); +void QGraphicsScenePrivate::touchEventHandler(QGraphicsSceneTouchEvent *sceneTouchEvent) +{ + Q_Q(QGraphicsScene); - bool dontSendUngrabEvents = mouseGrabberItems.isEmpty() || mouseGrabberItems.last() != item; - if (disabled) { - ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); - break; - } - if (touchEvent->isAccepted()) { - lastMouseGrabberItem = item; - return; - } - ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents); + QList<QGraphicsSceneTouchEvent::TouchPoint *> sceneActiveTouchPoints = sceneCurrentTouchPoints; + + QHash<QGraphicsItem *, QGraphicsSceneTouchEvent *> itemsNeedingEvents; + for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) { + QGraphicsSceneTouchEvent::TouchPoint *touchPoint = sceneTouchEvent->touchPoints().at(i); + + // update state + QGraphicsItem *item = 0; + QEvent::Type eventType = QEvent::None; + QList<QGraphicsSceneTouchEvent::TouchPoint *> activeTouchPoints; + if (touchPoint->state() == Qt::TouchPointPressed) { + // determine which widget this event will go to + item = q->itemAt(touchPoint->scenePos()); + QGraphicsSceneTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(sceneActiveTouchPoints, touchPoint->scenePos()); + if (closestTouchPoint) { + QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPoint->id()); + if (!item + || (closestItem + && (item->isAncestorOf(closestItem) + || closestItem->isAncestorOf(item)))) { + item = closestItem; + } + } + if (!item) + continue; - // Don't propagate through windows. - if (isWindow) - break; - } + itemForTouchPointId.insert(touchPoint->id(), item); - // Is the event still ignored? Then the mouse press goes to the scene. - // Reset the mouse grabber, clear the selection, clear focus, and leave - // the event ignored so that it can propagate through the originating - // view. - if (!touchEvent->isAccepted()) { - clearMouseGrabber(); + QList<QGraphicsSceneTouchEvent::TouchPoint *> ¤tTouchPoints = itemCurrentTouchPoints[item]; + eventType = appendTouchPoint(touchPoint, ¤tTouchPoints); + // make sure new points are added to activeTouchPoints as well + sceneActiveTouchPoints = sceneCurrentTouchPoints; + activeTouchPoints = currentTouchPoints; + } else if (touchPoint->state() == Qt::TouchPointReleased) { + item = itemForTouchPointId.take(touchPoint->id()); + if (!item) + continue; - QGraphicsView *view = touchEvent->widget() ? qobject_cast<QGraphicsView *>(touchEvent->widget()->parentWidget()) : 0; - bool dontClearSelection = view && view->dragMode() == QGraphicsView::ScrollHandDrag; - if (!dontClearSelection) { - // Clear the selection if the originating view isn't in scroll - // hand drag mode. The view will clear the selection if no drag - // happened. - q->clearSelection(); + QList<QGraphicsSceneTouchEvent::TouchPoint *> ¤tTouchPoints = itemCurrentTouchPoints[item]; + sceneActiveTouchPoints = sceneCurrentTouchPoints; + activeTouchPoints = currentTouchPoints; + eventType = removeTouchPoint(touchPoint, ¤tTouchPoints); + } else { + item = itemForTouchPointId.value(touchPoint->id()); + if (!item) + continue; + + sceneActiveTouchPoints = sceneCurrentTouchPoints; + activeTouchPoints = itemCurrentTouchPoints.value(item); + eventType = QEvent::GraphicsSceneTouchUpdate; } - } -} + Q_ASSERT(eventType != QEvent::None); -void QGraphicsScenePrivate::touchUpdateEvent(QGraphicsSceneTouchEvent *touchEvent) -{ - if (mouseGrabberItems.isEmpty()) { - touchEvent->ignore(); - return; + if (touchPoint->state() != Qt::TouchPointStationary) { + QGraphicsSceneTouchEvent *&touchEvent = itemsNeedingEvents[item]; + if (!touchEvent) { + touchEvent = new QGraphicsSceneTouchEvent(eventType); + touchEvent->setModifiers(sceneTouchEvent->modifiers()); + } + Q_ASSERT(touchEvent->type() == eventType); + touchEvent->setTouchPoints(activeTouchPoints); + } } - // Forward the event to the mouse grabber - sendTouchEvent(touchEvent); - touchEvent->accept(); -} - -void QGraphicsScenePrivate::touchEndEvent(QGraphicsSceneTouchEvent *touchEvent) -{ - if (mouseGrabberItems.isEmpty()) { - touchEvent->ignore(); + if (itemsNeedingEvents.isEmpty()) { + sceneTouchEvent->ignore(); return; } - // Forward the event to the mouse grabber - sendTouchEvent(touchEvent); - touchEvent->accept(); + bool acceptSceneTouchEvent = false; + QHash<QGraphicsItem *, QGraphicsSceneTouchEvent *>::ConstIterator it = itemsNeedingEvents.constBegin(); + const QHash<QGraphicsItem *, QGraphicsSceneTouchEvent *>::ConstIterator end = itemsNeedingEvents.constEnd(); + for (; it != end; ++it) { + QGraphicsItem *item = it.key(); + + QGraphicsSceneTouchEvent *touchEvent = it.value(); + updateTouchPointsForItem(item, touchEvent); + + switch (touchEvent->type()) { + case QEvent::GraphicsSceneTouchBegin: + { + // if the TouchBegin handler recurses, we assume that means the event + // has been implicitly accepted and continue to send touch events + item->d_ptr->acceptedTouchBeginEvent = true; + bool res = sendEvent(item, touchEvent) + && touchEvent->isAccepted(); + acceptSceneTouchEvent = acceptSceneTouchEvent || res; + break; + } + case QEvent::GraphicsSceneTouchEnd: + { + QList<QGraphicsSceneTouchEvent::TouchPoint *> currentTouchPoints = itemCurrentTouchPoints.take(item); + if (!currentTouchPoints.isEmpty()) { + qFatal("Qt: INTERNAL ERROR, the widget's currentTouchPoints should be empty!"); + } + // fall-through intended + } + default: + if (item->d_ptr->acceptedTouchBeginEvent) { + (void) sendEvent(item, touchEvent); + acceptSceneTouchEvent = true; + } + break; + } - // Reset the mouse grabber - if (!mouseGrabberItems.isEmpty()) { - lastMouseGrabberItem = mouseGrabberItems.last(); - if (lastMouseGrabberItemHasImplicitMouseGrab) - mouseGrabberItems.last()->ungrabMouse(); - } else { - lastMouseGrabberItem = 0; + delete touchEvent; } + sceneTouchEvent->setAccepted(acceptSceneTouchEvent); } QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 074e95c..589ab75 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -57,6 +57,7 @@ #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW +#include "qgraphicssceneevent.h" #include "qgraphicsscene_bsp_p.h" #include "qgraphicsitem_p.h" @@ -73,7 +74,6 @@ QT_BEGIN_NAMESPACE class QGraphicsView; class QGraphicsWidget; -class QGraphicsSceneTouchEvent; class QGraphicsScenePrivate : public QObjectPrivate { @@ -276,10 +276,17 @@ public: mutable QBitArray validTransforms; mutable QVector<int> freeSceneTransformSlots; - void sendTouchEvent(QGraphicsSceneTouchEvent *touchEvent); - void touchBeginEvent(QGraphicsSceneTouchEvent *touchEvent); - void touchUpdateEvent(QGraphicsSceneTouchEvent *touchEvent); - void touchEndEvent(QGraphicsSceneTouchEvent *touchEvent); + QList<QGraphicsSceneTouchEvent::TouchPoint *> sceneCurrentTouchPoints; + QHash<QGraphicsItem *, QList<QGraphicsSceneTouchEvent::TouchPoint *> > itemCurrentTouchPoints; + QHash<int, QGraphicsItem *> itemForTouchPointId; + static void updateTouchPointsForItem(QGraphicsItem *item, QGraphicsSceneTouchEvent *touchEvent); + static QGraphicsSceneTouchEvent::TouchPoint *findClosestTouchPoint(const QList<QGraphicsSceneTouchEvent::TouchPoint *> &activeTouchPoints, + const QPointF &scenePos); + QEvent::Type appendTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint, + QList<QGraphicsSceneTouchEvent::TouchPoint *> *currentTouchPoints); + QEvent::Type removeTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint, + QList<QGraphicsSceneTouchEvent::TouchPoint *> *currentTouchPoints); + void touchEventHandler(QGraphicsSceneTouchEvent *touchEvent); }; QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp index b599632..d5d0fb9 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.cpp +++ b/src/gui/graphicsview/qgraphicssceneevent.cpp @@ -301,6 +301,7 @@ #include <QtCore/qstring.h> #include "qgraphicsview.h" #include "qgraphicsitem.h" +#include <private/qevent_p.h> QT_BEGIN_NAMESPACE @@ -1966,10 +1967,7 @@ QGraphicsSceneTouchEvent::QGraphicsSceneTouchEvent(Type type) Destroys the QGraphicsSceneTouchEvent. */ QGraphicsSceneTouchEvent::~QGraphicsSceneTouchEvent() -{ - Q_D(QGraphicsSceneTouchEvent); - qDeleteAll(d->touchPoints); -} +{ } /*! Returns the list of touch points for this event. @@ -2006,116 +2004,6 @@ void QGraphicsSceneTouchEvent::setModifiers(Qt::KeyboardModifiers modifiers) d->modifiers = modifiers; } -class QGraphicsSceneTouchEventTouchPointPrivate -{ -public: - inline QGraphicsSceneTouchEventTouchPointPrivate() - : id(-1), state(Qt::TouchPointReleased), pressure(qreal(0.)) - { } - - int id; - Qt::TouchPointState state; - QPointF pos, startPos, lastPos; - QPointF scenePos, startScenePos, lastScenePos; - QPointF screenPos, startScreenPos, lastScreenPos; - qreal pressure; -}; - -/*! \internal - - Constructs a new touch point for use in a QGraphicsSceneTouchEvent. -*/ -QGraphicsSceneTouchEvent::TouchPoint::TouchPoint() - : d(new QGraphicsSceneTouchEventTouchPointPrivate) -{ -} - -/*! \internal - - Destroys the QGraphicsSceneTouchEvent::TouchPoint. -*/ -QGraphicsSceneTouchEvent::TouchPoint::~TouchPoint() -{ - delete d; -} - -/*! - Returns the identifier for this touch point. -*/ -int QGraphicsSceneTouchEvent::TouchPoint::id() const -{ - return d->id; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setId(int id) -{ - d->id = id; -} - -/*! - Returns the state of this touch point at the time the - QGraphicsSceneTouchEvent occurred. -*/ -Qt::TouchPointState QGraphicsSceneTouchEvent::TouchPoint::state() const -{ - return d->state; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setState(Qt::TouchPointState state) -{ - d->state = state; -} - -/*! - Returns the current position of this touch point in item coordinates. - - \sa scenePos(), screenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::pos() const -{ - return d->pos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setPos(const QPointF &pos) -{ - d->pos = pos; -} - -/*! - Returns the starting position of this touch point in item coordinates. - - \sa startScenePos(), startScreenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::startPos() const -{ - return d->startPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) -{ - d->startPos = startPos; -} - -/*! - Returns the previous position of this touch point in item coordinates. - - \sa lastScenePos(), lastScreenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::lastPos() const -{ - return d->lastPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) -{ - d->lastPos = lastPos; -} - /*! Returns the current position of this touch point in scene coordinates. @@ -2164,68 +2052,6 @@ void QGraphicsSceneTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastSc d->lastScenePos = lastScenePos; } -/*! - Returns the current position of this touch point in screen coordinates. - - \sa pos(), scenePos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::screenPos() const -{ - return d->screenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) -{ - d->screenPos = screenPos; -} - -/*! - Returns the starting position of this touch point in screen coordinates. - - \sa startPos(), startScenePos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::startScreenPos() const -{ - return d->startScreenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) -{ - d->startScreenPos = startScreenPos; -} - -/*! - Returns the previous position of this touch point in screen coordinates. - - \sa lastPos(), lastScenePos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::lastScreenPos() const -{ - return d->lastScreenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) -{ - d->lastScreenPos = lastScreenPos; -} - -/*! - Returns the pressure of this touch point. -*/ -qreal QGraphicsSceneTouchEvent::TouchPoint::pressure() const -{ - return d->pressure; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setPressure(qreal pressure) -{ - d->pressure = pressure; -} - QT_END_NAMESPACE #endif // QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicssceneevent.h b/src/gui/graphicsview/qgraphicssceneevent.h index 4b7065e..01cdab9 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.h +++ b/src/gui/graphicsview/qgraphicssceneevent.h @@ -42,7 +42,7 @@ #ifndef QGRAPHICSSCENEEVENT_H #define QGRAPHICSSCENEEVENT_H -#include <QtCore/qcoreevent.h> +#include <QtGui/qevent.h> #include <QtCore/qpoint.h> #include <QtCore/qrect.h> #include <QtGui/qpolygon.h> @@ -349,34 +349,12 @@ protected: }; class QGraphicsSceneTouchEventPrivate; -class QGraphicsSceneTouchEventTouchPointPrivate; class Q_GUI_EXPORT QGraphicsSceneTouchEvent : public QGraphicsSceneEvent { public: - QGraphicsSceneTouchEvent(Type type = None); - ~QGraphicsSceneTouchEvent(); - - class Q_GUI_EXPORT TouchPoint + class Q_GUI_EXPORT TouchPoint : public QTouchEvent::TouchPoint { public: - TouchPoint(); - ~TouchPoint(); - - int id() const; - void setId(int id); - - Qt::TouchPointState state() const; - void setState(Qt::TouchPointState state); - - QPointF pos() const; - void setPos(const QPointF &pos); - - QPointF startPos() const; - void setStartPos(const QPointF &startPos); - - QPointF lastPos() const; - void setLastPos(const QPointF &lastPos); - QPointF scenePos() const; void setScenePos(const QPointF &scenePos); @@ -386,24 +364,15 @@ public: QPointF lastScenePos() const; void setLastScenePos(const QPointF &lastScenePos); - QPointF screenPos() const; - void setScreenPos(const QPointF &screenPos); - - QPointF startScreenPos() const; - void setStartScreenPos(const QPointF &startScreenPos); - - QPointF lastScreenPos() const; - void setLastScreenPos(const QPointF &lastScreenPos); - qreal pressure() const; // 0.0 -> 1.0 void setPressure(qreal pressure); - - private: - QGraphicsSceneTouchEventTouchPointPrivate *d; }; - const QList<TouchPoint *> &touchPoints() const; - void setTouchPoints(const QList<TouchPoint *> &touchPoints); + QGraphicsSceneTouchEvent(Type type = None); + ~QGraphicsSceneTouchEvent(); + + const QList<QGraphicsSceneTouchEvent::TouchPoint *> &touchPoints() const; + void setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint *> &touchPoints); Qt::KeyboardModifiers modifiers() const; void setModifiers(Qt::KeyboardModifiers modifiers); diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 6f142e3..1d801cd 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -306,6 +306,30 @@ inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for sing return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); } +static void qt_convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d, + QTouchEvent *originalEvent, + QGraphicsSceneTouchEvent *touchEvent) +{ + QList<QTouchEvent::TouchPoint *> originalTouchPoints = originalEvent->touchPoints(); + QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints; + for (int i = 0; i < originalTouchPoints.count(); ++i) { + QGraphicsSceneTouchEvent::TouchPoint *touchPoint = + static_cast<QGraphicsSceneTouchEvent::TouchPoint *>(originalTouchPoints.at(i)); + // the scene will set the pos before delivering to an item + touchPoint->setScenePos(d->mapToScene(touchPoint->pos())); + // the scene will set the startPos before delivering to an item + touchPoint->setStartScenePos(d->mapToScene(touchPoint->startPos())); + // the scene will set the lastPos before delivering to an item + touchPoint->setLastScenePos(d->mapToScene(touchPoint->lastScreenPos())); + // lastScreenPos is already set in the originalTouchPoint + + touchPoints.append(touchPoint); + } + + touchEvent->setTouchPoints(touchPoints); + touchEvent->setModifiers(originalEvent->modifiers()); +} + /*! \internal */ @@ -2962,20 +2986,24 @@ bool QGraphicsView::viewportEvent(QEvent *event) { if (!isEnabled()) return false; - QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); - switch (touchEvent->type()) { - case QEvent::TouchBegin: - d->touchBeginEvent(touchEvent); - break; - case QEvent::TouchUpdate: - d->touchUpdateEvent(touchEvent); - break; - case QEvent::TouchEnd: - d->touchEndEvent(touchEvent); - break; - default: - break; + + if (d->scene && d->sceneInteractionAllowed) { + // Convert and deliver the touch event to the scene. + QEvent::Type eventType = event->type() == QEvent::TouchBegin + ? QEvent::GraphicsSceneTouchBegin + : event->type() == QEvent::TouchEnd + ? QEvent::GraphicsSceneTouchEnd + : QEvent::GraphicsSceneTouchUpdate; + QGraphicsSceneTouchEvent touchEvent(eventType); + touchEvent.setWidget(viewport()); + qt_convertTouchEventToGraphicsSceneTouchEvent(d, + static_cast<QTouchEvent *>(event), + &touchEvent); + touchEvent.setAccepted(false); + QApplication::sendEvent(d->scene, &touchEvent); + event->setAccepted(touchEvent.isAccepted()); } + return true; } default: @@ -3916,34 +3944,6 @@ void QGraphicsView::resetTransform() setTransform(QTransform()); } -static void qt_convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *originalEvent, QGraphicsSceneTouchEvent *touchEvent) -{ - QList<QTouchEvent::TouchPoint *> originalTouchPoints = originalEvent->touchPoints(); - QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints; - for (int i = 0; i < originalTouchPoints.count(); ++i) { - QTouchEvent::TouchPoint *originalTouchPoint = originalTouchPoints.at(i); - - QGraphicsSceneTouchEvent::TouchPoint *touchPoint = new QGraphicsSceneTouchEvent::TouchPoint(); - touchPoint->setId(originalTouchPoint->id()); - touchPoint->setState(originalTouchPoint->state()); - // the scene will set the pos before delivering to an item - touchPoint->setScenePos(d->mapToScene(originalTouchPoint->pos())); - touchPoint->setScreenPos(originalTouchPoint->globalPos()); - // the scene will set the startPos before delivering to an item - touchPoint->setStartScenePos(d->mapToScene(originalTouchPoint->startPos())); - touchPoint->setStartScreenPos(originalTouchPoint->startGlobalPos()); - // the scene will set the lastPos before delivering to an item - touchPoint->setLastScenePos(d->mapToScene(originalTouchPoint->lastPos())); - touchPoint->setLastScreenPos(originalTouchPoint->lastGlobalPos()); - touchPoint->setPressure(originalTouchPoint->pressure()); - - touchPoints.append(touchPoint); - } - - touchEvent->setTouchPoints(touchPoints); - touchEvent->setModifiers(originalEvent->modifiers()); -} - QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const { QPointF p = point; @@ -3952,54 +3952,6 @@ QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const return identityMatrix ? p : matrix.inverted().map(p); } -void QGraphicsViewPrivate::touchBeginEvent(QTouchEvent *event) -{ - Q_Q(QGraphicsView); - - if (!scene || !sceneInteractionAllowed) - return; - - // Convert and deliver the touch event to the scene. - QGraphicsSceneTouchEvent touchEvent(QEvent::GraphicsSceneTouchBegin); - touchEvent.setWidget(q->viewport()); - qt_convertTouchEventToGraphicsSceneTouchEvent(this, event, &touchEvent); - touchEvent.setAccepted(false); - QApplication::sendEvent(scene, &touchEvent); - event->setAccepted(touchEvent.isAccepted()); -} - -void QGraphicsViewPrivate::touchUpdateEvent(QTouchEvent *event) -{ - Q_Q(QGraphicsView); - - if (!scene || !sceneInteractionAllowed) - return; - - // Convert and deliver the touch event to the scene. - QGraphicsSceneTouchEvent touchEvent(QEvent::GraphicsSceneTouchUpdate); - touchEvent.setWidget(q->viewport()); - qt_convertTouchEventToGraphicsSceneTouchEvent(this, event, &touchEvent); - touchEvent.setAccepted(false); - QApplication::sendEvent(scene, &touchEvent); - event->setAccepted(touchEvent.isAccepted()); -} - -void QGraphicsViewPrivate::touchEndEvent(QTouchEvent *event) -{ - Q_Q(QGraphicsView); - - if (!scene || !sceneInteractionAllowed) - return; - - // Convert and deliver the touch event to the scene. - QGraphicsSceneTouchEvent touchEvent(QEvent::GraphicsSceneTouchEnd); - touchEvent.setWidget(q->viewport()); - qt_convertTouchEventToGraphicsSceneTouchEvent(this, event, &touchEvent); - touchEvent.setAccepted(false); - QApplication::sendEvent(scene, &touchEvent); - event->setAccepted(touchEvent.isAccepted()); -} - QT_END_NAMESPACE #include "moc_qgraphicsview.cpp" diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index daaeca2..779b638 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -183,9 +183,6 @@ public: const QRegion &exposedRegion) const; QPointF mapToScene(const QPointF &point) const; - void touchBeginEvent(QTouchEvent *event); - void touchUpdateEvent(QTouchEvent *event); - void touchEndEvent(QTouchEvent *event); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 2fb6e91..e46ccf1 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4045,7 +4045,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // 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); - touchPoint->d->widget = widget; + d->widgetForTouchPointId[touchPoint->d->id] = widget; } if (origin != widget) d->widgetCurrentTouchPoints.remove(origin); @@ -5245,10 +5245,10 @@ void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEven QTouchEvent::TouchPoint *touchPoint = touchEvent->_touchPoints.at(i); // preserve the sub-pixel resolution - const QPointF delta = touchPoint->d->globalPos - touchPoint->d->globalPos.toPoint(); - touchPoint->d->pos = widget->mapFromGlobal(touchPoint->d->globalPos.toPoint()) + delta; - touchPoint->d->startPos = widget->mapFromGlobal(touchPoint->d->startGlobalPos.toPoint()) + delta; - touchPoint->d->lastPos = widget->mapFromGlobal(touchPoint->d->lastGlobalPos.toPoint()) + delta; + 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; } } diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index e44e7aa..096c349 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -433,6 +433,7 @@ public: // map<gesture name -> number of widget subscribed to it> QMap<QString, int> grabbedGestures; + QHash<int, QWidget *> widgetForTouchPointId; QMap<QWidget *, QList<QTouchEvent::TouchPoint *> > widgetCurrentTouchPoints; static void updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent); @@ -441,13 +442,13 @@ public: static qt_GetTouchInputInfoPtr GetTouchInputInfo; static qt_CloseTouchInputHandlePtr CloseTouchInputHandle; - QMap<DWORD, int> touchInputIDToTouchPointID; + QHash<DWORD, int> touchInputIDToTouchPointID; QVector<QTouchEvent::TouchPoint *> appAllTouchPoints; QList<QTouchEvent::TouchPoint *> appCurrentTouchPoints; void initializeMultitouch(); static QTouchEvent::TouchPoint *findClosestTouchPoint(const QList<QTouchEvent::TouchPoint *> &activeTouchPoints, - const QPointF &pos); + const QPointF &screenPos); QEvent::Type appendTouchPoint(QTouchEvent::TouchPoint *touchPoint, QList<QTouchEvent::TouchPoint *> *currentTouchPoints); QEvent::Type removeTouchPoint(QTouchEvent::TouchPoint *touchPoint, diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index ef49ac6..f537805 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -4008,6 +4008,7 @@ void QApplicationPrivate::initializeMultitouch() GetTouchInputInfo = static_cast<qt_GetTouchInputInfoPtr>(library.resolve("GetTouchInputInfo")); CloseTouchInputHandle = static_cast<qt_CloseTouchInputHandlePtr>(library.resolve("CloseTouchInputHandle")); + widgetForTouchPointId.clear(); widgetCurrentTouchPoints.clear(); touchInputIDToTouchPointID.clear(); appAllTouchPoints.clear(); @@ -4015,13 +4016,13 @@ void QApplicationPrivate::initializeMultitouch() } QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QList<QTouchEvent::TouchPoint *> &appActiveTouchPoints, - const QPointF &pos) + const QPointF &screenPos) { QTouchEvent::TouchPoint *closestTouchPoint = 0; qreal closestDistance; for (int i = 0; i < appActiveTouchPoints.count(); ++i) { QTouchEvent::TouchPoint *touchPoint = appActiveTouchPoints.at(i); - qreal distance = QLineF(pos, touchPoint->d->globalPos).length(); + qreal distance = QLineF(screenPos, touchPoint->d->screenPos).length(); if (!closestTouchPoint || distance < closestDistance) { closestTouchPoint = touchPoint; closestDistance = distance; @@ -4112,64 +4113,67 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) touchPoint = appAllTouchPoints[touchPointID] = new QTouchEvent::TouchPoint(touchPointID); // update state + QWidget *widget = 0; bool down = touchPoint->d->state != Qt::TouchPointReleased; - QPointF globalPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); + QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); QEvent::Type eventType = QEvent::None; QList<QTouchEvent::TouchPoint *> activeTouchPoints; if (!down && (touchInput.dwFlags & TOUCHEVENTF_DOWN)) { // determine which widget this event will go to - QWidget *w = widgetForHwnd->childAt(widgetForHwnd->mapFromGlobal(globalPos.toPoint())); - if (!w) - w = widgetForHwnd; - - QTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(appActiveTouchPoints, globalPos); - if (closestTouchPoint - && (w->isAncestorOf(closestTouchPoint->d->widget) - || closestTouchPoint->d->widget->isAncestorOf(w))) { - w = closestTouchPoint->d->widget; + widget = widgetForHwnd->childAt(widgetForHwnd->mapFromGlobal(screenPos.toPoint())); + if (!widget) + widget = widgetForHwnd; + + QTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(appActiveTouchPoints, screenPos); + if (closestTouchPoint) { + QWidget *closestWidget = widgetForTouchPointId.value(closestTouchPoint->d->id); + if (closestWidget + && (widget->isAncestorOf(closestWidget) + || closestWidget->isAncestorOf(widget))) + widget = closestWidget; } - touchPoint->d->widget = w; + widgetForTouchPointId[touchPoint->d->id] = widget; - QList<QTouchEvent::TouchPoint *> ¤tTouchPoints = widgetCurrentTouchPoints[w]; + QList<QTouchEvent::TouchPoint *> ¤tTouchPoints = widgetCurrentTouchPoints[widget]; eventType = appendTouchPoint(touchPoint, ¤tTouchPoints); // make sure new points are added to activeTouchPoints as well appActiveTouchPoints = appCurrentTouchPoints; activeTouchPoints = currentTouchPoints; touchPoint->d->state = Qt::TouchPointPressed; - touchPoint->d->globalPos - = touchPoint->d->startGlobalPos - = touchPoint->d->lastGlobalPos - = globalPos; + touchPoint->d->screenPos + = touchPoint->d->startScreenPos + = touchPoint->d->lastScreenPos + = screenPos; touchPoint->d->pressure = qreal(1.); } else if (down && (touchInput.dwFlags & TOUCHEVENTF_UP)) { - QWidget *w = touchPoint->d->widget; - QList<QTouchEvent::TouchPoint *> ¤tTouchPoints = widgetCurrentTouchPoints[w]; + widget = widgetForTouchPointId.take(touchPoint->d->id); + QList<QTouchEvent::TouchPoint *> ¤tTouchPoints = widgetCurrentTouchPoints[widget]; appActiveTouchPoints = appCurrentTouchPoints; activeTouchPoints = currentTouchPoints; eventType = removeTouchPoint(touchPoint, ¤tTouchPoints); touchPoint->d->state = Qt::TouchPointReleased; - touchPoint->d->lastGlobalPos = touchPoint->d->globalPos; - touchPoint->d->globalPos = globalPos; + touchPoint->d->lastScreenPos = touchPoint->d->screenPos; + touchPoint->d->screenPos = screenPos; touchPoint->d->pressure = qreal(0.); } else if (down) { - QWidget *w = touchPoint->d->widget; + widget = widgetForTouchPointId.value(touchPoint->d->id); appActiveTouchPoints = appCurrentTouchPoints; - activeTouchPoints = widgetCurrentTouchPoints.value(w); + activeTouchPoints = widgetCurrentTouchPoints.value(widget); eventType = QEvent::TouchUpdate; - touchPoint->d->state = globalPos == touchPoint->d->globalPos + touchPoint->d->state = screenPos == touchPoint->d->screenPos ? Qt::TouchPointStationary : Qt::TouchPointMoved; - touchPoint->d->lastGlobalPos = touchPoint->d->globalPos; - touchPoint->d->globalPos = globalPos; + touchPoint->d->lastScreenPos = touchPoint->d->screenPos; + touchPoint->d->screenPos = screenPos; // pressure should still be 1. } - Q_ASSERT(eventType != QEvent::None); + Q_ASSERT(widget != 0 && eventType != QEvent::None); if (touchPoint->d->state != Qt::TouchPointStationary) { - widgetsNeedingEvents.insert(touchPoint->d->widget, + widgetsNeedingEvents.insert(widget, QTouchEvent(eventType, q->keyboardModifiers(), activeTouchPoints)); } } diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 15f0511..35fe6a3 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3726,11 +3726,17 @@ void QGestureEvent::accept(const QString &type) */ QTouchEvent::QTouchEvent(QEvent::Type type, Qt::KeyboardModifiers modifiers, - const QList<TouchPoint *> &touchPoints) + const QList<QTouchEvent::TouchPoint *> &touchPoints) : QInputEvent(type, modifiers), _touchPoints(touchPoints) { } -/*! \fn const QList<QTouchEvent::TouchPoint *> &QTouchEvent::touchPoints() const +/*! + Destroys the QTouchEvent. +*/ +QTouchEvent::~QTouchEvent() +{ } + +/*! \fn const QList<QTouchEvent::TouchPoint *> &QTouchEvent::TouchPoints() const Returns the list of touch points contained in the touch event. */ @@ -3762,6 +3768,12 @@ int QTouchEvent::TouchPoint::id() const return d->id; } +/*! \internal */ +void QTouchEvent::TouchPoint::setId(int id) +{ + d->id = id; +} + /*! Returns the current state of this touch point. */ @@ -3770,56 +3782,98 @@ Qt::TouchPointState QTouchEvent::TouchPoint::state() const return d->state; } +/*! \internal */ +void QTouchEvent::TouchPoint::setState(Qt::TouchPointState state) +{ + d->state = state; +} + /*! Returns the position of this touch point, relative to the widget - that received the event. + or item that received the event. */ -const QPointF &QTouchEvent::TouchPoint::pos() const +QPointF QTouchEvent::TouchPoint::pos() const { return d->pos; } +/*! \internal */ +void QTouchEvent::TouchPoint::setPos(const QPointF &pos) +{ + d->pos = pos; +} + /*! Returns the starting position of this touch point, relative to the widget that received the event. */ -const QPointF &QTouchEvent::TouchPoint::startPos() const +QPointF QTouchEvent::TouchPoint::startPos() const { return d->startPos; } +/*! \internal */ +void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) +{ + d->startPos = startPos; +} + /*! Returns the position of this touch point from the previous touch event, relative to the widget that received the event. */ -const QPointF &QTouchEvent::TouchPoint::lastPos() const +QPointF QTouchEvent::TouchPoint::lastPos() const { return d->lastPos; } +/*! \internal */ +void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) +{ + d->lastPos = lastPos; +} + /*! - Returns the global position of this touch point. + Returns the screen position of this touch point. */ -const QPointF &QTouchEvent::TouchPoint::globalPos() const +QPointF QTouchEvent::TouchPoint::screenPos() const +{ + return d->screenPos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) { - return d->globalPos; + d->screenPos = screenPos; } /*! - Returns the global starting position of this touch point. + Returns the starting screen position of this touch point. */ -const QPointF &QTouchEvent::TouchPoint::startGlobalPos() const +QPointF QTouchEvent::TouchPoint::startScreenPos() const +{ + return d->startScreenPos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) { - return d->startGlobalPos; + d->startScreenPos = startScreenPos; } /*! - Returns the global position of this touch point from the previous + Returns the screen position of this touch point from the previous touch event. */ -const QPointF &QTouchEvent::TouchPoint::lastGlobalPos() const +QPointF QTouchEvent::TouchPoint::lastScreenPos() const +{ + return d->lastScreenPos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) { - return d->lastGlobalPos; + d->lastScreenPos = lastScreenPos; } /*! @@ -3831,4 +3885,10 @@ qreal QTouchEvent::TouchPoint::pressure() const return d->pressure; } +/*! \internal */ +void QTouchEvent::TouchPoint::setPressure(qreal pressure) +{ + d->pressure = pressure; +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index ea4f577..ed4129c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -768,20 +768,33 @@ public: ~TouchPoint(); int id() const; + void setId(int id); Qt::TouchPointState state() const; + void setState(Qt::TouchPointState state); - const QPointF &pos() const; - const QPointF &startPos() const; - const QPointF &lastPos() const; + QPointF pos() const; + void setPos(const QPointF &pos); - const QPointF &globalPos() const; - const QPointF &startGlobalPos() const; - const QPointF &lastGlobalPos() const; + QPointF startPos() const; + void setStartPos(const QPointF &startPos); + + QPointF lastPos() const; + void setLastPos(const QPointF &lastPos); + + QPointF screenPos() const; + void setScreenPos(const QPointF &screenPos); + + QPointF startScreenPos() const; + void setStartScreenPos(const QPointF &startScreenPos); + + QPointF lastScreenPos() const; + void setLastScreenPos(const QPointF &lastScreenPos); qreal pressure() const; // 0.0 -> 1.0 + void setPressure(qreal pressure); - private: + protected: QTouchEventTouchPointPrivate *d; friend class QApplication; @@ -790,13 +803,13 @@ public: QTouchEvent(QEvent::Type type, Qt::KeyboardModifiers modifiers, - const QList<TouchPoint *> &touchPoints); + const QList<QTouchEvent::TouchPoint *> &touchPoints); + ~QTouchEvent(); - inline const QList<TouchPoint *> &touchPoints() const { return _touchPoints; - } + inline const QList<QTouchEvent::TouchPoint *> &touchPoints() const { return _touchPoints; } protected: - QList<TouchPoint *> _touchPoints; + QList<QTouchEvent::TouchPoint *> _touchPoints; friend class QApplication; friend class QApplicationPrivate; diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 8623c66..dd78c3e 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -98,11 +98,11 @@ public: pressure(qreal(-1.)) { } - QPointer<QWidget> widget; int id; Qt::TouchPointState state; QPointF pos, startPos, lastPos; - QPointF globalPos, startGlobalPos, lastGlobalPos; + QPointF scenePos, startScenePos, lastScenePos; + QPointF screenPos, startScreenPos, lastScreenPos; qreal pressure; }; |