diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-29 10:10:53 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-02 20:51:05 +0000 |
commit | 00d2861f7447d0673bffb1f964e71bb5792b8312 (patch) | |
tree | 6969297e93f0fe00b7f344ae43130ab59872c5e9 /src | |
parent | c0ef03934632ebe897d8c2ebee2f9af53e168ed8 (diff) |
Add QQuickDrawerPrivate::offsetAt()
Share the duplicated logic in grabMouse() and grabTouch().
Change-Id: If53dd5dd4302009594548e94bcc5f95b352e1bf6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 23 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p_p.h | 2 |
2 files changed, 15 insertions, 10 deletions
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); } } diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index bfa97fb1..bc4f91eb 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -66,7 +66,9 @@ public: return drawer->d_func(); } + qreal offsetAt(const QPointF &point) const; qreal positionAt(const QPointF &point) const; + void reposition() override; void resizeOverlay() override; |