From 00d2861f7447d0673bffb1f964e71bb5792b8312 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 29 Apr 2017 10:10:53 +0200 Subject: Add QQuickDrawerPrivate::offsetAt() Share the duplicated logic in grabMouse() and grabTouch(). Change-Id: If53dd5dd4302009594548e94bcc5f95b352e1bf6 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickdrawer.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/quicktemplates2/qquickdrawer.cpp') diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 2ca0f6c3..94b8aea7 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -169,6 +169,17 @@ QQuickDrawerPrivate::QQuickDrawerPrivate() setEdge(Qt::LeftEdge); } +qreal QQuickDrawerPrivate::offsetAt(const QPointF &point) const +{ + qreal offset = positionAt(point) - position; + + // don't jump when dragged open + if (offset > 0 && position > 0 && !contains(point)) + offset = 0; + + return offset; +} + qreal QQuickDrawerPrivate::positionAt(const QPointF &point) const { Q_Q(const QQuickDrawer); @@ -322,11 +333,7 @@ bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event) if (!grabber || !grabber->keepMouseGrab()) { popupItem->grabMouse(); popupItem->setKeepMouseGrab(true); - offset = positionAt(movePoint) - position; - - // don't jump when dragged open - if (offset > 0 && position > 0 && !contains(movePoint)) - offset = 0; + offset = offsetAt(movePoint); } } @@ -371,11 +378,7 @@ bool QQuickDrawerPrivate::grabTouch(QQuickItem *item, QTouchEvent *event) if (overThreshold) { popupItem->setKeepTouchGrab(true); - offset = positionAt(movePoint) - position; - - // don't jump when dragged open - if (offset > 0 && position > 0 && !contains(movePoint)) - offset = 0; + offset = offsetAt(movePoint); } } -- cgit v1.2.3