diff options
Diffstat (limited to 'src/quicktemplates/qquickswipedelegate.cpp')
-rw-r--r-- | src/quicktemplates/qquickswipedelegate.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/quicktemplates/qquickswipedelegate.cpp b/src/quicktemplates/qquickswipedelegate.cpp index 24ca772b06..36782fee8c 100644 --- a/src/quicktemplates/qquickswipedelegate.cpp +++ b/src/quicktemplates/qquickswipedelegate.cpp @@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE \image qtquickcontrols-swipedelegate-behind.gif - \sa {Customizing SwipeDelegate}, {Delegate Controls}, {Qt Quick Controls 2 - Swipe to Remove}{Swipe to Remove Example} + \sa {Customizing SwipeDelegate}, {Delegate Controls}, {Qt Quick Controls 2 - Gallery}{Gallery Example} */ namespace { @@ -194,6 +194,7 @@ QQuickItem *QQuickSwipePrivate::createDelegateItem(QQmlComponent *component) if (item) { item->setParentItem(control); component->completeCreate(); + QJSEngine::setObjectOwnership(item, QJSEngine::JavaScriptOwnership); } return item; } @@ -770,12 +771,18 @@ bool QQuickSwipeDelegatePrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEv if (!swipePrivate->left && !swipePrivate->right && !swipePrivate->behind) return false; + if (item != q && swipePrivate->complete) { + // If the delegate is swiped open, send the event to the exposed item, + // in case it's an interactive child (like a Button). + const auto posInItem = item->mapToItem(q, event->position().toPoint()); + forwardMouseEvent(event, item, posInItem); + } + // Don't handle move events for the control if it wasn't pressed. if (item == q && !pressed) return false; - const QPointF mappedEventPos = item->mapToItem(q, event->position().toPoint()); - const qreal distance = (mappedEventPos - pressPoint).x(); + const qreal distance = (event->globalPosition() - event->points().first().globalPressPosition()).x(); if (!q->keepMouseGrab()) { // We used to use the custom threshold that QQuickDrawerPrivate::grabMouse used, // but since it's larger than what Flickable uses, it results in Flickable @@ -998,6 +1005,33 @@ QPalette QQuickSwipeDelegatePrivate::defaultPalette() const return QQuickTheme::palette(QQuickTheme::ListView); } +/*! \internal + Recursively search right and/or left item tree of swipe delegate for any item that + contains the \a event position. + + Returns the first such item found, otherwise \c nullptr. +*/ +QQuickItem *QQuickSwipeDelegatePrivate::getPressedItem(QQuickItem *childItem, QMouseEvent *event) const +{ + if (!childItem || !event) + return nullptr; + + QQuickItem *item = nullptr; + + if (childItem->acceptedMouseButtons() && + childItem->contains(childItem->mapFromScene(event->scenePosition()))) { + item = childItem; + } else { + const auto &childItems = childItem->childItems(); + for (const auto &child: childItems) { + if ((item = getPressedItem(child, event))) + break; + } + } + + return item; +} + QQuickSwipeDelegate::QQuickSwipeDelegate(QQuickItem *parent) : QQuickItemDelegate(*(new QQuickSwipeDelegatePrivate(this)), parent) { @@ -1240,17 +1274,11 @@ void QQuickSwipeDelegate::mousePressEvent(QMouseEvent *event) swipePrivate->velocityCalculator.startMeasuring(event->position().toPoint(), event->timestamp()); if (swipePrivate->complete) { - auto item = d->swipe.rightItem(); - if (item && item->contains(item->mapFromScene(event->scenePosition()))) { - d->pressedItem = item; - d->handleMousePressEvent(item, event); - } else { - item = d->swipe.leftItem(); - if (item && item->contains(item->mapFromScene(event->scenePosition()))) { - d->pressedItem = item; - d->handleMousePressEvent(item, event); - } - } + d->pressedItem = d->getPressedItem(d->swipe.rightItem(), event); + if (!d->pressedItem) + d->pressedItem = d->getPressedItem(d->swipe.leftItem(), event); + if (d->pressedItem) + d->handleMousePressEvent(d->pressedItem, event); } } |