summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-11 12:00:50 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-11 12:00:50 (GMT)
commitecc7f07e612bf156afb7fa2dbcbd2288b9b32e79 (patch)
tree88bbdcb558ef7337d3d3621b3b706f004505c569 /src/gui/graphicsview
parent666299f9074235185aa7372729c84a2639224601 (diff)
downloadQt-ecc7f07e612bf156afb7fa2dbcbd2288b9b32e79.zip
Qt-ecc7f07e612bf156afb7fa2dbcbd2288b9b32e79.tar.gz
Qt-ecc7f07e612bf156afb7fa2dbcbd2288b9b32e79.tar.bz2
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
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp5
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp45
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h10
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.cpp402
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.h83
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp77
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h5
7 files changed, 70 insertions, 557 deletions
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<QGraphicsSceneTouchEvent *>(event));
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ d->touchEventHandler(static_cast<QTouchEvent *>(event));
break;
case QEvent::Timer:
if (d->indexTimerId && static_cast<QTimerEvent *>(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<QGraphicsSceneTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
+ QList<QTouchEvent::TouchPoint> 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<Qt::TouchPointStates, QList<QGraphicsSceneTouchEvent::TouchPoint> > StatesAndTouchPoints;
+ typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
QHash<QGraphicsItem *, StatesAndTouchPoints> 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<QGesture*> &gestures, const QSet<QString> &cancelled);
- QMap<int, QGraphicsSceneTouchEvent::TouchPoint> sceneCurrentTouchPoints;
+ QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
QHash<int, QGraphicsItem *> 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<QGraphicsSceneTouchEvent::TouchPoint> 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::TouchPoint> &QGraphicsSceneTouchEvent::touchPoints() const
-{
- Q_D(const QGraphicsSceneTouchEvent);
- return d->touchPoints;
-}
-
-/*! \internal */
-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.
-
- \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 <QtGui/qevent.h>
+#include <QtCore/qcoreevent.h>
#include <QtCore/qpoint.h>
#include <QtCore/qrect.h>
#include <QtGui/qpolygon.h>
@@ -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<QString> 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<QGraphicsSceneTouchEvent::TouchPoint> &touchPoints() const;
- void setTouchPoints(const QList<QGraphicsSceneTouchEvent::TouchPoint> &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<QTouchEvent::TouchPoint> originalTouchPoints = originalEvent->touchPoints();
- QList<QGraphicsSceneTouchEvent::TouchPoint> 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<QTouchEvent::TouchPoint> 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<QTouchEvent *>(event), &touchEvent);
- touchEvent.setAccepted(false);
- QApplication::sendEvent(d->scene, &touchEvent);
- event->setAccepted(touchEvent.isAccepted());
+ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(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