QQuickWindowPrivate::removeGrabber: take params for mouse and touch

QQuickItem::ungrabTouchPoints() wasn't intended to ungrab mouse
and QQuickItem::ungrabMouse() wasn't intended to ungrab touch.
This seems to make the tests more likely to pass.

Change-Id: I2d39028dc8267b7c8b0e1bac721f1a12014f0b25
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Shawn Rutledge 2016-07-01 16:56:43 +02:00
parent e00b9df034
commit e7d6606e2d
3 changed files with 12 additions and 19 deletions

View File

@ -7208,16 +7208,7 @@ void QQuickItem::ungrabMouse()
if (!d->window) if (!d->window)
return; return;
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(d->window); QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(d->window);
if (windowPriv->mouseGrabberItem != this) { windowPriv->removeGrabber(this, true, false);
qWarning("QQuickItem::ungrabMouse(): Item is not the mouse grabber.");
return;
}
qCDebug(DBG_MOUSE_TARGET) << "ungrabMouse" << windowPriv->mouseGrabberItem << "-> null";
windowPriv->mouseGrabberItem = 0;
QEvent ev(QEvent::UngrabMouse);
d->window->sendEvent(this, &ev);
} }
@ -7304,7 +7295,7 @@ void QQuickItem::ungrabTouchPoints()
if (!d->window) if (!d->window)
return; return;
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(d->window); QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(d->window);
windowPriv->removeGrabber(this); windowPriv->removeGrabber(this, false, true);
} }
/*! /*!

View File

@ -771,17 +771,19 @@ void QQuickWindowPrivate::setMouseGrabber(QQuickItem *grabber)
} }
} }
void QQuickWindowPrivate::removeGrabber(QQuickItem *grabber) void QQuickWindowPrivate::removeGrabber(QQuickItem *grabber, bool mouse, bool touch)
{ {
Q_Q(QQuickWindow); Q_Q(QQuickWindow);
QMutableHashIterator<int, QQuickItem *> itemTouchMapIt(itemForTouchPointId); if (Q_LIKELY(touch)) {
while (itemTouchMapIt.hasNext()) { QMutableHashIterator<int, QQuickItem *> itemTouchMapIt(itemForTouchPointId);
if (itemTouchMapIt.next().value() == grabber) { while (itemTouchMapIt.hasNext()) {
itemTouchMapIt.remove(); if (itemTouchMapIt.next().value() == grabber) {
grabber->touchUngrabEvent(); itemTouchMapIt.remove();
grabber->touchUngrabEvent();
}
} }
} }
if (mouseGrabberItem == grabber) { if (Q_LIKELY(mouse) && mouseGrabberItem == grabber) {
qCDebug(DBG_MOUSE_TARGET) << "removeGrabber" << mouseGrabberItem << "-> null"; qCDebug(DBG_MOUSE_TARGET) << "removeGrabber" << mouseGrabberItem << "-> null";
mouseGrabberItem = 0; mouseGrabberItem = 0;
QEvent ev(QEvent::UngrabMouse); QEvent ev(QEvent::UngrabMouse);

View File

@ -143,7 +143,7 @@ public:
bool translateTouchToMouse(QQuickItem *item, QTouchEvent *event); bool translateTouchToMouse(QQuickItem *item, QTouchEvent *event);
void translateTouchEvent(QTouchEvent *touchEvent); void translateTouchEvent(QTouchEvent *touchEvent);
void setMouseGrabber(QQuickItem *grabber); void setMouseGrabber(QQuickItem *grabber);
void removeGrabber(QQuickItem *grabber); void removeGrabber(QQuickItem *grabber, bool mouse = true, bool touch = true);
static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform); static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
static QMouseEvent *cloneMouseEvent(QMouseEvent *event, QPointF *transformedLocalPos = 0); static QMouseEvent *cloneMouseEvent(QMouseEvent *event, QPointF *transformedLocalPos = 0);
bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *); bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *);