diff options
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickscrollbar.cpp | 33 | ||||
-rw-r--r-- | src/quicktemplates2/qquickscrollbar_p.h | 5 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index 66df3dc9..f7a5c246 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -164,6 +164,7 @@ public: active(false), pressed(false), moving(false), + interactive(true), orientation(Qt::Vertical), snapMode(QQuickScrollBar::NoSnap) { @@ -191,6 +192,7 @@ public: bool active; bool pressed; bool moving; + bool interactive; Qt::Orientation orientation; QQuickScrollBar::SnapMode snapMode; }; @@ -216,7 +218,7 @@ qreal QQuickScrollBarPrivate::positionAt(const QPointF &point) const void QQuickScrollBarPrivate::updateActive() { Q_Q(QQuickScrollBar); - q->setActive(moving || pressed || hovered); + q->setActive(moving || (interactive && (pressed || hovered))); } void QQuickScrollBarPrivate::resizeContent() @@ -489,6 +491,35 @@ void QQuickScrollBar::setSnapMode(SnapMode mode) } /*! + \since QtQuick.Controls 2.2 + \qmlproperty bool QtQuick.Controls::ScrollBar::interactive + + This property holds whether the scroll bar is interactive. The default value is \c true. + + A non-interactive scroll bar is visually and behaviorally similar to \l ScrollIndicator. + This property is useful for switching between typical mouse- and touch-orientated UIs + with interactive and non-interactive scroll bars, respectively. +*/ +bool QQuickScrollBar::isInteractive() const +{ + Q_D(const QQuickScrollBar); + return d->interactive; +} + +void QQuickScrollBar::setInteractive(bool interactive) +{ + Q_D(QQuickScrollBar); + if (d->interactive == interactive) + return; + + d->interactive = interactive; + setAcceptedMouseButtons(interactive ? Qt::LeftButton : Qt::NoButton); + if (!interactive) + ungrabMouse(); + emit interactiveChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::ScrollBar::increase() Increases the position by \l stepSize or \c 0.1 if stepSize is \c 0.0. diff --git a/src/quicktemplates2/qquickscrollbar_p.h b/src/quicktemplates2/qquickscrollbar_p.h index a34c337c..9709f183 100644 --- a/src/quicktemplates2/qquickscrollbar_p.h +++ b/src/quicktemplates2/qquickscrollbar_p.h @@ -66,6 +66,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) public: explicit QQuickScrollBar(QQuickItem *parent = nullptr); @@ -97,6 +98,9 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + bool isInteractive() const; + void setInteractive(bool interactive); + public Q_SLOTS: void increase(); void decrease(); @@ -111,6 +115,7 @@ Q_SIGNALS: void pressedChanged(); void orientationChanged(); Q_REVISION(2) void snapModeChanged(); + Q_REVISION(2) void interactiveChanged(); protected: void mousePressEvent(QMouseEvent *event) override; |