summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qcoreevent.h20
-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
-rw-r--r--src/gui/kernel/qapplication.cpp127
-rw-r--r--src/gui/kernel/qapplication_p.h11
-rw-r--r--src/gui/kernel/qevent.cpp116
-rw-r--r--src/gui/kernel/qevent.h35
-rw-r--r--src/gui/kernel/qevent_p.h15
12 files changed, 550 insertions, 227 deletions
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index 3381a31..feefd08 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -272,17 +272,15 @@ public:
Signal = 192,
Wrapped = 193,
- RawTouch = 194,
-
- TouchBegin = 195,
- TouchUpdate = 196,
- TouchEnd = 197,
- GraphicsSceneTouchBegin = 198,
- GraphicsSceneTouchUpdate = 199,
- GraphicsSceneTouchEnd = 200,
-
- Gesture = 201,
- GraphicsSceneGesture = 202,
+ TouchBegin = 194,
+ TouchUpdate = 195,
+ TouchEnd = 196,
+ GraphicsSceneTouchBegin = 197,
+ GraphicsSceneTouchUpdate = 198,
+ GraphicsSceneTouchEnd = 199,
+
+ Gesture = 200,
+ GraphicsSceneGesture = 201,
// 512 reserved for Qt Jambi's MetaCall event
// 513 reserved for Qt Jambi's DeleteOnMainThread event
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
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index ca0054f..00399fc 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -3587,19 +3587,22 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
QApplicationPrivate::mouse_buttons |= me->button();
else
QApplicationPrivate::mouse_buttons &= ~me->button();
- } else if (e->type() == QEvent::RawTouch
+ }
+#if !defined(QT_NO_WHEELEVENT) || !defined(QT_NO_TABLETEVENT)
+ else if (false
# ifndef QT_NO_WHEELEVENT
- || e->type() == QEvent::Wheel
+ || e->type() == QEvent::Wheel
# endif
# ifndef QT_NO_TABLETEVENT
- || e->type() == QEvent::TabletMove
- || e->type() == QEvent::TabletPress
- || e->type() == QEvent::TabletRelease
+ || e->type() == QEvent::TabletMove
+ || e->type() == QEvent::TabletPress
+ || e->type() == QEvent::TabletRelease
# endif
- ) {
+ ) {
QInputEvent *ie = static_cast<QInputEvent*>(e);
QApplicationPrivate::modifier_buttons = ie->modifiers();
}
+#endif // !QT_NO_WHEELEVENT || !QT_NO_TABLETEVENT
}
if (!d->grabbedGestures.isEmpty() && e->spontaneous() && receiver->isWidgetType()) {
@@ -3633,10 +3636,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
}
bool res = false;
- if (e->type() == QEvent::RawTouch) {
- res = d->translateRawTouchEvent(qobject_cast<QWidget *>(receiver),
- static_cast<QTouchEvent *>(e));
- } else if (!receiver->isWidgetType()) {
+ if (!receiver->isWidgetType()) {
res = d->notify_helper(receiver, e);
} else switch (e->type()) {
#if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT)
@@ -4060,8 +4060,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (res && eventAccepted) {
// the first widget to accept the TouchBegin gets an implicit grab.
for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
- QTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().at(i);
- d->widgetForTouchPointId[touchPoint->id()] = widget;
+ const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
+ d->widgetForTouchPointId[touchPoint.id()] = widget;
}
break;
} else if (widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) {
@@ -5255,13 +5255,13 @@ int QApplication::eventDeliveryDelayForGestures()
void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent)
{
for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
- QTouchEvent::TouchPoint *touchPoint = touchEvent->touchPoints().at(i);
+ QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i];
// preserve the sub-pixel resolution
- const QPointF delta = touchPoint->screenPos() - touchPoint->screenPos().toPoint();
- touchPoint->setPos(widget->mapFromGlobal(touchPoint->screenPos().toPoint()) + delta);
- touchPoint->setStartPos(widget->mapFromGlobal(touchPoint->startScreenPos().toPoint()) + delta);
- touchPoint->setLastPos(widget->mapFromGlobal(touchPoint->lastScreenPos().toPoint()) + delta);
+ 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);
}
}
@@ -5281,97 +5281,75 @@ void QApplicationPrivate::cleanupMultitouch()
appCurrentTouchPoints.clear();
}
-QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QPointF &screenPos)
+int QApplicationPrivate::findClosestTouchPointId(const QPointF &globalPos)
{
- QTouchEvent::TouchPoint *closestTouchPoint = 0;
- qreal closestDistance;
- for (int i = 0; i < appCurrentTouchPoints.count(); ++i) {
- QTouchEvent::TouchPoint *touchPoint = appCurrentTouchPoints.at(i);
- qreal distance = QLineF(screenPos, touchPoint->screenPos()).length();
- if (!closestTouchPoint || distance < closestDistance) {
- closestTouchPoint = touchPoint;
+ int closestTouchPointId = -1;
+ qreal closestDistance = qreal(0.);
+ foreach (const QTouchEvent::TouchPoint &touchPoint, appCurrentTouchPoints) {
+ qreal distance = QLineF(globalPos, touchPoint.globalPos()).length();
+ if (closestTouchPointId == -1 || distance < closestDistance) {
+ closestTouchPointId = touchPoint.id();
closestDistance = distance;
}
}
- return closestTouchPoint;
+ return closestTouchPointId;
}
-void QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touchPoint)
+bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
+ const QList<QTouchEvent::TouchPoint> &touchPoints)
{
- // insort touch point
- int at = 0;
- for (; at < appCurrentTouchPoints.count(); ++at) {
- if (appCurrentTouchPoints.at(at)->id() > touchPoint->id())
- break;
- }
- appCurrentTouchPoints.insert(at, touchPoint);
-}
+ QApplicationPrivate *d = self;
+ QApplication *q = self->q_func();
-void QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touchPoint)
-{
- // remove touch point from all known touch points
- for (int i = qMin(appCurrentTouchPoints.count() - 1, touchPoint->id()); i >= 0; --i) {
- if (appCurrentTouchPoints.at(i) == touchPoint) {
- appCurrentTouchPoints.removeAt(i);
- break;
- }
- }
-}
-
-bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, QTouchEvent *rawTouchEvent)
-{
- Q_Q(QApplication);
-
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint *> > StatesAndTouchPoints;
+ typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
- for (int i = 0; i < rawTouchEvent->touchPoints().count(); ++i) {
- QTouchEvent::TouchPoint *touchPoint = rawTouchEvent->touchPoints().at(i);
+ for (int i = 0; i < touchPoints.count(); ++i) {
+ const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
// update state
QWidget *widget = 0;
- switch (touchPoint->state()) {
+ switch (touchPoint.state()) {
case Qt::TouchPointPressed:
{
// determine which widget this event will go to
if (!window)
- window = q->topLevelAt(touchPoint->screenPos().toPoint());
+ window = q->topLevelAt(touchPoint.globalPos().toPoint());
if (!window)
continue;
- widget = window->childAt(window->mapFromGlobal(touchPoint->screenPos().toPoint()));
+ widget = window->childAt(window->mapFromGlobal(touchPoint.globalPos().toPoint()));
if (!widget)
widget = window;
- QTouchEvent::TouchPoint *closestTouchPoint = findClosestTouchPoint(touchPoint->screenPos());
- if (closestTouchPoint) {
- QWidget *closestWidget = widgetForTouchPointId.value(closestTouchPoint->id());
- if (closestWidget
- && (widget->isAncestorOf(closestWidget)
- || closestWidget->isAncestorOf(widget)))
- widget = closestWidget;
+ int closestTouchPointId = d->findClosestTouchPointId(touchPoint.globalPos());
+ QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId);
+ if (closestWidget
+ && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
+ widget = closestWidget;
}
- widgetForTouchPointId[touchPoint->id()] = widget;
-
- appendTouchPoint(touchPoint);
+ d->widgetForTouchPointId[touchPoint.id()] = widget;
+ d->appCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
break;
}
case Qt::TouchPointReleased:
- widget = widgetForTouchPointId.take(touchPoint->id());
+ widget = d->widgetForTouchPointId.take(touchPoint.id());
if (!widget)
continue;
- removeTouchPoint(touchPoint);
+ d->appCurrentTouchPoints.remove(touchPoint.id());
break;
default:
- widget = widgetForTouchPointId.value(touchPoint->id());
+ widget = d->widgetForTouchPointId.value(touchPoint.id());
if (!widget)
continue;
+ Q_ASSERT(d->appCurrentTouchPoints.contains(touchPoint.id()));
+ d->appCurrentTouchPoints[touchPoint.id()] = touchPoint;
break;
}
Q_ASSERT(widget != 0);
StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[widget];
- maskAndPoints.first |= touchPoint->state();
+ maskAndPoints.first |= touchPoint.state();
maskAndPoints.second.append(touchPoint);
}
@@ -5404,7 +5382,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, QTouchEvent *r
}
QTouchEvent touchEvent(eventType,
- rawTouchEvent->modifiers(),
+ q->keyboardModifiers(),
it.value().first,
it.value().second);
updateTouchPointsForWidget(widget, &touchEvent);
@@ -5430,10 +5408,15 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, QTouchEvent *r
returnValue = returnValue || res;
}
- rawTouchEvent->setAccepted(returnValue);
return returnValue;
}
+Q_GUI_EXPORT bool qt_translateRawTouchEvent(const QList<QTouchEvent::TouchPoint> &touchPoints,
+ QWidget *window)
+{
+ return QApplicationPrivate::translateRawTouchEvent(window, touchPoints);
+}
+
QT_END_NAMESPACE
#include "moc_qapplication.cpp"
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index 55d8fc4..d34d4fe 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -435,16 +435,17 @@ public:
QMap<QString, int> grabbedGestures;
QHash<int, QWidget *> widgetForTouchPointId;
- QList<QTouchEvent::TouchPoint *> appCurrentTouchPoints;
+ QMap<int, QTouchEvent::TouchPoint> appCurrentTouchPoints;
static void updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
void initializeMultitouch();
void initializeMultitouch_sys();
void cleanupMultitouch();
void cleanupMultitouch_sys();
- QTouchEvent::TouchPoint *findClosestTouchPoint(const QPointF &screenPos);
- void appendTouchPoint(QTouchEvent::TouchPoint *touchPoint);
- void removeTouchPoint(QTouchEvent::TouchPoint *touchPoint);
- bool translateRawTouchEvent(QWidget *widget, QTouchEvent *rawTouchEvent);
+ int findClosestTouchPointId(const QPointF &screenPos);
+ void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
+ void removeTouchPoint(int touchPointId);
+ static bool translateRawTouchEvent(QWidget *widget,
+ const QList<QTouchEvent::TouchPoint> &touchPoints);
#if defined(Q_WS_WIN)
static qt_RegisterTouchWindowPtr RegisterTouchWindow;
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 2692e82..5b3c0fe 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3679,24 +3679,28 @@ void QGestureEvent::accept(const QString &type)
track-pad), and if the widget has the Qt::WA_AcceptTouchEvents
attribute.
- Like QMouseEvent, Qt automatically grabs the touch device on the
- first press inside a widget; the widget will receive all touch
- events until the last touch point is released.
+ All touch events are of type QEvent::TouchBegin,
+ QEvent::TouchUpdate, or QEvent::TouchEnd. The touchPoints()
+ function returns a list of all touch points contained in the event.
+ Information about each touch point can be retreived using the
+ QTouchEvent::TouchPoint class.
+
+ Similar to QMouseEvent, Qt automatically grabs each touch point on
+ the first press inside a widget; the widget will receive all
+ updates for the touch point until it is released. Note that it is
+ possible for a widget to receive events for multiple touch points,
+ and that multiple widgets may be receiving touch events at the same
+ time.
A touch event contains a special accept flag that indicates
whether the receiver wants the event. By default, the event is
- ignored. You should call accept() if the touch event is handled by
- your widget. A touch event is propagated up the parent widget
+ accepted. You should call ignore() if the touch event is not handled by
+ your widget. A QEvent::TouchBegin event is propagated up the parent widget
chain until a widget accepts it with accept(), or an event filter
- consumes it. If the touch event is neither accepted nor consumed,
+ consumes it. If the QEvent::TouchBegin event is neither accepted nor consumed,
then mouse events are simulated from the state of the first touch
point.
- All touch events are of type QEvent::Touch. The touchPoints()
- function returns a list of all touch points contained in the
- event. Information about each touch point can be retreived using
- the QTouchEvent::TouchPoint class.
-
The Qt::TouchPointState enum describes the different states that a
touch point may have.
@@ -3728,7 +3732,7 @@ void QGestureEvent::accept(const QString &type)
QTouchEvent::QTouchEvent(QEvent::Type type,
Qt::KeyboardModifiers modifiers,
Qt::TouchPointStates touchPointStates,
- const QList<QTouchEvent::TouchPoint *> &touchPoints)
+ const QList<QTouchEvent::TouchPoint> &touchPoints)
: QInputEvent(type, modifiers),
_touchPointStates(touchPointStates),
_touchPoints(touchPoints)
@@ -3752,12 +3756,12 @@ QTouchEvent::~QTouchEvent()
Sets a bitwise OR of all the touch point states for this event.
*/
-/*! \fn const QList<QTouchEvent::TouchPoint *> &QTouchEvent::TouchPoints() const
+/*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::TouchPoints() const
Returns the list of touch points contained in the touch event.
*/
-/*! \fn void QTouchEvent::setTouchPoints(QList<QTouchEvent::TouchPoint *> &touchPoints)
+/*! \fn void QTouchEvent::setTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints)
\internal
@@ -3774,17 +3778,30 @@ QTouchEvent::TouchPoint::TouchPoint(int id)
/*! \internal
+ Constructs a copy of \a other.
+*/
+QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
+ : d(other.d)
+{
+ d->ref.ref();
+}
+
+/*! \internal
+
Destroys the QTouchEvent::TouchPoint.
*/
QTouchEvent::TouchPoint::~TouchPoint()
{
- delete d;
+ if (!d->ref.deref())
+ delete d;
}
/*!
- Returns the id number of this touch point. Id numbers are
- sequential, starting at zero, meaning the first touch point has id
- 0, the second has id 1, and so on...
+ 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 QTouchEvent::TouchPoint::id() const
{
@@ -3794,6 +3811,8 @@ int QTouchEvent::TouchPoint::id() const
/*! \internal */
void QTouchEvent::TouchPoint::setId(int id)
{
+ if (d->ref != 1)
+ d = d->detach();
d->id = id;
}
@@ -3808,6 +3827,8 @@ Qt::TouchPointState QTouchEvent::TouchPoint::state() const
/*! \internal */
void QTouchEvent::TouchPoint::setState(Qt::TouchPointState state)
{
+ if (d->ref != 1)
+ d = d->detach();
d->state = state;
}
@@ -3823,6 +3844,8 @@ QPointF QTouchEvent::TouchPoint::pos() const
/*! \internal */
void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
{
+ if (d->ref != 1)
+ d = d->detach();
d->pos = pos;
}
@@ -3838,6 +3861,8 @@ QPointF QTouchEvent::TouchPoint::startPos() const
/*! \internal */
void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
{
+ if (d->ref != 1)
+ d = d->detach();
d->startPos = startPos;
}
@@ -3853,64 +3878,74 @@ QPointF QTouchEvent::TouchPoint::lastPos() const
/*! \internal */
void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
{
+ if (d->ref != 1)
+ d = d->detach();
d->lastPos = lastPos;
}
/*!
Returns the screen position of this touch point.
*/
-QPointF QTouchEvent::TouchPoint::screenPos() const
+QPointF QTouchEvent::TouchPoint::globalPos() const
{
return d->screenPos;
}
/*! \internal */
-void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
+void QTouchEvent::TouchPoint::setGlobalPos(const QPointF &globalPos)
{
- d->screenPos = screenPos;
+ if (d->ref != 1)
+ d = d->detach();
+ d->screenPos = globalPos;
}
/*!
Returns the starting screen position of this touch point.
*/
-QPointF QTouchEvent::TouchPoint::startScreenPos() const
+QPointF QTouchEvent::TouchPoint::startGlobalPos() const
{
return d->startScreenPos;
}
/*! \internal */
-void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
+void QTouchEvent::TouchPoint::setStartGlobalPos(const QPointF &startGlobalPos)
{
- d->startScreenPos = startScreenPos;
+ if (d->ref != 1)
+ d = d->detach();
+ d->startScreenPos = startGlobalPos;
}
/*!
Returns the screen position of this touch point from the previous
touch event.
*/
-QPointF QTouchEvent::TouchPoint::lastScreenPos() const
+QPointF QTouchEvent::TouchPoint::lastGlobalPos() const
{
return d->lastScreenPos;
}
/*! \internal */
-void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
+void QTouchEvent::TouchPoint::setLastGlobalPos(const QPointF &lastGlobalPos)
{
- d->lastScreenPos = lastScreenPos;
+ if (d->ref != 1)
+ d = d->detach();
+ d->lastScreenPos = lastGlobalPos;
}
/*!
- Returns the area of this touch point.
+ Returns the size of this touch point.
*/
-QSizeF QTouchEvent::TouchPoint::area() const
+QSizeF QTouchEvent::TouchPoint::size() const
{
- return d->area;
+ return d->screenSize;
}
/*! \internal */
-void QTouchEvent::TouchPoint::setArea(const QSizeF &area)
+void QTouchEvent::TouchPoint::setSize(const QSizeF &size)
{
- d->area = area;
+ if (d->ref != 1)
+ d = d->detach();
+ d->screenSize = size;
}
/*!
@@ -3925,7 +3960,24 @@ qreal QTouchEvent::TouchPoint::pressure() const
/*! \internal */
void QTouchEvent::TouchPoint::setPressure(qreal pressure)
{
+ if (d->ref != 1)
+ d = d->detach();
d->pressure = pressure;
}
+/*! \internal */
+QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
+{
+ other.d->ref.ref();
+ if (!d->ref.deref())
+ delete d;
+ d = other.d;
+ 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 f622126..0c4bbb7 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -765,6 +765,7 @@ public:
{
public:
TouchPoint(int id = -1);
+ TouchPoint(const TouchPoint &other);
~TouchPoint();
int id() const;
@@ -782,29 +783,33 @@ public:
QPointF lastPos() const;
void setLastPos(const QPointF &lastPos);
- QPointF screenPos() const;
- void setScreenPos(const QPointF &screenPos);
+ QPointF globalPos() const;
+ void setGlobalPos(const QPointF &globalPos);
- QPointF startScreenPos() const;
- void setStartScreenPos(const QPointF &startScreenPos);
+ QPointF startGlobalPos() const;
+ void setStartGlobalPos(const QPointF &startGlobalPos);
- QPointF lastScreenPos() const;
- void setLastScreenPos(const QPointF &lastScreenPos);
+ QPointF lastGlobalPos() const;
+ void setLastGlobalPos(const QPointF &lastGlobalPos);
- QSizeF area() const;
- void setArea(const QSizeF &area);
+ QSizeF size() const;
+ void setSize(const QSizeF &size);
- qreal pressure() const; // 0.0 -> 1.0
+ qreal pressure() const;
void setPressure(qreal pressure);
- protected:
+ TouchPoint &operator=(const TouchPoint &other);
+
+ private:
QTouchEventTouchPointPrivate *d;
+
+ friend class QTouchEventTouchPointPrivate;
};
QTouchEvent(QEvent::Type type,
Qt::KeyboardModifiers modifiers,
Qt::TouchPointStates touchPointStates,
- const QList<QTouchEvent::TouchPoint *> &touchPoints);
+ const QList<QTouchEvent::TouchPoint> &touchPoints);
~QTouchEvent();
inline Qt::TouchPointStates touchPointStates() const
@@ -816,18 +821,20 @@ public:
_touchPointStates = touchPointStates;
}
- inline const QList<QTouchEvent::TouchPoint *> &touchPoints() const
+ inline const QList<QTouchEvent::TouchPoint> &touchPoints() const
{
return _touchPoints;
}
- inline void setTouchPoints(const QList<QTouchEvent::TouchPoint *> &touchPoints)
+ inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
{
_touchPoints = touchPoints;
}
protected:
Qt::TouchPointStates _touchPointStates;
- QList<QTouchEvent::TouchPoint *> _touchPoints;
+ QList<QTouchEvent::TouchPoint> _touchPoints;
+
+ friend class QApplicationPrivate;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index 37a0ee7..573fdc8 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -93,18 +93,29 @@ class QTouchEventTouchPointPrivate
{
public:
inline QTouchEventTouchPointPrivate(int id)
- : id(id),
+ : ref(1),
+ id(id),
state(Qt::TouchPointReleased),
pressure(qreal(-1.))
{ }
+ inline QTouchEventTouchPointPrivate *detach()
+ {
+ QTouchEventTouchPointPrivate *d = new QTouchEventTouchPointPrivate(*this);
+ d->ref = 1;
+ return d;
+ }
+
+ QAtomicInt ref;
int id;
Qt::TouchPointState state;
QPointF pos, startPos, lastPos;
QPointF scenePos, startScenePos, lastScenePos;
QPointF screenPos, startScreenPos, lastScreenPos;
- QSizeF area;
+ QSizeF size, sceneSize, screenSize;
qreal pressure;
+
+ static QTouchEventTouchPointPrivate *get(const QTouchEvent::TouchPoint &tp);
};
QT_END_NAMESPACE