diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-11-30 18:51:00 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-09 16:36:00 +0100 |
commit | 4471e45f74a74827464774480306c1fbd70a5d7e (patch) | |
tree | df41701cbb5bae1b6776bc79d6ebbc414fe54d75 | |
parent | 5da5230ab29743b63bf238a379891c98ac9d5038 (diff) |
Remove QWidget dependency from QTouchEvent.
QWidget *widget() is replaced with QObject *target().
Change-Id: Ib2c860480764410cf1527662e89f352ff688b32a
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/gui/kernel/qevent.cpp | 22 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 6 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 12 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 5 |
5 files changed, 25 insertions, 22 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 035f1b2666..7ff7fc0f5d 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3467,7 +3467,8 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType, Qt::TouchPointStates touchPointStates, const QList<QTouchEvent::TouchPoint> &touchPoints) : QInputEvent(eventType, modifiers), - _widget(0), + _window(0), + _target(0), _device(device), _touchPointStates(touchPointStates), _touchPoints(touchPoints) @@ -3479,11 +3480,6 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType, QTouchEvent::~QTouchEvent() { } -/*! \fn QWidget *QTouchEvent::widget() const - - Returns the widget on which the event occurred. -*/ - /*! \fn QWindow *QTouchEvent::window() const Returns the window on which the event occurred. Useful for doing @@ -3492,6 +3488,12 @@ QTouchEvent::~QTouchEvent() touch event. */ +/*! \fn QObject *QTouchEvent::target() const + + Returns the target object within the window on which the event occurred. + This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available. +*/ + /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. @@ -3521,18 +3523,18 @@ QTouchEvent::~QTouchEvent() Returns the touch device from which this touch event originates. */ -/*! \fn void QTouchEvent::setWidget(QWidget *widget) +/*! \fn void QTouchEvent::setWindow(QWindow *window) \internal - Sets the widget for this event. + Sets the window for this event. */ -/*! \fn void QTouchEvent::setWindow(QWindow *window) +/*! \fn void QTouchEvent::setTarget(QObject *target) \internal - Sets the window for this event. + Sets the target within the window (typically a widget) for this event. */ /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 6a0442509c..7237b16df7 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -776,23 +776,23 @@ public: const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>()); ~QTouchEvent(); - inline QWidget *widget() const { return _widget; } inline QWindow *window() const { return _window; } + inline QObject *target() const { return _target; } QT_DEPRECATED inline QTouchEvent::DeviceType deviceType() const { return static_cast<DeviceType>(int(_device->type())); } inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; } inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; } inline QTouchDevice *device() const { return _device; } // internal - inline void setWidget(QWidget *awidget) { _widget = awidget; } inline void setWindow(QWindow *awindow) { _window = awindow; } + inline void setTarget(QObject *atarget) { _target = atarget; } inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; } inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; } inline void setDevice(QTouchDevice *device) { _device = device; } protected: - QWidget *_widget; QWindow *_window; + QObject *_target; QTouchDevice *_device; Qt::TouchPointStates _touchPointStates; QList<QTouchEvent::TouchPoint> _touchPoints; diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 791f25aa27..f5057490c7 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -5777,8 +5777,8 @@ void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouch for (int i = 0; i < touchPoints.count(); ++i) { QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); - touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget())); - touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget())); + touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), static_cast<QWidget *>(touchEvent->target()))); + touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), static_cast<QWidget *>(touchEvent->target()))); } touchEvent->setTouchPoints(touchPoints); } @@ -5819,7 +5819,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) // determine which item this touch point will go to cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(), touchPoint.scenePos(), - sceneTouchEvent->widget()); + static_cast<QWidget *>(sceneTouchEvent->target())); item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first(); } @@ -5888,13 +5888,13 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) } QTouchEvent touchEvent(eventType); - touchEvent.setWidget(sceneTouchEvent->widget()); + touchEvent.setWindow(sceneTouchEvent->window()); + touchEvent.setTarget(sceneTouchEvent->target()); touchEvent.setDevice(sceneTouchEvent->device()); touchEvent.setModifiers(sceneTouchEvent->modifiers()); touchEvent.setTouchPointStates(it.value().first); touchEvent.setTouchPoints(it.value().second); touchEvent.setTimestamp(sceneTouchEvent->timestamp()); - touchEvent.setWindow(sceneTouchEvent->window()); switch (touchEvent.type()) { case QEvent::TouchBegin: @@ -5935,7 +5935,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), firstTouchPoint.scenePos(), - touchEvent->widget()); + static_cast<QWidget *>(touchEvent->target())); } Q_ASSERT(cachedItemsUnderMouse.first() == origin); diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 2ebd4ecc63..8efd4eee4a 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -2836,7 +2836,7 @@ bool QGraphicsView::viewportEvent(QEvent *event) if (d->scene && d->sceneInteractionAllowed) { // Convert and deliver the touch event to the scene. QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); - touchEvent->setWidget(viewport()); + touchEvent->setTarget(viewport()); QGraphicsViewPrivate::translateTouchEvent(d, touchEvent); (void) QApplication::sendEvent(d->scene, touchEvent); } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index afd5fb70e1..e6e8a8eab4 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3896,7 +3896,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) while (widget) { // first, try to deliver the touch event bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); - touchEvent->setWidget(widget); + touchEvent->setTarget(widget); touchEvent->setAccepted(acceptTouchEvents); QWeakPointer<QWidget> p = widget; res = acceptTouchEvents && d->notify_helper(widget, touchEvent); @@ -3920,7 +3920,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } QPoint offset = widget->pos(); widget = widget->parentWidget(); - touchEvent->setWidget(widget); + touchEvent->setTarget(widget); for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) { QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i]; QRectF rect = pt.rect(); @@ -5355,6 +5355,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, updateTouchPointsForWidget(widget, &touchEvent); touchEvent.setTimestamp(timestamp); touchEvent.setWindow(window->windowHandle()); + touchEvent.setTarget(window); switch (touchEvent.type()) { case QEvent::TouchBegin: |