Remove QWidget dependency from QTouchEvent.

QWidget *widget() is replaced with QObject *target().

Change-Id: Ib2c860480764410cf1527662e89f352ff688b32a
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Laszlo Agocs 2011-11-30 18:51:00 +02:00 committed by Qt by Nokia
parent 5da5230ab2
commit 4471e45f74
5 changed files with 28 additions and 25 deletions

View File

@ -3467,7 +3467,8 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType,
Qt::TouchPointStates touchPointStates, Qt::TouchPointStates touchPointStates,
const QList<QTouchEvent::TouchPoint> &touchPoints) const QList<QTouchEvent::TouchPoint> &touchPoints)
: QInputEvent(eventType, modifiers), : QInputEvent(eventType, modifiers),
_widget(0), _window(0),
_target(0),
_device(device), _device(device),
_touchPointStates(touchPointStates), _touchPointStates(touchPointStates),
_touchPoints(touchPoints) _touchPoints(touchPoints)
@ -3479,11 +3480,6 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType,
QTouchEvent::~QTouchEvent() QTouchEvent::~QTouchEvent()
{ } { }
/*! \fn QWidget *QTouchEvent::widget() const
Returns the widget on which the event occurred.
*/
/*! \fn QWindow *QTouchEvent::window() const /*! \fn QWindow *QTouchEvent::window() const
Returns the window on which the event occurred. Useful for doing Returns the window on which the event occurred. Useful for doing
@ -3492,6 +3488,12 @@ QTouchEvent::~QTouchEvent()
touch event. 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 /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
@ -3521,13 +3523,6 @@ QTouchEvent::~QTouchEvent()
Returns the touch device from which this touch event originates. Returns the touch device from which this touch event originates.
*/ */
/*! \fn void QTouchEvent::setWidget(QWidget *widget)
\internal
Sets the widget for this event.
*/
/*! \fn void QTouchEvent::setWindow(QWindow *window) /*! \fn void QTouchEvent::setWindow(QWindow *window)
\internal \internal
@ -3535,6 +3530,13 @@ QTouchEvent::~QTouchEvent()
Sets the window for this event. Sets the window for this event.
*/ */
/*! \fn void QTouchEvent::setTarget(QObject *target)
\internal
Sets the target within the window (typically a widget) for this event.
*/
/*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
\internal \internal

View File

@ -776,23 +776,23 @@ public:
const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>()); const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
~QTouchEvent(); ~QTouchEvent();
inline QWidget *widget() const { return _widget; }
inline QWindow *window() const { return _window; } 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())); } QT_DEPRECATED inline QTouchEvent::DeviceType deviceType() const { return static_cast<DeviceType>(int(_device->type())); }
inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; } inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; } inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
inline QTouchDevice *device() const { return _device; } inline QTouchDevice *device() const { return _device; }
// internal // internal
inline void setWidget(QWidget *awidget) { _widget = awidget; }
inline void setWindow(QWindow *awindow) { _window = awindow; } inline void setWindow(QWindow *awindow) { _window = awindow; }
inline void setTarget(QObject *atarget) { _target = atarget; }
inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; } inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; }
inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; } inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
inline void setDevice(QTouchDevice *device) { _device = device; } inline void setDevice(QTouchDevice *device) { _device = device; }
protected: protected:
QWidget *_widget;
QWindow *_window; QWindow *_window;
QObject *_target;
QTouchDevice *_device; QTouchDevice *_device;
Qt::TouchPointStates _touchPointStates; Qt::TouchPointStates _touchPointStates;
QList<QTouchEvent::TouchPoint> _touchPoints; QList<QTouchEvent::TouchPoint> _touchPoints;

View File

@ -5777,8 +5777,8 @@ void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouch
for (int i = 0; i < touchPoints.count(); ++i) { for (int i = 0; i < touchPoints.count(); ++i) {
QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect());
touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget())); touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), static_cast<QWidget *>(touchEvent->target())));
touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget())); touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), static_cast<QWidget *>(touchEvent->target())));
} }
touchEvent->setTouchPoints(touchPoints); touchEvent->setTouchPoints(touchPoints);
} }
@ -5819,7 +5819,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
// determine which item this touch point will go to // determine which item this touch point will go to
cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(), cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(),
touchPoint.scenePos(), touchPoint.scenePos(),
sceneTouchEvent->widget()); static_cast<QWidget *>(sceneTouchEvent->target()));
item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first(); item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first();
} }
@ -5888,13 +5888,13 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
} }
QTouchEvent touchEvent(eventType); QTouchEvent touchEvent(eventType);
touchEvent.setWidget(sceneTouchEvent->widget()); touchEvent.setWindow(sceneTouchEvent->window());
touchEvent.setTarget(sceneTouchEvent->target());
touchEvent.setDevice(sceneTouchEvent->device()); touchEvent.setDevice(sceneTouchEvent->device());
touchEvent.setModifiers(sceneTouchEvent->modifiers()); touchEvent.setModifiers(sceneTouchEvent->modifiers());
touchEvent.setTouchPointStates(it.value().first); touchEvent.setTouchPointStates(it.value().first);
touchEvent.setTouchPoints(it.value().second); touchEvent.setTouchPoints(it.value().second);
touchEvent.setTimestamp(sceneTouchEvent->timestamp()); touchEvent.setTimestamp(sceneTouchEvent->timestamp());
touchEvent.setWindow(sceneTouchEvent->window());
switch (touchEvent.type()) { switch (touchEvent.type()) {
case QEvent::TouchBegin: case QEvent::TouchBegin:
@ -5935,7 +5935,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first(); const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(), cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(),
firstTouchPoint.scenePos(), firstTouchPoint.scenePos(),
touchEvent->widget()); static_cast<QWidget *>(touchEvent->target()));
} }
Q_ASSERT(cachedItemsUnderMouse.first() == origin); Q_ASSERT(cachedItemsUnderMouse.first() == origin);

View File

@ -2836,7 +2836,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
if (d->scene && d->sceneInteractionAllowed) { if (d->scene && d->sceneInteractionAllowed) {
// Convert and deliver the touch event to the scene. // Convert and deliver the touch event to the scene.
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
touchEvent->setWidget(viewport()); touchEvent->setTarget(viewport());
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent); QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
(void) QApplication::sendEvent(d->scene, touchEvent); (void) QApplication::sendEvent(d->scene, touchEvent);
} }

View File

@ -3896,7 +3896,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
while (widget) { while (widget) {
// first, try to deliver the touch event // first, try to deliver the touch event
bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents); bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents);
touchEvent->setWidget(widget); touchEvent->setTarget(widget);
touchEvent->setAccepted(acceptTouchEvents); touchEvent->setAccepted(acceptTouchEvents);
QWeakPointer<QWidget> p = widget; QWeakPointer<QWidget> p = widget;
res = acceptTouchEvents && d->notify_helper(widget, touchEvent); res = acceptTouchEvents && d->notify_helper(widget, touchEvent);
@ -3920,7 +3920,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
} }
QPoint offset = widget->pos(); QPoint offset = widget->pos();
widget = widget->parentWidget(); widget = widget->parentWidget();
touchEvent->setWidget(widget); touchEvent->setTarget(widget);
for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) { for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) {
QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i]; QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i];
QRectF rect = pt.rect(); QRectF rect = pt.rect();
@ -5355,6 +5355,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
updateTouchPointsForWidget(widget, &touchEvent); updateTouchPointsForWidget(widget, &touchEvent);
touchEvent.setTimestamp(timestamp); touchEvent.setTimestamp(timestamp);
touchEvent.setWindow(window->windowHandle()); touchEvent.setWindow(window->windowHandle());
touchEvent.setTarget(window);
switch (touchEvent.type()) { switch (touchEvent.type()) {
case QEvent::TouchBegin: case QEvent::TouchBegin: