summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-05 14:49:21 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-05 14:49:21 (GMT)
commit8d8b3e03cfc36c72665494eaa9bb461ff18072a0 (patch)
tree339041f1692b5f0fdef5a1558bd9534980bb2f4b /src/gui/graphicsview
parent12c315f34ca428c3da38716d2c071a8e94f2acf0 (diff)
downloadQt-8d8b3e03cfc36c72665494eaa9bb461ff18072a0.zip
Qt-8d8b3e03cfc36c72665494eaa9bb461ff18072a0.tar.gz
Qt-8d8b3e03cfc36c72665494eaa9bb461ff18072a0.tar.bz2
Some API changes after an API review round
1. Don't have QGraphicsSceneTouchEvent::TouchPoint inherit from QTouchEvent::TouchPoint. The only reason to do this is to support an implementation trick, which can be done another way (see below). This means we have to essentially duplicate the API in the GraphicsScene variant. 2. Don't use a list of pointers to touch points in QTouchEvent and QGraphicsSceneTouchEvent. This means we have to make the TouchPoint classes implicitly shared (and the effect of the previous trick of static_casting the widget touch point to a graphics-scene touch point can be emulated by sharing the d-pointers between the classes). 3. QEvent::RawTouch isn't really an event type, it's a backdoor. Remove it and export the bool qt_translateRawTouchEvent(QList<QTouchEvent::TouchPoint>, QWidget *) function instead. 4. Rename QTouchEvent::TouchPoint::area() to size() (which is more clear as to what the function returns). QGraphicsSceneTouchEvent::TouchPoint gains size(), sceneSize(), and screenSize() functions (the actual translation from screen to scene to item still needs to be implemented).
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp105
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h6
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.cpp249
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.h52
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp38
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h3
6 files changed, 362 insertions, 91 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index bf8d83d..2f6c4e1 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -5687,98 +5687,77 @@ void QGraphicsScenePrivate::releaseGesture(QGraphicsItem *item, int gestureId)
void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item,
QGraphicsSceneTouchEvent *touchEvent)
{
- QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints = touchEvent->touchPoints();
+ QList<QGraphicsSceneTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
for (int i = 0; i < touchPoints.count(); ++i) {
- QGraphicsSceneTouchEvent::TouchPoint *touchPoint = touchPoints.at(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()));
+ QGraphicsSceneTouchEvent::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()));
+#warning FIXME
+ // ### touchPoint.setSize(item->d_ptr->genericMapFromScene(touchPoint.sceneSize(), touchEvent->widget()));
}
+ touchEvent->setTouchPoints(touchPoints);
}
-QGraphicsSceneTouchEvent::TouchPoint *QGraphicsScenePrivate::findClosestTouchPoint(const QPointF &scenePos)
+int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
{
- QGraphicsSceneTouchEvent::TouchPoint *closestTouchPoint = 0;
- qreal closestDistance;
- for (int i = 0; i < sceneCurrentTouchPoints.count(); ++i) {
- QGraphicsSceneTouchEvent::TouchPoint *touchPoint = sceneCurrentTouchPoints.at(i);
- qreal distance = QLineF(scenePos, touchPoint->scenePos()).length();
- if (!closestTouchPoint || distance < closestDistance) {
- closestTouchPoint = touchPoint;
+ int closestTouchPointId = -1;
+ qreal closestDistance = qreal(0.);
+ foreach (const QGraphicsSceneTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) {
+ qreal distance = QLineF(scenePos, touchPoint.scenePos()).length();
+ if (closestTouchPointId == -1|| distance < closestDistance) {
+ closestTouchPointId = touchPoint.id();
closestDistance = distance;
}
}
- return closestTouchPoint;
-}
-
-void QGraphicsScenePrivate::appendTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint)
-{
- // insort touch point (for the app)
- int at = 0;
- for (; at < sceneCurrentTouchPoints.count(); ++at) {
- if (sceneCurrentTouchPoints.at(at)->id() > touchPoint->id())
- break;
- }
- sceneCurrentTouchPoints.insert(at, touchPoint);
-}
-
-void QGraphicsScenePrivate::removeTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint)
-{
- // 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;
- }
- }
+ return closestTouchPointId;
}
void QGraphicsScenePrivate::touchEventHandler(QGraphicsSceneTouchEvent *sceneTouchEvent)
{
- typedef QPair<Qt::TouchPointStates, QList<QGraphicsSceneTouchEvent::TouchPoint *> > StatesAndTouchPoints;
+ typedef QPair<Qt::TouchPointStates, QList<QGraphicsSceneTouchEvent::TouchPoint> > StatesAndTouchPoints;
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents;
for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
- QGraphicsSceneTouchEvent::TouchPoint *touchPoint = sceneTouchEvent->touchPoints().at(i);
+ const QGraphicsSceneTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i);
// update state
QGraphicsItem *item = 0;
- QList<QGraphicsSceneTouchEvent::TouchPoint *> activeTouchPoints;
- if (touchPoint->state() == Qt::TouchPointPressed) {
+ if (touchPoint.state() == Qt::TouchPointPressed) {
// determine which item this event will go to
- cachedItemsUnderMouse = itemsAtPosition(touchPoint->screenPos().toPoint(),
- touchPoint->scenePos(),
+ cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(),
+ touchPoint.scenePos(),
sceneTouchEvent->widget());
item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first();
- QGraphicsSceneTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(touchPoint->scenePos());
- if (closestTouchPoint) {
- QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPoint->id());
- if (!item
- || (closestItem
- && (item->isAncestorOf(closestItem)
- || closestItem->isAncestorOf(item)))) {
- item = closestItem;
- }
+ int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos());
+ QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId);
+ if (!item
+ || (closestItem
+ && (item->isAncestorOf(closestItem)
+ || closestItem->isAncestorOf(item)))) {
+ item = closestItem;
}
if (!item)
continue;
- itemForTouchPointId.insert(touchPoint->id(), item);
- appendTouchPoint(touchPoint);
- } else if (touchPoint->state() == Qt::TouchPointReleased) {
- item = itemForTouchPointId.take(touchPoint->id());
+ itemForTouchPointId.insert(touchPoint.id(), item);
+ sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
+ } else if (touchPoint.state() == Qt::TouchPointReleased) {
+ item = itemForTouchPointId.take(touchPoint.id());
if (!item)
continue;
- removeTouchPoint(touchPoint);
+ sceneCurrentTouchPoints.remove(touchPoint.id());
} else {
- item = itemForTouchPointId.value(touchPoint->id());
+ item = itemForTouchPointId.value(touchPoint.id());
if (!item)
continue;
+ Q_ASSERT(sceneCurrentTouchPoints.contains(touchPoint.id()));
+ sceneCurrentTouchPoints[touchPoint.id()] = touchPoint;
}
StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item];
- statesAndTouchPoints.first |= touchPoint->state();
+ statesAndTouchPoints.first |= touchPoint.state();
statesAndTouchPoints.second.append(touchPoint);
}
@@ -5847,9 +5826,9 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QGraphics
Q_Q(QGraphicsScene);
if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) {
- QGraphicsSceneTouchEvent::TouchPoint *firstTouchPoint = touchEvent->touchPoints().first();
- cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint->screenPos().toPoint(),
- firstTouchPoint->scenePos(),
+ const QGraphicsSceneTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
+ cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(),
+ firstTouchPoint.scenePos(),
touchEvent->widget());
}
Q_ASSERT(cachedItemsUnderMouse.first() == origin);
@@ -5885,8 +5864,8 @@ 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) {
- QGraphicsSceneTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().at(i);
- itemForTouchPointId[touchPoint->id()] = item;
+ const QGraphicsSceneTouchEvent::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 4af35a0..f90bb8f 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -279,12 +279,10 @@ public:
mutable QBitArray validTransforms;
mutable QVector<int> freeSceneTransformSlots;
- QList<QGraphicsSceneTouchEvent::TouchPoint *> sceneCurrentTouchPoints;
+ QMap<int, QGraphicsSceneTouchEvent::TouchPoint> sceneCurrentTouchPoints;
QHash<int, QGraphicsItem *> itemForTouchPointId;
static void updateTouchPointsForItem(QGraphicsItem *item, QGraphicsSceneTouchEvent *touchEvent);
- QGraphicsSceneTouchEvent::TouchPoint *findClosestTouchPoint(const QPointF &scenePos);
- void appendTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint);
- void removeTouchPoint(QGraphicsSceneTouchEvent::TouchPoint *touchPoint);
+ int findClosestTouchPointId(const QPointF &scenePos);
void touchEventHandler(QGraphicsSceneTouchEvent *touchEvent);
bool sendTouchBeginEvent(QGraphicsItem *item, QGraphicsSceneTouchEvent *touchEvent);
};
diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp
index 0104e9c..c1052e3 100644
--- a/src/gui/graphicsview/qgraphicssceneevent.cpp
+++ b/src/gui/graphicsview/qgraphicssceneevent.cpp
@@ -1962,7 +1962,7 @@ public:
Qt::KeyboardModifiers modifiers;
Qt::TouchPointStates touchPointStates;
- QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints;
+ QList<QGraphicsSceneTouchEvent::TouchPoint> touchPoints;
};
/*!
@@ -2019,19 +2019,132 @@ void QGraphicsSceneTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPoi
\sa QGraphicsSceneTouchEvent::TouchPoint
*/
-const QList<QGraphicsSceneTouchEvent::TouchPoint *> &QGraphicsSceneTouchEvent::touchPoints() const
+const QList<QGraphicsSceneTouchEvent::TouchPoint> &QGraphicsSceneTouchEvent::touchPoints() const
{
Q_D(const QGraphicsSceneTouchEvent);
return d->touchPoints;
}
/*! \internal */
-void QGraphicsSceneTouchEvent::setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint *> &touchPoints)
+void QGraphicsSceneTouchEvent::setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint> &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.
@@ -2045,6 +2158,8 @@ QPointF QGraphicsSceneTouchEvent::TouchPoint::scenePos() const
/*! \internal */
void QGraphicsSceneTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
{
+ if (d->ref != 1)
+ d = d->detach();
d->scenePos = scenePos;
}
@@ -2061,6 +2176,8 @@ QPointF QGraphicsSceneTouchEvent::TouchPoint::startScenePos() const
/*! \internal */
void QGraphicsSceneTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
{
+ if (d->ref != 1)
+ d = d->detach();
d->startScenePos = startScenePos;
}
@@ -2077,9 +2194,135 @@ QPointF QGraphicsSceneTouchEvent::TouchPoint::lastScenePos() const
/*! \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 size of this touch point.
+*/
+QSizeF QGraphicsSceneTouchEvent::TouchPoint::size() const
+{
+ return d->size;
+}
+
+/*! \internal */
+void QGraphicsSceneTouchEvent::TouchPoint::setSize(const QSizeF &size)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->size = size;
+}
+
+/*!
+ Returns the size of this touch point in scene coordinates.
+*/
+QSizeF QGraphicsSceneTouchEvent::TouchPoint::sceneSize() const
+{
+ return d->sceneSize;
+}
+
+/*! \internal */
+void QGraphicsSceneTouchEvent::TouchPoint::setSceneSize(const QSizeF &sceneSize)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->sceneSize = sceneSize;
+}
+
+/*!
+ Returns the size of this touch point in screen coordinates.
+*/
+QSizeF QGraphicsSceneTouchEvent::TouchPoint::screenSize() const
+{
+ return d->screenSize;
+}
+
+/*! \internal */
+void QGraphicsSceneTouchEvent::TouchPoint::setScreenSize(const QSizeF &screenSize)
+{
+ if (d->ref != 1)
+ d = d->detach();
+ d->screenSize = screenSize;
+}
+
+/*!
+ 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 9fcda2f..3c53f36 100644
--- a/src/gui/graphicsview/qgraphicssceneevent.h
+++ b/src/gui/graphicsview/qgraphicssceneevent.h
@@ -353,9 +353,28 @@ class QGraphicsSceneTouchEventPrivate;
class Q_GUI_EXPORT QGraphicsSceneTouchEvent : public QGraphicsSceneEvent
{
public:
- class Q_GUI_EXPORT TouchPoint : public QTouchEvent::TouchPoint
+ 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);
@@ -365,8 +384,33 @@ public:
QPointF lastScenePos() const;
void setLastScenePos(const QPointF &lastScenePos);
- qreal pressure() const; // 0.0 -> 1.0
+ QPointF screenPos() const;
+ void setScreenPos(const QPointF &screenPos);
+
+ QPointF startScreenPos() const;
+ void setStartScreenPos(const QPointF &startScreenPos);
+
+ QPointF lastScreenPos() const;
+ void setLastScreenPos(const QPointF &lastScreenPos);
+
+ QSizeF size() const;
+ void setSize(const QSizeF &size);
+
+ QSizeF sceneSize() const;
+ void setSceneSize(const QSizeF &sceneSize);
+
+ QSizeF screenSize() const;
+ void setScreenSize(const QSizeF &screenSize);
+
+ 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);
@@ -378,8 +422,8 @@ public:
Qt::TouchPointStates touchPointStates() const;
void setTouchPointStates(Qt::TouchPointStates touchPointStates);
- const QList<QGraphicsSceneTouchEvent::TouchPoint *> &touchPoints() const;
- void setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint *> &touchPoints);
+ const QList<QGraphicsSceneTouchEvent::TouchPoint> &touchPoints() const;
+ void setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint> &touchPoints);
private:
Q_DECLARE_PRIVATE(QGraphicsSceneTouchEvent);
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index c50b4a1..da1837c 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -284,6 +284,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
#include <private/qt_x11_p.h>
#endif
+#include <private/qevent_p.h>
+
QT_BEGIN_NAMESPACE
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);
@@ -297,22 +299,26 @@ 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)
+void QGraphicsViewPrivate::convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d,
+ QTouchEvent *originalEvent,
+ QGraphicsSceneTouchEvent *touchEvent)
{
- QList<QTouchEvent::TouchPoint *> originalTouchPoints = originalEvent->touchPoints();
- QList<QGraphicsSceneTouchEvent::TouchPoint *> touchPoints;
+ 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->lastPos()));
- // lastScreenPos is already set in the originalTouchPoint
+ 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()));
+ touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos()));
+ touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos()));
+#warning FIXME
+ // ### touchPoint.setSceneSize(d->mapToScene(touchPoint.screenSize()));
+
+ // screenPos, startScreenPos, lastScreenPos, and screenSize are already set from the
+ // originalTouchPoint
touchPoints.append(touchPoint);
}
@@ -2892,9 +2898,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
}
QGraphicsSceneTouchEvent touchEvent(eventType);
touchEvent.setWidget(viewport());
- qt_convertTouchEventToGraphicsSceneTouchEvent(d,
- static_cast<QTouchEvent *>(event),
- &touchEvent);
+ QGraphicsViewPrivate::convertTouchEventToGraphicsSceneTouchEvent(d, static_cast<QTouchEvent *>(event), &touchEvent);
touchEvent.setAccepted(false);
QApplication::sendEvent(d->scene, &touchEvent);
event->setAccepted(touchEvent.isAccepted());
diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h
index 779b638..da1ca14 100644
--- a/src/gui/graphicsview/qgraphicsview_p.h
+++ b/src/gui/graphicsview/qgraphicsview_p.h
@@ -183,6 +183,9 @@ public:
const QRegion &exposedRegion) const;
QPointF mapToScene(const QPointF &point) const;
+ static void convertTouchEventToGraphicsSceneTouchEvent(QGraphicsViewPrivate *d,
+ QTouchEvent *originalEvent,
+ QGraphicsSceneTouchEvent *touchEvent);
};
QT_END_NAMESPACE