diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-24 23:52:44 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-25 14:20:08 +0000 |
commit | cacac5a630d6e91417f077e072455a94e78bf571 (patch) | |
tree | fe7a4872d4f12293582448fdf14ddcf1eaba7330 | |
parent | 35415a2d70d5103d5a25c369fd42fec9a3842262 (diff) |
Eradicate QQuickDrawerPrivate::handleMouseMoveEvent()
Change-Id: I4759baa3691498fce8c291cbb0d3f77e9e2fd8d6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 73 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p_p.h | 4 |
2 files changed, 32 insertions, 45 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 41b169a4..c2597cc4 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -282,9 +282,11 @@ bool QQuickDrawerPrivate::startDrag(QEvent *event) return false; } -bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event) +bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event) { Q_Q(QQuickDrawer); + handleMouseEvent(item, event); + if (!window || !interactive || popupItem->keepMouseGrab()) return false; @@ -310,6 +312,19 @@ bool QQuickDrawerPrivate::grabMouse(QMouseEvent *event) overThreshold = qAbs(movePoint.y() - q->height()) < dragMargin; } + if (overThreshold) { + QQuickItem *grabber = window->mouseGrabberItem(); + if (!grabber || !grabber->keepMouseGrab()) { + popupItem->grabMouse(); + popupItem->setKeepMouseGrab(true); + offset = positionAt(movePoint) - position; + + // don't jump when dragged open + if (offset > 0 && position > 0 && !popupItem->contains(popupItem->mapFromScene(movePoint))) + offset = 0; + } + } + return overThreshold; } @@ -326,7 +341,15 @@ void QQuickDrawerPrivate::handlePress(const QPointF &point, ulong timestamp) void QQuickDrawerPrivate::handleMove(const QPointF &point, ulong timestamp) { + Q_Q(QQuickDrawer); QQuickPopupPrivate::handleMove(point, timestamp); + + // limit/reset the offset to the edge of the drawer when pushed from the outside + if (qFuzzyCompare(position, 1.0) && !popupItem->contains(popupItem->mapFromScene(point))) + offset = 0; + + if (popupItem->keepMouseGrab() || popupItem->keepTouchGrab()) + q->setPosition(positionAt(point) - offset); } void QQuickDrawerPrivate::handleRelease(const QPointF &point, ulong timestamp) @@ -403,43 +426,6 @@ void QQuickDrawerPrivate::handleUngrab() velocityCalculator.reset(); } -bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event) -{ - Q_Q(QQuickDrawer); - handleMove(item->mapToScene(event->localPos()), event->timestamp()); - - // Don't react to synthesized mouse move events at INF,INF coordinates. - // QQuickWindowPrivate::translateTouchToMouse() uses them to clear hover - // on touch release (QTBUG-55995). - if (qIsInf(event->screenPos().x()) || qIsInf(event->screenPos().y())) - return true; - - const QPointF movePoint = event->windowPos(); - - if (grabMouse(event)) { - QQuickItem *grabber = window->mouseGrabberItem(); - if (!grabber || !grabber->keepMouseGrab()) { - popupItem->grabMouse(); - popupItem->setKeepMouseGrab(true); - offset = positionAt(movePoint) - position; - - // don't jump when dragged open - if (offset > 0 && position > 0 && !popupItem->contains(popupItem->mapFromScene(movePoint))) - offset = 0; - } - } - - // limit/reset the offset to the edge of the drawer when pushed from the outside - if (qFuzzyCompare(position, 1.0) && !popupItem->contains(popupItem->mapFromScene(movePoint))) - offset = 0; - - if (popupItem->keepMouseGrab()) - q->setPosition(positionAt(movePoint) - offset); - event->accept(); - - return popupItem->keepMouseGrab(); -} - static QList<QQuickStateAction> prepareTransition(QQuickDrawer *drawer, QQuickTransition *transition, qreal to) { QList<QQuickStateAction> actions; @@ -621,7 +607,7 @@ bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) Q_D(QQuickDrawer); switch (event->type()) { case QEvent::MouseMove: - return d->handleMouseMoveEvent(child, static_cast<QMouseEvent *>(event)); + return d->grabMouse(child, static_cast<QMouseEvent *>(event)); case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: d->handleMouseEvent(child, static_cast<QMouseEvent *>(event)); @@ -635,7 +621,7 @@ bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) void QQuickDrawer::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickDrawer); - d->handleMouseMoveEvent(d->popupItem, event); + d->grabMouse(d->popupItem, event); } bool QQuickDrawer::overlayEvent(QQuickItem *item, QEvent *event) @@ -651,10 +637,13 @@ bool QQuickDrawer::overlayEvent(QQuickItem *item, QEvent *event) return false; case QEvent::MouseMove: - return d->handleMouseMoveEvent(item, static_cast<QMouseEvent *>(event)); + return d->grabMouse(item, static_cast<QMouseEvent *>(event)); + default: - return QQuickPopup::overlayEvent(item, event); + break; } + + return QQuickPopup::overlayEvent(item, event); } void QQuickDrawer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index 9fca728f..4c577982 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -71,15 +71,13 @@ public: void resizeOverlay() override; bool startDrag(QEvent *event); - bool grabMouse(QMouseEvent *event); + bool grabMouse(QQuickItem *item, QMouseEvent *event); void handlePress(const QPointF &point, ulong timestamp) override; void handleMove(const QPointF &point, ulong timestamp) override; void handleRelease(const QPointF &point, ulong timestamp) override; void handleUngrab() override; - bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event); - bool prepareEnterTransition() override; bool prepareExitTransition() override; |