diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-01-25 10:22:47 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-01-26 14:12:44 +0000 |
commit | 855e23ebd6691b03420b7f1621ea4185447cfd54 (patch) | |
tree | 5e7f8c314a5d8425918f22783119aaa36b701d3c /src/quicktemplates2 | |
parent | f2602121228e910b9e400dadd2b8ee951052c3ba (diff) |
Keep track whether ScrollBar::interactive is explicitly set
The upcoming ScrollView toggles between interactive and non-interactive
scroll bars depending on whether it is interacted via touch or a mouse
device. This allows ScrollView to check whether the user or style
explicitly requested a specific mode and respect it.
Change-Id: I69d21652b3a91cb9db0f76ba52adc35ccd612ab1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickscrollbar.cpp | 29 | ||||
-rw-r--r-- | src/quicktemplates2/qquickscrollbar_p.h | 3 | ||||
-rw-r--r-- | src/quicktemplates2/qquickscrollbar_p_p.h | 2 |
3 files changed, 26 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index ac786649..f0dd640b 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -163,6 +163,7 @@ QQuickScrollBarPrivate::QQuickScrollBarPrivate() pressed(false), moving(false), interactive(true), + explicitInteractive(false), orientation(Qt::Vertical), snapMode(QQuickScrollBar::NoSnap), policy(QQuickScrollBar::AsNeeded) @@ -187,6 +188,19 @@ qreal QQuickScrollBarPrivate::positionAt(const QPointF &point) const return (point.y() - q->topPadding()) / q->availableHeight(); } +void QQuickScrollBarPrivate::setInteractive(bool enabled) +{ + Q_Q(QQuickScrollBar); + if (interactive == enabled) + return; + + interactive = enabled; + q->setAcceptedMouseButtons(interactive ? Qt::LeftButton : Qt::NoButton); + if (!interactive) + q->ungrabMouse(); + emit q->interactiveChanged(); +} + void QQuickScrollBarPrivate::updateActive() { Q_Q(QQuickScrollBar); @@ -480,14 +494,15 @@ bool QQuickScrollBar::isInteractive() const void QQuickScrollBar::setInteractive(bool interactive) { Q_D(QQuickScrollBar); - if (d->interactive == interactive) - return; + d->explicitInteractive = true; + d->setInteractive(interactive); +} - d->interactive = interactive; - setAcceptedMouseButtons(interactive ? Qt::LeftButton : Qt::NoButton); - if (!interactive) - ungrabMouse(); - emit interactiveChanged(); +void QQuickScrollBar::resetInteractive() +{ + Q_D(QQuickScrollBar); + d->explicitInteractive = false; + d->setInteractive(true); } /*! diff --git a/src/quicktemplates2/qquickscrollbar_p.h b/src/quicktemplates2/qquickscrollbar_p.h index dabc860b..868cb5d8 100644 --- a/src/quicktemplates2/qquickscrollbar_p.h +++ b/src/quicktemplates2/qquickscrollbar_p.h @@ -65,7 +65,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBar : public QQuickControl Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL REVISION 2) - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 2) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive RESET resetInteractive NOTIFY interactiveChanged FINAL REVISION 2) Q_PROPERTY(Policy policy READ policy WRITE setPolicy NOTIFY policyChanged FINAL REVISION 2) public: @@ -100,6 +100,7 @@ public: bool isInteractive() const; void setInteractive(bool interactive); + void resetInteractive(); enum Policy { AsNeeded = Qt::ScrollBarAsNeeded, diff --git a/src/quicktemplates2/qquickscrollbar_p_p.h b/src/quicktemplates2/qquickscrollbar_p_p.h index fa5bd0b5..cbbef2c8 100644 --- a/src/quicktemplates2/qquickscrollbar_p_p.h +++ b/src/quicktemplates2/qquickscrollbar_p_p.h @@ -70,6 +70,7 @@ public: qreal snapPosition(qreal position) const; qreal positionAt(const QPointF &point) const; + void setInteractive(bool interactive); void updateActive(); void resizeContent() override; @@ -86,6 +87,7 @@ public: bool pressed; bool moving; bool interactive; + bool explicitInteractive; Qt::Orientation orientation; QQuickScrollBar::SnapMode snapMode; QQuickScrollBar::Policy policy; |