aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickscrollbar.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-20 08:14:57 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-21 16:20:11 +0000
commit5e162c68fade8e5d4175deb92496376bd7be43d7 (patch)
tree4440b7b212abc87a6ddb2ad7ce375c92c285d54b /src/templates/qquickscrollbar.cpp
parent737bdea1e3dc41b5b30bb26c36224e31966ebd54 (diff)
ScrollBar: add increase(), decrease() and stepSize
Change-Id: I052b650fee7ae94cc826446d285d653a41bd1e75 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickscrollbar.cpp')
-rw-r--r--src/templates/qquickscrollbar.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/templates/qquickscrollbar.cpp b/src/templates/qquickscrollbar.cpp
index e457e510..376609da 100644
--- a/src/templates/qquickscrollbar.cpp
+++ b/src/templates/qquickscrollbar.cpp
@@ -73,6 +73,21 @@ QT_BEGIN_NAMESPACE
\li \l active
\endlist
+ Notice that ScrollBar does not filter key events of the Flickable it is
+ attached to. The following example illustrates how to implement scrolling
+ with up and down keys:
+
+ \code
+ Flickable {
+ focus: true
+
+ Keys.onUpPressed: scrollBar.decrease()
+ Keys.onDownPressed: scrollBar.increase()
+
+ ScrollBar.vertical: ScrollBar { id: scrollBar }
+ }
+ \endcode
+
\labs
\sa ScrollIndicator, {Customizing ScrollBar}, {Indicator Controls}
@@ -83,7 +98,7 @@ class QQuickScrollBarPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickScrollBar)
public:
- QQuickScrollBarPrivate() : size(0), position(0), offset(0),
+ QQuickScrollBarPrivate() : size(0), position(0), stepSize(0), offset(0),
active(false), pressed(false), moving(false),
orientation(Qt::Vertical)
{
@@ -100,6 +115,7 @@ public:
qreal size;
qreal position;
+ qreal stepSize;
qreal offset;
bool active;
bool pressed;
@@ -164,6 +180,7 @@ qreal QQuickScrollBar::size() const
void QQuickScrollBar::setSize(qreal size)
{
Q_D(QQuickScrollBar);
+ size = qBound(0.0, size, 1.0 - d->position);
if (qFuzzyCompare(d->size, size))
return;
@@ -189,6 +206,7 @@ qreal QQuickScrollBar::position() const
void QQuickScrollBar::setPosition(qreal position)
{
Q_D(QQuickScrollBar);
+ position = qBound(0.0, position, 1.0 - d->size);
if (qFuzzyCompare(d->position, position))
return;
@@ -199,6 +217,29 @@ void QQuickScrollBar::setPosition(qreal position)
}
/*!
+ \qmlproperty real Qt.labs.controls::ScrollBar::stepSize
+
+ This property holds the step size. The default value is \c 0.0.
+
+ \sa increase(), decrease()
+*/
+qreal QQuickScrollBar::stepSize() const
+{
+ Q_D(const QQuickScrollBar);
+ return d->stepSize;
+}
+
+void QQuickScrollBar::setStepSize(qreal step)
+{
+ Q_D(QQuickScrollBar);
+ if (qFuzzyCompare(d->stepSize, step))
+ return;
+
+ d->stepSize = step;
+ emit stepSizeChanged();
+}
+
+/*!
\qmlproperty bool Qt.labs.controls::ScrollBar::active
This property holds whether the scroll bar is active, i.e. when it's \l pressed
@@ -270,6 +311,38 @@ void QQuickScrollBar::setOrientation(Qt::Orientation orientation)
emit orientationChanged();
}
+/*!
+ \qmlmethod void Qt.labs.controls::ScrollBar::increase()
+
+ Increases the position by \l stepSize or \c 0.1 if stepSize is \c 0.0.
+
+ \sa stepSize
+*/
+void QQuickScrollBar::increase()
+{
+ Q_D(QQuickScrollBar);
+ qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize;
+ setActive(true);
+ setPosition(d->position + step);
+ setActive(false);
+}
+
+/*!
+ \qmlmethod void Qt.labs.controls::ScrollBar::decrease()
+
+ Decreases the position by \l stepSize or \c 0.1 if stepSize is \c 0.0.
+
+ \sa stepSize
+*/
+void QQuickScrollBar::decrease()
+{
+ Q_D(QQuickScrollBar);
+ qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize;
+ setActive(true);
+ setPosition(d->position - step);
+ setActive(false);
+}
+
void QQuickScrollBar::mousePressEvent(QMouseEvent *event)
{
Q_D(QQuickScrollBar);