From ecc7f07e612bf156afb7fa2dbcbd2288b9b32e79 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 11 Jun 2009 14:00:50 +0200 Subject: remove duplicated code and API (merge QTouchEvent and QGraphicsSceneTouchEvent) the API for these 2 classes is identical, the implementation is almost identical, they share the same data structures, so bite the bullet and merge them. this means we go back to using screenPos() instead of globalPos() again --- examples/multitouch/knobs/knob.cpp | 14 +- src/corelib/kernel/qcoreevent.cpp | 3 - src/corelib/kernel/qcoreevent.h | 7 +- src/gui/graphicsview/qgraphicsitem.cpp | 5 +- src/gui/graphicsview/qgraphicsscene.cpp | 45 ++- src/gui/graphicsview/qgraphicsscene_p.h | 10 +- src/gui/graphicsview/qgraphicssceneevent.cpp | 402 --------------------------- src/gui/graphicsview/qgraphicssceneevent.h | 83 +----- src/gui/graphicsview/qgraphicsview.cpp | 77 +++-- src/gui/graphicsview/qgraphicsview_p.h | 5 +- src/gui/kernel/qapplication.cpp | 36 ++- src/gui/kernel/qapplication_win.cpp | 22 +- src/gui/kernel/qevent.cpp | 242 +++++++++++----- src/gui/kernel/qevent.h | 73 +++-- src/gui/kernel/qevent_p.h | 7 +- src/testlib/qtesttouch.h | 6 +- tests/auto/qtouchevent/tst_qtouchevent.cpp | 35 +-- 17 files changed, 340 insertions(+), 732 deletions(-) diff --git a/examples/multitouch/knobs/knob.cpp b/examples/multitouch/knobs/knob.cpp index d568167..b62d5b8 100644 --- a/examples/multitouch/knobs/knob.cpp +++ b/examples/multitouch/knobs/knob.cpp @@ -42,7 +42,7 @@ #include "knob.h" #include -#include +#include Knob::Knob() : QGraphicsEllipseItem(-50, -50, 100, 100) @@ -62,15 +62,15 @@ Knob::Knob() bool Knob::sceneEvent(QEvent *event) { switch (event->type()) { - case QEvent::GraphicsSceneTouchBegin: - case QEvent::GraphicsSceneTouchUpdate: - case QEvent::GraphicsSceneTouchEnd: + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: { - QGraphicsSceneTouchEvent *touchEvent = static_cast(event); + QTouchEvent *touchEvent = static_cast(event); if (touchEvent->touchPoints().count() == 2) { - const QGraphicsSceneTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); - const QGraphicsSceneTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last(); + const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first(); + const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last(); QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos()); QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos()); diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index d28d34e..68d05ea 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -226,9 +226,6 @@ QT_BEGIN_NAMESPACE \value TouchBegin Beginning of a sequence of touch-screen and/or track-pad events (QTouchEvent) \value TouchUpdate Touch-screen event (QTouchEvent) \value TouchEnd End of touch-event sequence (QTouchEvent) - \value GraphicsSceneTouchBegin Beginning of a sequence of touch-screen and/or track-pad events in a graphics scene (QGraphicsSceneTouchEvent) - \value GraphicsSceneTouchUpdate Touch-screen event in a graphics scene (QGraphicsSceneTouchEvent) - \value GraphicsSceneTouchEnd End of touch-event sequence in a graphics scene (QGraphicsSceneTouchEvent) \value Gesture A gesture has occured. \value GraphicsSceneGesture A gesture has occured on a graphics scene. diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index feefd08..2f80db6 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -275,12 +275,9 @@ public: TouchBegin = 194, TouchUpdate = 195, TouchEnd = 196, - GraphicsSceneTouchBegin = 197, - GraphicsSceneTouchUpdate = 198, - GraphicsSceneTouchEnd = 199, - Gesture = 200, - GraphicsSceneGesture = 201, + Gesture = 197, + GraphicsSceneGesture = 198, // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 97ca88e..97e2ac8 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2232,9 +2232,8 @@ void QGraphicsItem::setAcceptsHoverEvents(bool enabled) /*! \since 4.6 - Returns true if an item accepts touch events - (QGraphicsSceneTouchEvent); otherwise, returns false. By default, - items do not accept touch events. + Returns true if an item accepts touch events (QTouchEvent); otherwise, returns false. By + default, items do not accept touch events. \sa setAcceptTouchEvents() */ diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 291b3af..f881965 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3796,9 +3796,9 @@ bool QGraphicsScene::event(QEvent *event) case QEvent::GraphicsSceneHoverEnter: case QEvent::GraphicsSceneHoverLeave: case QEvent::GraphicsSceneHoverMove: - case QEvent::GraphicsSceneTouchBegin: - case QEvent::GraphicsSceneTouchUpdate: - case QEvent::GraphicsSceneTouchEnd: + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: // 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 @@ -3993,10 +3993,10 @@ bool QGraphicsScene::event(QEvent *event) d->sendGestureEvent(ev->gestures().toSet(), ev->cancelledGestures()); } break; - case QEvent::GraphicsSceneTouchBegin: - case QEvent::GraphicsSceneTouchUpdate: - case QEvent::GraphicsSceneTouchEnd: - d->touchEventHandler(static_cast(event)); + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + d->touchEventHandler(static_cast(event)); break; case QEvent::Timer: if (d->indexTimerId && static_cast(event)->timerId() == d->indexTimerId) { @@ -5954,12 +5954,11 @@ void QGraphicsScenePrivate::releaseGesture(QGraphicsItem *item, int gestureId) //### } -void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, - QGraphicsSceneTouchEvent *touchEvent) +void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent) { - QList touchPoints = touchEvent->touchPoints(); + QList touchPoints = touchEvent->touchPoints(); for (int i = 0; i < touchPoints.count(); ++i) { - QGraphicsSceneTouchEvent::TouchPoint &touchPoint = touchPoints[i]; + QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; touchPoint.setPos(item->d_ptr->genericMapFromScene(touchPoint.scenePos(), touchEvent->widget())); touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget())); touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget())); @@ -5975,7 +5974,7 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) { int closestTouchPointId = -1; qreal closestDistance = qreal(0.); - foreach (const QGraphicsSceneTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) { + foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) { qreal distance = QLineF(scenePos, touchPoint.scenePos()).length(); if (closestTouchPointId == -1|| distance < closestDistance) { closestTouchPointId = touchPoint.id(); @@ -5985,13 +5984,13 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) return closestTouchPointId; } -void QGraphicsScenePrivate::touchEventHandler(QGraphicsSceneTouchEvent *sceneTouchEvent) +void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) { - typedef QPair > StatesAndTouchPoints; + typedef QPair > StatesAndTouchPoints; QHash itemsNeedingEvents; for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) { - const QGraphicsSceneTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i); + const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i); // update state QGraphicsItem *item = 0; @@ -6049,29 +6048,29 @@ void QGraphicsScenePrivate::touchEventHandler(QGraphicsSceneTouchEvent *sceneTou switch (it.value().first) { case Qt::TouchPointPressed: // all touch points have pressed state - eventType = QEvent::GraphicsSceneTouchBegin; + eventType = QEvent::TouchBegin; break; case Qt::TouchPointReleased: // all touch points have released state - eventType = QEvent::GraphicsSceneTouchEnd; + eventType = QEvent::TouchEnd; break; case Qt::TouchPointStationary: // don't send the event if nothing changed continue; default: // all other combinations - eventType = QEvent::GraphicsSceneTouchUpdate; + eventType = QEvent::TouchUpdate; break; } - QGraphicsSceneTouchEvent touchEvent(eventType); + QTouchEvent touchEvent(eventType); touchEvent.setWidget(sceneTouchEvent->widget()); touchEvent.setModifiers(sceneTouchEvent->modifiers()); touchEvent.setTouchPointStates(it.value().first); touchEvent.setTouchPoints(it.value().second); switch (touchEvent.type()) { - case QEvent::GraphicsSceneTouchBegin: + case QEvent::TouchBegin: { // if the TouchBegin handler recurses, we assume that means the event // has been implicitly accepted and continue to send touch events @@ -6093,12 +6092,12 @@ void QGraphicsScenePrivate::touchEventHandler(QGraphicsSceneTouchEvent *sceneTou sceneTouchEvent->setAccepted(acceptSceneTouchEvent); } -bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QGraphicsSceneTouchEvent *touchEvent) +bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent) { Q_Q(QGraphicsScene); if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) { - const QGraphicsSceneTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); + const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), firstTouchPoint.scenePos(), touchEvent->widget()); @@ -6136,7 +6135,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QGraphics if (res && eventAccepted) { // the first item to accept the TouchBegin gets an implicit grab. for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { - const QGraphicsSceneTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); + const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); itemForTouchPointId[touchPoint.id()] = item; } break; diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index bd312a1..6983d12 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -35,7 +35,7 @@ ** ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ +** $QT_END_LICENSE$' ** ****************************************************************************/ @@ -304,12 +304,12 @@ public: void releaseGesture(QGraphicsItem *item, int gestureId); void sendGestureEvent(const QSet &gestures, const QSet &cancelled); - QMap sceneCurrentTouchPoints; + QMap sceneCurrentTouchPoints; QHash itemForTouchPointId; - static void updateTouchPointsForItem(QGraphicsItem *item, QGraphicsSceneTouchEvent *touchEvent); + static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent); int findClosestTouchPointId(const QPointF &scenePos); - void touchEventHandler(QGraphicsSceneTouchEvent *touchEvent); - bool sendTouchBeginEvent(QGraphicsItem *item, QGraphicsSceneTouchEvent *touchEvent); + void touchEventHandler(QTouchEvent *touchEvent); + bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent); }; QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp index 1be8d0d..bf82dd4 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.cpp +++ b/src/gui/graphicsview/qgraphicssceneevent.cpp @@ -257,37 +257,6 @@ QGraphicsItem::ItemPositionHasChanged */ -/*! - \class QGraphicsSceneTouchEvent - \brief The QGraphicsSceneTouchEvent class provides touch events in the graphics view framework. - \since 4.6 - \ingroup multimedia - \ingroup graphicsview-api - - When a QGraphicsView receives a QTouchEvent, it translates it to a - QGraphicsSceneTouchEvent. The event is then forwarded to the - QGraphicsScene associated with the view. - - The touchPoints() function returns a list of touch points for the - event. In addition to containing the item, scene, and screen - coordinates, each touch point also contains its starting and - previous coordinates. - - \sa QTouchEvent -*/ - -/*! - \class QGraphicsSceneTouchEvent::TouchPoint - \brief The QGraphicsSceneTouchEvent::TouchPoint class represents a single touch point in a QGraphicsSceneTouchEvent. - \since 4.6 - \ingroup multimedia - \ingroup graphicsview-api - - Each touch point in a QGraphicsSceneTouchEvent has an id() and - state() in addition to current, starting, and previous coordinates - for the touch point in item, scene, and screen coordinates. -*/ - #include "qgraphicssceneevent.h" #ifndef QT_NO_GRAPHICSVIEW @@ -1952,377 +1921,6 @@ void QGraphicsSceneGestureEvent::accept(const QString &type) g->accept(); } -class QGraphicsSceneTouchEventPrivate : public QGraphicsSceneEventPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsSceneTouchEvent) -public: - inline QGraphicsSceneTouchEventPrivate() - : modifiers(Qt::NoModifier), touchPointStates() - { } - - Qt::KeyboardModifiers modifiers; - Qt::TouchPointStates touchPointStates; - QList touchPoints; -}; - -/*! - \internal - - Constructs a generic QGraphicsSceneTouchEvent of type \a type. -*/ -QGraphicsSceneTouchEvent::QGraphicsSceneTouchEvent(Type type) - : QGraphicsSceneEvent(*new QGraphicsSceneTouchEventPrivate, type) -{ } - -/*! - Destroys the QGraphicsSceneTouchEvent. -*/ -QGraphicsSceneTouchEvent::~QGraphicsSceneTouchEvent() -{ } - -/*! - Returns the keyboard modifiers in use at the time the event was - sent. -*/ -Qt::KeyboardModifiers QGraphicsSceneTouchEvent::modifiers() const -{ - Q_D(const QGraphicsSceneTouchEvent); - return d->modifiers; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::setModifiers(Qt::KeyboardModifiers modifiers) -{ - Q_D(QGraphicsSceneTouchEvent); - d->modifiers = modifiers; -} - -/*! - Returns a bitwise OR of all of the touch point states at the time - the event was sent. -*/ -Qt::TouchPointStates QGraphicsSceneTouchEvent::touchPointStates() const -{ - Q_D(const QGraphicsSceneTouchEvent); - return d->touchPointStates; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) -{ - Q_D(QGraphicsSceneTouchEvent); - d->touchPointStates = touchPointStates; -} - -/*! - Returns the list of touch points for this event. - - \sa QGraphicsSceneTouchEvent::TouchPoint -*/ -const QList &QGraphicsSceneTouchEvent::touchPoints() const -{ - Q_D(const QGraphicsSceneTouchEvent); - return d->touchPoints; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::setTouchPoints(const QList &touchPoints) -{ - Q_D(QGraphicsSceneTouchEvent); - d->touchPoints = touchPoints; -} - -/*! \internal */ -QGraphicsSceneTouchEvent::TouchPoint::TouchPoint(int id) - : d(new QTouchEventTouchPointPrivate(id)) -{ } - -/*! \internal */ -QGraphicsSceneTouchEvent::TouchPoint::TouchPoint(const QGraphicsSceneTouchEvent::TouchPoint &other) - : d(other.d) -{ - d->ref.ref(); -} - -/*! \internal */ -QGraphicsSceneTouchEvent::TouchPoint::TouchPoint(QTouchEventTouchPointPrivate *dd) - : d(dd) -{ - d->ref.ref(); -} - -/*! \internal */ -QGraphicsSceneTouchEvent::TouchPoint::~TouchPoint() -{ - if (!d->ref.deref()) - delete d; -} - -/*! - Returns the id number of this touch point. - - Id numbers are globally sequential, starting at zero, meaning the - first touch point in the application has id 0, the second has id 1, - and so on. -*/ -int QGraphicsSceneTouchEvent::TouchPoint::id() const -{ - return d->id; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setId(int id) -{ - if (!d->ref == 1) - d = d->detach(); - d->id = id; -} - -/*! - Returns the current state of this touch point. -*/ -Qt::TouchPointState QGraphicsSceneTouchEvent::TouchPoint::state() const -{ - return d->state; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setState(Qt::TouchPointState state) -{ - if (d->ref != 1) - d = d->detach(); - d->state = state; -} - -/*! - Returns the position of this touch point, relative to the widget - or item that received the event. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::pos() const -{ - return d->pos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setPos(const QPointF &pos) -{ - if (d->ref != 1) - d = d->detach(); - d->pos = pos; -} - -/*! - Returns the starting position of this touch point, relative to the - widget that received the event. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::startPos() const -{ - return d->startPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) -{ - if (d->ref != 1) - d = d->detach(); - d->startPos = startPos; -} - -/*! - Returns the position of this touch point from the previous touch - event, relative to the widget that received the event. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::lastPos() const -{ - return d->lastPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) -{ - if (d->ref != 1) - d = d->detach(); - d->lastPos = lastPos; -} - -/*! - Returns the current position of this touch point in scene coordinates. - - \sa pos(), screenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::scenePos() const -{ - return d->scenePos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos) -{ - if (d->ref != 1) - d = d->detach(); - d->scenePos = scenePos; -} - -/*! - Returns the starting position of this touch point in scene coordinates. - - \sa startPos(), startScreenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::startScenePos() const -{ - return d->startScenePos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos) -{ - if (d->ref != 1) - d = d->detach(); - d->startScenePos = startScenePos; -} - -/*! - Returns the previous position of this touch point in scene coordinates. - - \sa lastPos(), lastScreenPos() -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::lastScenePos() const -{ - return d->lastScenePos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos) -{ - if (d->ref != 1) - d = d->detach(); - d->lastScenePos = lastScenePos; -} - -/*! - Returns the screen position of this touch point. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::screenPos() const -{ - return d->screenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) -{ - if (d->ref != 1) - d = d->detach(); - d->screenPos = screenPos; -} - -/*! - Returns the starting screen position of this touch point. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::startScreenPos() const -{ - return d->startScreenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) -{ - if (d->ref != 1) - d = d->detach(); - d->startScreenPos = startScreenPos; -} - -/*! - Returns the screen position of this touch point from the previous - touch event. -*/ -QPointF QGraphicsSceneTouchEvent::TouchPoint::lastScreenPos() const -{ - return d->lastScreenPos; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) -{ - if (d->ref != 1) - d = d->detach(); - d->lastScreenPos = lastScreenPos; -} - -/*! - Returns the rect for this touch point. -*/ -QRectF QGraphicsSceneTouchEvent::TouchPoint::rect() const -{ - return d->rect; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setRect(const QRectF &rect) -{ - if (d->ref != 1) - d = d->detach(); - d->rect = rect; -} - -/*! - Returns the rect of this touch point in scene coordinates. -*/ -QRectF QGraphicsSceneTouchEvent::TouchPoint::sceneRect() const -{ - return d->sceneRect; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) -{ - if (d->ref != 1) - d = d->detach(); - d->sceneRect = sceneRect; -} - -/*! - Returns the rect of this touch point in screen coordinates. -*/ -QRectF QGraphicsSceneTouchEvent::TouchPoint::screenRect() const -{ - return d->screenRect; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) -{ - if (d->ref != 1) - d = d->detach(); - d->screenRect = screenRect; -} - -/*! - Returns the pressure of this touch point. The return value is in - the range 0.0 to 1.0. -*/ -qreal QGraphicsSceneTouchEvent::TouchPoint::pressure() const -{ - return d->pressure; -} - -/*! \internal */ -void QGraphicsSceneTouchEvent::TouchPoint::setPressure(qreal pressure) -{ - if (d->ref != 1) - d = d->detach(); - d->pressure = pressure; -} - -/*! \internal */ -QGraphicsSceneTouchEvent::TouchPoint &QGraphicsSceneTouchEvent::TouchPoint::operator=(const QGraphicsSceneTouchEvent::TouchPoint &other) -{ - other.d->ref.ref(); - if (!d->ref.deref()) - delete d; - d = other.d; - return *this; -} - QT_END_NAMESPACE #endif // QT_NO_GRAPHICSVIEW diff --git a/src/gui/graphicsview/qgraphicssceneevent.h b/src/gui/graphicsview/qgraphicssceneevent.h index 3eb5cce..93a7177 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.h +++ b/src/gui/graphicsview/qgraphicssceneevent.h @@ -42,7 +42,7 @@ #ifndef QGRAPHICSSCENEEVENT_H #define QGRAPHICSSCENEEVENT_H -#include +#include #include #include #include @@ -60,7 +60,6 @@ QT_MODULE(Gui) class QMimeData; class QPointF; class QSizeF; -class QRectF; class QWidget; class QGraphicsSceneEventPrivate; @@ -350,86 +349,6 @@ protected: QSet m_cancelledGestures; }; -class QGraphicsSceneTouchEventPrivate; -class Q_GUI_EXPORT QGraphicsSceneTouchEvent : public QGraphicsSceneEvent -{ -public: - class Q_GUI_EXPORT TouchPoint - { - public: - TouchPoint(int id = -1); - TouchPoint(const TouchPoint &other); - ~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); - - QPointF startScenePos() const; - void setStartScenePos(const QPointF &startScenePos); - - 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); - - QRectF rect() const; - void setRect(const QRectF &rect); - - QRectF sceneRect() const; - void setSceneRect(const QRectF &sceneRect); - - QRectF screenRect() const; - void setScreenRect(const QRectF &screenRect); - - qreal pressure() const; - void setPressure(qreal pressure); - - TouchPoint &operator=(const TouchPoint &other); - - private: - TouchPoint(QTouchEventTouchPointPrivate *dd); - QTouchEventTouchPointPrivate *d; - friend class QGraphicsViewPrivate; - }; - - QGraphicsSceneTouchEvent(Type type = None); - ~QGraphicsSceneTouchEvent(); - - Qt::KeyboardModifiers modifiers() const; - void setModifiers(Qt::KeyboardModifiers modifiers); - - Qt::TouchPointStates touchPointStates() const; - void setTouchPointStates(Qt::TouchPointStates touchPointStates); - - const QList &touchPoints() const; - void setTouchPoints(const QList &touchPoints); - -private: - Q_DECLARE_PRIVATE(QGraphicsSceneTouchEvent); -}; - #endif // QT_NO_GRAPHICSVIEW QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 521ef7f..ab7d7ab 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -297,34 +297,21 @@ 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); } -void QGraphicsViewPrivate::convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d, - QTouchEvent *originalEvent, - QGraphicsSceneTouchEvent *touchEvent) -{ - QList originalTouchPoints = originalEvent->touchPoints(); - QList touchPoints; - for (int i = 0; i < originalTouchPoints.count(); ++i) { - QGraphicsSceneTouchEvent::TouchPoint touchPoint = - QTouchEventTouchPointPrivate::get(originalTouchPoints.at(i)); - // the scene will set the item local pos, startPos, lastPos, and size before delivering to - // an item, but for now those functions are returning the view's local coordinates (since - // we're reusing the d-pointer from the orignalTouchPoint) - touchPoint.setScenePos(d->mapToScene(touchPoint.pos())); +void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent) +{ + QList touchPoints = touchEvent->touchPoints(); + for (int i = 0; i < touchPoints.count(); ++i) { + QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; + // the scene will set the item local pos, startPos, lastPos, and rect before delivering to + // an item, but for now those functions are returning the view's local coordinates + touchPoint.setSceneRect(d->mapToScene(touchPoint.rect())); touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos())); touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos())); -#ifdef Q_CC_GNU -# warning FIXME -#endif - // ### touchPoint.setSceneSize(d->mapToScene(touchPoint.screenSize())); - - // screenPos, startScreenPos, lastScreenPos, and screenSize are already set from the - // originalTouchPoint - touchPoints.append(touchPoint); + // screenPos, startScreenPos, lastScreenPos, and screenRect are already set } touchEvent->setTouchPoints(touchPoints); - touchEvent->setModifiers(originalEvent->modifiers()); } /*! @@ -2768,23 +2755,10 @@ bool QGraphicsView::viewportEvent(QEvent *event) if (d->scene && d->sceneInteractionAllowed) { // Convert and deliver the touch event to the scene. - QEvent::Type eventType; - switch(event->type()) { - case QEvent::TouchUpdate: - eventType = QEvent::GraphicsSceneTouchUpdate; - break; - case QEvent::TouchBegin: - eventType = QEvent::GraphicsSceneTouchBegin; - break; - default: - eventType = QEvent::GraphicsSceneTouchEnd; - } - QGraphicsSceneTouchEvent touchEvent(eventType); - touchEvent.setWidget(viewport()); - QGraphicsViewPrivate::convertTouchEventToGraphicsSceneTouchEvent(d, static_cast(event), &touchEvent); - touchEvent.setAccepted(false); - QApplication::sendEvent(d->scene, &touchEvent); - event->setAccepted(touchEvent.isAccepted()); + QTouchEvent *touchEvent = static_cast(event); + touchEvent->setWidget(viewport()); + QGraphicsViewPrivate::translateTouchEvent(d, touchEvent); + (void) QApplication::sendEvent(d->scene, touchEvent); } return true; @@ -3719,6 +3693,31 @@ QPointF QGraphicsViewPrivate::mapToScene(const QPointF &point) const return identityMatrix ? p : matrix.inverted().map(p); } +QRectF QGraphicsViewPrivate::mapToScene(const QRectF &rect) const +{ + QPointF scrollOffset(horizontalScroll(), verticalScroll()); + QPointF tl = scrollOffset + rect.topLeft(); + QPointF tr = scrollOffset + rect.topRight(); + QPointF br = scrollOffset + rect.bottomRight(); + QPointF bl = scrollOffset + rect.bottomLeft(); + + QPolygonF poly; + poly.resize(4); + if (!identityMatrix) { + QTransform x = matrix.inverted(); + poly[0] = x.map(tl); + poly[1] = x.map(tr); + poly[2] = x.map(br); + poly[3] = x.map(bl); + } else { + poly[0] = tl; + poly[1] = tr; + poly[2] = br; + poly[3] = bl; + } + return poly.boundingRect(); +} + QT_END_NAMESPACE #include "moc_qgraphicsview.cpp" diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index a54ccf0..6138d0a 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -179,9 +179,8 @@ public: const QRegion &exposedRegion) const; QPointF mapToScene(const QPointF &point) const; - static void convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d, - QTouchEvent *originalEvent, - QGraphicsSceneTouchEvent *touchEvent); + QRectF mapToScene(const QRectF &rect) const; + static void translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 7cb1ac1..c072c4a 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4052,6 +4052,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) while (widget) { // first, try to deliver the touch event bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); + touchEvent->setWidget(widget); touchEvent->setAccepted(acceptTouchEvents); res = acceptTouchEvents && d->notify_helper(widget, touchEvent); eventAccepted = touchEvent->isAccepted(); @@ -5258,10 +5259,15 @@ void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEven QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i]; // preserve the sub-pixel resolution - const QPointF delta = touchPoint.globalPos() - touchPoint.globalPos().toPoint(); - touchPoint.setPos(widget->mapFromGlobal(touchPoint.globalPos().toPoint()) + delta); - touchPoint.setStartPos(widget->mapFromGlobal(touchPoint.startGlobalPos().toPoint()) + delta); - touchPoint.setLastPos(widget->mapFromGlobal(touchPoint.lastGlobalPos().toPoint()) + delta); + QRectF rect = touchPoint.screenRect(); + const QPointF screenPos = rect.center(); + const QPointF delta = screenPos - screenPos.toPoint(); + + rect.moveCenter(widget->mapFromGlobal(screenPos.toPoint()) + delta); + touchPoint.setRect(rect); + + touchPoint.setStartPos(widget->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta); + touchPoint.setLastPos(widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta); } } @@ -5281,12 +5287,12 @@ void QApplicationPrivate::cleanupMultitouch() appCurrentTouchPoints.clear(); } -int QApplicationPrivate::findClosestTouchPointId(const QPointF &globalPos) +int QApplicationPrivate::findClosestTouchPointId(const QPointF &screenPos) { int closestTouchPointId = -1; qreal closestDistance = qreal(0.); foreach (const QTouchEvent::TouchPoint &touchPoint, appCurrentTouchPoints) { - qreal distance = QLineF(globalPos, touchPoint.globalPos()).length(); + qreal distance = QLineF(screenPos, touchPoint.screenPos()).length(); if (closestTouchPointId == -1 || distance < closestDistance) { closestTouchPointId = touchPoint.id(); closestDistance = distance; @@ -5314,22 +5320,22 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, { // determine which widget this event will go to if (!window) - window = q->topLevelAt(touchPoint.globalPos().toPoint()); + window = q->topLevelAt(touchPoint.screenPos().toPoint()); if (!window) continue; - widget = window->childAt(window->mapFromGlobal(touchPoint.globalPos().toPoint())); + widget = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint())); if (!widget) widget = window; - int closestTouchPointId = d->findClosestTouchPointId(touchPoint.globalPos()); + int closestTouchPointId = d->findClosestTouchPointId(touchPoint.screenPos()); QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId); if (closestWidget && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) { widget = closestWidget; } d->widgetForTouchPointId[touchPoint.id()] = widget; - touchPoint.setStartGlobalPos(touchPoint.globalPos()); - touchPoint.setLastGlobalPos(touchPoint.globalPos()); + touchPoint.setStartScreenPos(touchPoint.screenPos()); + touchPoint.setLastScreenPos(touchPoint.screenPos()); d->appCurrentTouchPoints.insert(touchPoint.id(), touchPoint); break; } @@ -5340,8 +5346,8 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, continue; QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.take(touchPoint.id()); - touchPoint.setStartGlobalPos(previousTouchPoint.startGlobalPos()); - touchPoint.setLastGlobalPos(previousTouchPoint.globalPos()); + touchPoint.setStartScreenPos(previousTouchPoint.startScreenPos()); + touchPoint.setLastScreenPos(previousTouchPoint.screenPos()); break; } default: @@ -5350,8 +5356,8 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, continue; Q_ASSERT(d->appCurrentTouchPoints.contains(touchPoint.id())); QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.value(touchPoint.id()); - touchPoint.setStartGlobalPos(previousTouchPoint.startGlobalPos()); - touchPoint.setLastGlobalPos(previousTouchPoint.globalPos()); + touchPoint.setStartScreenPos(previousTouchPoint.startScreenPos()); + touchPoint.setLastScreenPos(previousTouchPoint.screenPos()); d->appCurrentTouchPoints[touchPoint.id()] = touchPoint; break; } diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 0c5945d..4ecf299 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -4040,27 +4040,27 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg) QTouchEvent::TouchPoint touchPoint(touchPointID); // update state - QPointF globalPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); - QRectF globalRect; + QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.)); + QRectF screenRect; if (touchInput.dwMask & TOUCHINPUTMASKF_CONTACTAREA) - globalRect.setSize(QSizeF(qreal(touchInput.cxContact) / qreal(100.), + screenRect.setSize(QSizeF(qreal(touchInput.cxContact) / qreal(100.), qreal(touchInput.cyContact) / qreal(100.))); - globalRect.moveCenter(globalPos); + screenRect.moveCenter(screenPos); if (touchInput.dwFlags & TOUCHEVENTF_DOWN) { touchPoint.setState(Qt::TouchPointPressed); - touchPoint.setGlobalPos(globalPos); - touchPoint.setRect(globalRect); + touchPoint.setScreenPos(screenPos); + touchPoint.setRect(screenRect); } else if (touchInput.dwFlags & TOUCHEVENTF_UP) { touchPoint.setState(Qt::TouchPointReleased); - touchPoint.setGlobalPos(globalPos); - touchPoint.setRect(globalRect); + touchPoint.setScreenPos(screenPos); + touchPoint.setRect(screenRect); } else { - touchPoint.setState(globalPos == touchPoint.globalPos() + touchPoint.setState(screenPos == touchPoint.screenPos() ? Qt::TouchPointStationary : Qt::TouchPointMoved); - touchPoint.setGlobalPos(globalPos); - touchPoint.setRect(globalRect); + touchPoint.setScreenPos(screenPos); + touchPoint.setRect(screenRect); } touchPoints.append(touchPoint); diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 7a86dbf..a55d7e2 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -85,6 +85,13 @@ QInputEvent::~QInputEvent() \sa QApplication::keyboardModifiers() */ +/*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers) + + \internal + + Sets the keyboard modifiers flags for this event. +*/ + /*! \class QMouseEvent \ingroup events @@ -3744,21 +3751,34 @@ QTouchEvent::QTouchEvent(QEvent::Type type, QTouchEvent::~QTouchEvent() { } +/*! \fn QWidget *QTouchEvent::widget() const + + Returns the widget on which the event occurred. +*/ + + /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const Returns a bitwise OR of all the touch point states for this event. */ -/*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) +/*! \fn const QList &QTouchEvent::touchPoints() const + + Returns the list of touch points contained in the touch event. +*/ + +/*! \fn void QTouchEvent::setWidget(QWidget *widget) \internal - Sets a bitwise OR of all the touch point states for this event. + Sets the widget for this event. */ -/*! \fn const QList &QTouchEvent::TouchPoints() const +/*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) - Returns the list of touch points contained in the touch event. + \internal + + Sets a bitwise OR of all the touch point states for this event. */ /*! \fn void QTouchEvent::setTouchPoints(QList &touchPoints) @@ -3808,14 +3828,6 @@ int QTouchEvent::TouchPoint::id() const return d->id; } -/*! \internal */ -void QTouchEvent::TouchPoint::setId(int id) -{ - if (d->ref != 1) - d = d->detach(); - d->id = id; -} - /*! Returns the current state of this touch point. */ @@ -3824,29 +3836,29 @@ Qt::TouchPointState QTouchEvent::TouchPoint::state() const return d->state; } -/*! \internal */ -void QTouchEvent::TouchPoint::setState(Qt::TouchPointState state) -{ - if (d->ref != 1) - d = d->detach(); - d->state = state; -} - /*! Returns the position of this touch point, relative to the widget or item that received the event. */ QPointF QTouchEvent::TouchPoint::pos() const { - return d->pos; + return d->rect.center(); } -/*! \internal */ -void QTouchEvent::TouchPoint::setPos(const QPointF &pos) +/*! + Returns the scene position of this touch point. +*/ +QPointF QTouchEvent::TouchPoint::scenePos() const { - if (d->ref != 1) - d = d->detach(); - d->pos = pos; + return d->sceneRect.center(); +} + +/*! + Returns the screen position of this touch point. +*/ +QPointF QTouchEvent::TouchPoint::screenPos() const +{ + return d->screenRect.center(); } /*! @@ -3858,12 +3870,20 @@ QPointF QTouchEvent::TouchPoint::startPos() const return d->startPos; } -/*! \internal */ -void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) +/*! + Returns the starting scene position of this touch point. +*/ +QPointF QTouchEvent::TouchPoint::startScenePos() const { - if (d->ref != 1) - d = d->detach(); - d->startPos = startPos; + return d->startScenePos; +} + +/*! + Returns the starting screen position of this touch point. +*/ +QPointF QTouchEvent::TouchPoint::startScreenPos() const +{ + return d->startScreenPos; } /*! @@ -3875,70 +3895,144 @@ QPointF QTouchEvent::TouchPoint::lastPos() const return d->lastPos; } +/*! + Returns the scene position of this touch point from the previous + touch event. +*/ +QPointF QTouchEvent::TouchPoint::lastScenePos() const +{ + return d->lastScenePos; +} + +/*! + Returns the screen position of this touch point from the previous + touch event. +*/ +QPointF QTouchEvent::TouchPoint::lastScreenPos() const +{ + return d->lastScreenPos; +} + +/*! + Returns the rect for this touch point. The rect is centered around the point returned by pos(). + Note this function returns an empty rect if the device does not report touch point sizes. +*/ +QRectF QTouchEvent::TouchPoint::rect() const +{ + return d->screenRect; +} + +/*! + Returns the rect for this touch point in scene coordinates. +*/ +QRectF QTouchEvent::TouchPoint::sceneRect() const +{ + return d->sceneRect; +} + +/*! + Returns the rect for this touch point in screen coordinates. +*/ +QRectF QTouchEvent::TouchPoint::screenRect() const +{ + return d->screenRect; +} + +/*! + Returns the pressure of this touch point. The return value is in + the range 0.0 to 1.0. +*/ +qreal QTouchEvent::TouchPoint::pressure() const +{ + return d->pressure; +} + /*! \internal */ -void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) +void QTouchEvent::TouchPoint::setId(int id) { if (d->ref != 1) d = d->detach(); - d->lastPos = lastPos; + d->id = id; } -/*! - Returns the screen position of this touch point. -*/ -QPointF QTouchEvent::TouchPoint::globalPos() const +/*! \internal */ +void QTouchEvent::TouchPoint::setState(Qt::TouchPointState state) { - return d->screenPos; + if (d->ref != 1) + d = d->detach(); + d->state = state; } /*! \internal */ -void QTouchEvent::TouchPoint::setGlobalPos(const QPointF &globalPos) +void QTouchEvent::TouchPoint::setPos(const QPointF &pos) { if (d->ref != 1) d = d->detach(); - d->screenPos = globalPos; + d->rect.moveCenter(pos); } -/*! - Returns the starting screen position of this touch point. -*/ -QPointF QTouchEvent::TouchPoint::startGlobalPos() const +/*! \internal */ +void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos) { - return d->startScreenPos; + if (d->ref != 1) + d = d->detach(); + d->sceneRect.moveCenter(scenePos); } /*! \internal */ -void QTouchEvent::TouchPoint::setStartGlobalPos(const QPointF &startGlobalPos) +void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos) { if (d->ref != 1) d = d->detach(); - d->startScreenPos = startGlobalPos; + d->screenRect.moveCenter(screenPos); } -/*! - Returns the screen position of this touch point from the previous - touch event. -*/ -QPointF QTouchEvent::TouchPoint::lastGlobalPos() const +/*! \internal */ +void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos) { - return d->lastScreenPos; + if (d->ref != 1) + d = d->detach(); + d->startPos = startPos; } /*! \internal */ -void QTouchEvent::TouchPoint::setLastGlobalPos(const QPointF &lastGlobalPos) +void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos) { if (d->ref != 1) d = d->detach(); - d->lastScreenPos = lastGlobalPos; + d->startScenePos = startScenePos; } -/*! - Returns the rect for this touch point. The rect is centered around the point returned by pos(). - Note this function returns an empty rect if the device does not report touch point sizes. -*/ -QRectF QTouchEvent::TouchPoint::rect() const +/*! \internal */ +void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos) { - return d->screenRect; + if (d->ref != 1) + d = d->detach(); + d->startScreenPos = startScreenPos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos) +{ + if (d->ref != 1) + d = d->detach(); + d->lastPos = lastPos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos) +{ + if (d->ref != 1) + d = d->detach(); + d->lastScenePos = lastScenePos; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos) +{ + if (d->ref != 1) + d = d->detach(); + d->lastScreenPos = lastScreenPos; } /*! \internal */ @@ -3946,16 +4040,23 @@ void QTouchEvent::TouchPoint::setRect(const QRectF &rect) { if (d->ref != 1) d = d->detach(); - d->screenRect = rect; + d->rect = rect; } -/*! - Returns the pressure of this touch point. The return value is in - the range 0.0 to 1.0. -*/ -qreal QTouchEvent::TouchPoint::pressure() const +/*! \internal */ +void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect) { - return d->pressure; + if (d->ref != 1) + d = d->detach(); + d->sceneRect = sceneRect; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect) +{ + if (d->ref != 1) + d = d->detach(); + d->screenRect = screenRect; } /*! \internal */ @@ -3976,9 +4077,4 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T return *this; } -QTouchEventTouchPointPrivate *QTouchEventTouchPointPrivate::get(const QTouchEvent::TouchPoint &tp) -{ - return tp.d; -} - QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 4d62958..2f735ac 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -70,6 +70,7 @@ public: QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QInputEvent(); inline Qt::KeyboardModifiers modifiers() const { return modState; } + inline void setModifiers(Qt::KeyboardModifiers modifiers) { modState = modifiers; } protected: Qt::KeyboardModifiers modState; }; @@ -769,68 +770,66 @@ public: ~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 globalPos() const; - void setGlobalPos(const QPointF &globalPos); + QPointF scenePos() const; + QPointF startScenePos() const; + QPointF lastScenePos() const; - QPointF startGlobalPos() const; - void setStartGlobalPos(const QPointF &startGlobalPos); - - QPointF lastGlobalPos() const; - void setLastGlobalPos(const QPointF &lastGlobalPos); + QPointF screenPos() const; + QPointF startScreenPos() const; + QPointF lastScreenPos() const; QRectF rect() const; - void setRect(const QRectF &rect); + QRectF sceneRect() const; + QRectF screenRect() const; qreal pressure() const; - void setPressure(qreal pressure); + // internal + void setId(int id); + void setState(Qt::TouchPointState state); + void setPos(const QPointF &pos); + void setScenePos(const QPointF &scenePos); + void setScreenPos(const QPointF &screenPos); + void setStartPos(const QPointF &startPos); + void setStartScenePos(const QPointF &startScenePos); + void setStartScreenPos(const QPointF &startScreenPos); + void setLastPos(const QPointF &lastPos); + void setLastScenePos(const QPointF &lastScenePos); + void setLastScreenPos(const QPointF &lastScreenPos); + void setRect(const QRectF &rect); + void setSceneRect(const QRectF &sceneRect); + void setScreenRect(const QRectF &screenRect); + void setPressure(qreal pressure); TouchPoint &operator=(const TouchPoint &other); private: QTouchEventTouchPointPrivate *d; - - friend class QTouchEventTouchPointPrivate; }; QTouchEvent(QEvent::Type type, - Qt::KeyboardModifiers modifiers, - Qt::TouchPointStates touchPointStates, - const QList &touchPoints); + Qt::KeyboardModifiers modifiers = Qt::NoModifier, + Qt::TouchPointStates touchPointStates = 0, + const QList &touchPoints = QList()); ~QTouchEvent(); - inline Qt::TouchPointStates touchPointStates() const - { - return _touchPointStates; - } - inline void setTouchPointStates(Qt::TouchPointStates touchPointStates) - { - _touchPointStates = touchPointStates; - } + inline QWidget *widget() const { return _widget; } + inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; } + inline const QList &touchPoints() const { return _touchPoints; } - inline const QList &touchPoints() const - { - return _touchPoints; - } - inline void setTouchPoints(const QList &touchPoints) - { - _touchPoints = touchPoints; - } + // internal + inline void setWidget(QWidget *widget) { _widget = widget; } + inline void setTouchPointStates(Qt::TouchPointStates touchPointStates) { _touchPointStates = touchPointStates; } + inline void setTouchPoints(const QList &touchPoints) { _touchPoints = touchPoints; } protected: + QWidget *_widget; Qt::TouchPointStates _touchPointStates; QList _touchPoints; diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 3475d0d..2a481fb 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -109,13 +109,10 @@ public: QAtomicInt ref; int id; Qt::TouchPointState state; - QPointF pos, startPos, lastPos; - QPointF scenePos, startScenePos, lastScenePos; - QPointF screenPos, startScreenPos, lastScreenPos; QRectF rect, sceneRect, screenRect; + QPointF startPos, startScenePos, startScreenPos; + QPointF lastPos, lastScenePos, lastScreenPos; qreal pressure; - - static QTouchEventTouchPointPrivate *get(const QTouchEvent::TouchPoint &tp); }; QT_END_NAMESPACE diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h index 2db015a..141cb4d 100644 --- a/src/testlib/qtesttouch.h +++ b/src/testlib/qtesttouch.h @@ -78,21 +78,21 @@ namespace QTest QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0) { QTouchEvent::TouchPoint &p = point(touchId); - p.setGlobalPos(mapToScreen(widget, pt)); + p.setScreenPos(mapToScreen(widget, pt)); p.setState(Qt::TouchPointPressed); return *this; } QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0) { QTouchEvent::TouchPoint &p = point(touchId); - p.setGlobalPos(mapToScreen(widget, pt)); + p.setScreenPos(mapToScreen(widget, pt)); p.setState(Qt::TouchPointMoved); return *this; } QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0) { QTouchEvent::TouchPoint &p = point(touchId); - p.setGlobalPos(mapToScreen(widget, pt)); + p.setScreenPos(mapToScreen(widget, pt)); p.setState(Qt::TouchPointReleased); return *this; } diff --git a/tests/auto/qtouchevent/tst_qtouchevent.cpp b/tests/auto/qtouchevent/tst_qtouchevent.cpp index ae6e217..336ab33 100644 --- a/tests/auto/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/qtouchevent/tst_qtouchevent.cpp @@ -250,7 +250,7 @@ void tst_QTouchEvent::basicRawEventTranslation() touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); QPointF pos = touchWidget.rect().center(); - QPointF globalPos = touchWidget.mapToGlobal(pos.toPoint()); + QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint()); QPointF delta(10, 10); QTouchEvent::TouchPoint rawTouchPoint; @@ -258,7 +258,7 @@ void tst_QTouchEvent::basicRawEventTranslation() // this should be translated to a TouchBegin rawTouchPoint.setState(Qt::TouchPointPressed); - rawTouchPoint.setGlobalPos(globalPos); + rawTouchPoint.setScreenPos(screenPos); bool res = qt_translateRawTouchEvent(QList() << rawTouchPoint, &touchWidget); QVERIFY(res); QVERIFY(touchWidget.seenTouchBegin); @@ -271,15 +271,16 @@ void tst_QTouchEvent::basicRawEventTranslation() QCOMPARE(touchBeginPoint.pos(), pos); QCOMPARE(touchBeginPoint.startPos(), pos); QCOMPARE(touchBeginPoint.lastPos(), pos); - QCOMPARE(touchBeginPoint.globalPos(), rawTouchPoint.globalPos()); - QCOMPARE(touchBeginPoint.startGlobalPos(), rawTouchPoint.globalPos()); - QCOMPARE(touchBeginPoint.lastGlobalPos(), rawTouchPoint.globalPos()); - QCOMPARE(touchBeginPoint.size(), QSizeF()); + QCOMPARE(touchBeginPoint.screenPos(), rawTouchPoint.screenPos()); + QCOMPARE(touchBeginPoint.startScreenPos(), rawTouchPoint.screenPos()); + QCOMPARE(touchBeginPoint.lastScreenPos(), rawTouchPoint.screenPos()); + QCOMPARE(touchBeginPoint.rect(), QRectF(pos, QSizeF(0, 0))); + QCOMPARE(touchBeginPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); QCOMPARE(touchBeginPoint.pressure(), qreal(-1.)); // moving the point should translate to TouchUpdate rawTouchPoint.setState(Qt::TouchPointMoved); - rawTouchPoint.setGlobalPos(globalPos + delta); + rawTouchPoint.setScreenPos(screenPos + delta); res = qt_translateRawTouchEvent(QList() << rawTouchPoint, &touchWidget); QVERIFY(res); QVERIFY(touchWidget.seenTouchBegin); @@ -292,15 +293,16 @@ void tst_QTouchEvent::basicRawEventTranslation() QCOMPARE(touchUpdatePoint.pos(), pos + delta); QCOMPARE(touchUpdatePoint.startPos(), pos); QCOMPARE(touchUpdatePoint.lastPos(), pos); - QCOMPARE(touchUpdatePoint.globalPos(), rawTouchPoint.globalPos()); - QCOMPARE(touchUpdatePoint.startGlobalPos(), globalPos); - QCOMPARE(touchUpdatePoint.lastGlobalPos(), globalPos); - QCOMPARE(touchUpdatePoint.size(), QSizeF()); + QCOMPARE(touchUpdatePoint.screenPos(), rawTouchPoint.screenPos()); + QCOMPARE(touchUpdatePoint.startScreenPos(), screenPos); + QCOMPARE(touchUpdatePoint.lastScreenPos(), screenPos); + QCOMPARE(touchUpdatePoint.rect(), QRectF(pos + delta, QSizeF(0, 0))); + QCOMPARE(touchUpdatePoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); QCOMPARE(touchUpdatePoint.pressure(), qreal(-1.)); // releasing the point translates to TouchEnd rawTouchPoint.setState(Qt::TouchPointReleased); - rawTouchPoint.setGlobalPos(globalPos + delta + delta); + rawTouchPoint.setScreenPos(screenPos + delta + delta); res = qt_translateRawTouchEvent(QList() << rawTouchPoint, &touchWidget); QVERIFY(res); QVERIFY(touchWidget.seenTouchBegin); @@ -313,10 +315,11 @@ void tst_QTouchEvent::basicRawEventTranslation() QCOMPARE(touchEndPoint.pos(), pos + delta + delta); QCOMPARE(touchEndPoint.startPos(), pos); QCOMPARE(touchEndPoint.lastPos(), pos + delta); - QCOMPARE(touchEndPoint.globalPos(), rawTouchPoint.globalPos()); - QCOMPARE(touchEndPoint.startGlobalPos(), globalPos); - QCOMPARE(touchEndPoint.lastGlobalPos(), globalPos + delta); - QCOMPARE(touchEndPoint.size(), QSizeF()); + QCOMPARE(touchEndPoint.screenPos(), rawTouchPoint.screenPos()); + QCOMPARE(touchEndPoint.startScreenPos(), screenPos); + QCOMPARE(touchEndPoint.lastScreenPos(), screenPos + delta); + QCOMPARE(touchEndPoint.rect(), QRectF(pos + delta + delta, QSizeF(0, 0))); + QCOMPARE(touchEndPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); QCOMPARE(touchEndPoint.pressure(), qreal(-1.)); } -- cgit v0.12