aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-01-19 14:31:54 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-01-20 09:05:06 +0000
commitfdd41317118cd14fdab472a60ac67516d9d4d937 (patch)
treee271bd55ae5a0e6bf700ffc32f7db53b6072a671 /src/quicktemplates2
parent945a407d6f6ca25098efcf3bdf138fb622cd5110 (diff)
Add ScrollBar::interactive
[ChangeLog][Controls][ScrollBar] Added an interactive-property. A non-interactive ScrollBar is visually and behaviorally similar to ScrollIndicator. This property is useful for switching between typical mouse- and touch-orientated UIs with interactive and non- interactive scroll bars, respectively. Change-Id: Ie98bfa0b5bba94a9751baf3c65f17b850b58fd1f Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickscrollbar.cpp33
-rw-r--r--src/quicktemplates2/qquickscrollbar_p.h5
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;