From f71d22d6e077410c42291486e15b67215baa0739 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 28 Apr 2017 15:50:14 +0200 Subject: Add QQuickPopupPrivate::contains() for convenience This logic seemed to be repeated in several places... Change-Id: I3b74140c7d7e44fa6ada12cf7844d96086d99e47 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickdrawer.cpp | 10 +++++----- src/quicktemplates2/qquickpopup.cpp | 7 ++++++- src/quicktemplates2/qquickpopup_p_p.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 44500bd3..b896c142 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -308,7 +308,7 @@ bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event) } // Don't be too eager to steal presses outside the drawer (QTBUG-53929) - if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !popupItem->contains(popupItem->mapFromScene(movePoint))) { + if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !contains(movePoint)) { if (edge == Qt::LeftEdge || edge == Qt::RightEdge) overThreshold = qAbs(movePoint.x() - q->width()) < dragMargin; else @@ -323,7 +323,7 @@ bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event) offset = positionAt(movePoint) - position; // don't jump when dragged open - if (offset > 0 && position > 0 && !popupItem->contains(popupItem->mapFromScene(movePoint))) + if (offset > 0 && position > 0 && !contains(movePoint)) offset = 0; } } @@ -358,7 +358,7 @@ bool QQuickDrawerPrivate::grabTouch(QQuickItem *item, QTouchEvent *event) } // Don't be too eager to steal presses outside the drawer (QTBUG-53929) - if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !popupItem->contains(popupItem->mapFromScene(movePoint))) { + if (overThreshold && qFuzzyCompare(position, qreal(1.0)) && !contains(movePoint)) { if (edge == Qt::LeftEdge || edge == Qt::RightEdge) overThreshold = qAbs(movePoint.x() - q->width()) < dragMargin; else @@ -370,7 +370,7 @@ bool QQuickDrawerPrivate::grabTouch(QQuickItem *item, QTouchEvent *event) offset = positionAt(movePoint) - position; // don't jump when dragged open - if (offset > 0 && position > 0 && !popupItem->contains(popupItem->mapFromScene(movePoint))) + if (offset > 0 && position > 0 && !contains(movePoint)) offset = 0; } } @@ -399,7 +399,7 @@ bool QQuickDrawerPrivate::handleMove(QQuickItem *item, const QPointF &point, ulo return false; // 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))) + if (qFuzzyCompare(position, 1.0) && !contains(point)) offset = 0; bool isGrabbed = popupItem->keepMouseGrab() || popupItem->keepTouchGrab(); diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index 68a82204..9fb712ea 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -284,7 +284,7 @@ bool QQuickPopupPrivate::tryClose(const QPointF &pos, QQuickPopup::ClosePolicy f const bool onOutside = closePolicy & (flags & outsideFlags); const bool onOutsideParent = closePolicy & (flags & outsideParentFlags); if (onOutside || onOutsideParent) { - if (!popupItem->contains(popupItem->mapFromScene(pos))) { + if (!contains(pos)) { if (!onOutsideParent || !parentItem || !parentItem->contains(parentItem->mapFromScene(pos))) { closeOrReject(); return true; @@ -294,6 +294,11 @@ bool QQuickPopupPrivate::tryClose(const QPointF &pos, QQuickPopup::ClosePolicy f return false; } +bool QQuickPopupPrivate::contains(const QPointF &scenePos) const +{ + return popupItem->contains(popupItem->mapFromScene(scenePos)); +} + bool QQuickPopupPrivate::acceptTouch(const QTouchEvent::TouchPoint &point) { if (point.id() == touchId) diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index 5c2fe4f7..f5697993 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -97,6 +97,8 @@ public: void closeOrReject(); bool tryClose(const QPointF &pos, QQuickPopup::ClosePolicy flags); + bool contains(const QPointF &scenePos) const; + virtual bool acceptTouch(const QTouchEvent::TouchPoint &point); virtual bool blockInput(QQuickItem *item, const QPointF &point) const; -- cgit v1.2.3