From 841b10d10943d912fe75674045a740cff29e266c Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 16 Mar 2009 16:31:05 +0100 Subject: Removed QWidget::gestureEvent() functions since adding a new virtual function breaks binary compatibility. --- examples/gestures/imageviewer/imagewidget.cpp | 9 ++++ examples/gestures/imageviewer/imagewidget.h | 1 + src/gui/graphicsview/qgraphicsscene.cpp | 68 +++++++++++++-------------- src/gui/graphicsview/qgraphicsscene.h | 1 - src/gui/kernel/qwidget.cpp | 7 +-- src/gui/kernel/qwidget.h | 2 - 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp index 0a279ca..b3c92bc 100644 --- a/examples/gestures/imageviewer/imagewidget.cpp +++ b/examples/gestures/imageviewer/imagewidget.cpp @@ -131,6 +131,15 @@ void ImageWidget::paintEvent(QPaintEvent*) p.restore(); } +bool ImageWidget::event(QEvent *event) +{ + if (event->type() == QEvent::Gesture) { + gestureEvent(static_cast(event)); + return true; + } + return QWidget::event(event); +} + void ImageWidget::gestureEvent(QGestureEvent *event) { touchFeedback.doubleTapped = false; diff --git a/examples/gestures/imageviewer/imagewidget.h b/examples/gestures/imageviewer/imagewidget.h index 56fcb40..3f3ff96 100644 --- a/examples/gestures/imageviewer/imagewidget.h +++ b/examples/gestures/imageviewer/imagewidget.h @@ -56,6 +56,7 @@ public: void openDirectory(const QString &path); protected: + bool event(QEvent *event); void paintEvent(QPaintEvent*); void gestureEvent(QGestureEvent *event); void resizeEvent(QResizeEvent*); diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 0f70cfe..337b6ee 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3951,8 +3951,38 @@ bool QGraphicsScene::event(QEvent *event) // geometries that do not have an explicit style set. update(); break; - case QEvent::GraphicsSceneGesture: - gestureEvent(static_cast(event)); + case QEvent::GraphicsSceneGesture: { + QGraphicsSceneGestureEvent *ev = static_cast(event); + QList gestureTypes = ev->gestureTypes(); + QGraphicsView *view = qobject_cast(ev->widget()); + if (!view) { + qWarning("QGraphicsScene::event: gesture event was received without a view"); + break; + } + + // find graphics items that intersects with gestures hot spots. + QPolygonF poly; + QMap sceneHotSpots; + foreach(const QString &type, gestureTypes) { + QPointF pt = ev->mapToScene(ev->gesture(type)->hotSpot()); + sceneHotSpots.insert(qHash(type), pt); + poly << pt; + } + QList itemsInGestureArea = items(poly, Qt::IntersectsItemBoundingRect); + + foreach(QGraphicsItem *item, itemsInGestureArea) { + QMap::const_iterator it = sceneHotSpots.begin(), + e = sceneHotSpots.end(); + for(; it != e; ++it) { + if (item->contains(item->mapFromScene(it.value())) && + item->d_ptr->gestures.contains(it.key())) { + d->sendEvent(item, ev); + if (ev->isAccepted()) + break; + } + } + } + } break; case QEvent::GraphicsSceneTouchBegin: d->touchBeginEvent(static_cast(event)); @@ -5604,40 +5634,6 @@ void QGraphicsScenePrivate::removeView(QGraphicsView *view) view->releaseGesture(gestureId); } -void QGraphicsScene::gestureEvent(QGraphicsSceneGestureEvent *event) -{ - Q_D(QGraphicsScene); - QList gestureTypes = event->gestureTypes(); - QGraphicsView *view = qobject_cast(event->widget()); - if (!view) { - qWarning("QGraphicsScene::gestureEvent: gesture event was received without a view"); - return; - } - - // find graphics items that intersects with gestures hot spots. - QPolygonF poly; - QMap sceneHotSpots; - foreach(const QString &type, gestureTypes) { - QPointF pt = event->mapToScene(event->gesture(type)->hotSpot()); - sceneHotSpots.insert(qHash(type), pt); - poly << pt; - } - QList itemsInGestureArea = items(poly, Qt::IntersectsItemBoundingRect); - - foreach(QGraphicsItem *item, itemsInGestureArea) { - QMap::const_iterator it = sceneHotSpots.begin(), - e = sceneHotSpots.end(); - for(; it != e; ++it) { - if (item->contains(item->mapFromScene(it.value())) && - item->d_ptr->gestures.contains(it.key())) { - d->sendEvent(item, event); - if (event->isAccepted()) - break; - } - } - } -} - void QGraphicsScenePrivate::grabGesture(QGraphicsItem *item, int gestureId) { if (!grabbedGestures.contains(gestureId)) { diff --git a/src/gui/graphicsview/qgraphicsscene.h b/src/gui/graphicsview/qgraphicsscene.h index 45def44..a76b348 100644 --- a/src/gui/graphicsview/qgraphicsscene.h +++ b/src/gui/graphicsview/qgraphicsscene.h @@ -256,7 +256,6 @@ protected: virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void inputMethodEvent(QInputMethodEvent *event); - virtual void gestureEvent(QGraphicsSceneGestureEvent *event); virtual void drawBackground(QPainter *painter, const QRectF &rect); virtual void drawForeground(QPainter *painter, const QRectF &rect); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 9c0c404..0029809 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -7931,7 +7931,7 @@ bool QWidget::event(QEvent *event) break; #endif case QEvent::Gesture: - gestureEvent((QGestureEvent*)event); + event->ignore(); break; #ifndef QT_NO_PROPERTIES case QEvent::DynamicPropertyChange: { @@ -8738,11 +8738,6 @@ bool QWidget::qwsEvent(QWSEvent *) #endif -void QWidget::gestureEvent(QGestureEvent *event) -{ - event->ignore(); -} - /*! Ensures that the widget has been polished by QStyle (i.e., has a diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 6324782..80d4f3e 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -677,8 +677,6 @@ protected: // Misc. protected functions virtual void changeEvent(QEvent *); - virtual void gestureEvent(QGestureEvent *); - int metric(PaintDeviceMetric) const; virtual void inputMethodEvent(QInputMethodEvent *); -- cgit v0.12