aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickslider.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-04 21:39:57 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-05 12:07:26 +0000
commit47736b3510696ad3fdff1e9460938f29435261f2 (patch)
treee82bd4a3aba6621a627425c9c3a524b30690daf0 /src/quicktemplates2/qquickslider.cpp
parentae3e7f0799fcdd094e54d792e1a9b13c0e7730aa (diff)
Add QQuickSlider::live
[ChangeLog][Controls][Slider] Added a live-property that determines whether the slider provides live updates for the value-property while the handle is dragged. Change-Id: Ib393548f80be4db57a977eac39d5d560ca441f3c Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickslider.cpp')
-rw-r--r--src/quicktemplates2/qquickslider.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp
index 43754260..3eb186be 100644
--- a/src/quicktemplates2/qquickslider.cpp
+++ b/src/quicktemplates2/qquickslider.cpp
@@ -77,7 +77,7 @@ class QQuickSliderPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickSlider)
public:
- QQuickSliderPrivate() : from(0), to(1), value(0), position(0), stepSize(0), pressed(false),
+ QQuickSliderPrivate() : from(0), to(1), value(0), position(0), stepSize(0), live(false), pressed(false),
orientation(Qt::Horizontal), snapMode(QQuickSlider::NoSnap),
handle(nullptr)
{
@@ -93,6 +93,7 @@ public:
qreal value;
qreal position;
qreal stepSize;
+ bool live;
bool pressed;
QPoint pressPoint;
Qt::Orientation orientation;
@@ -222,12 +223,12 @@ void QQuickSlider::setTo(qreal to)
This property holds the value in the range \c from - \c to. The default value is \c 0.0.
- Unlike the \l position property, the \c value is not updated while the
- handle is dragged, but only after the value has been chosen and the slider
- has been released. The \l valueAt() method can be used to get continuous
- updates.
+ Unlike the \l position property, the \c value is not updated by default
+ while the handle is dragged, but only after the value has been chosen and
+ the slider has been released. The \l live property can be used to make the
+ slider provide live updates for the \c value property.
- \sa position, valueAt()
+ \sa position, live, valueAt()
*/
qreal QQuickSlider::value() const
{
@@ -256,9 +257,9 @@ void QQuickSlider::setValue(qreal value)
This property holds the logical position of the handle.
The position is defined as a percentage of the control's size, scaled
- to \c {0.0 - 1.0}. Unlike the \l value property, the \c position is
- continuously updated while the handle is dragged. For visualizing a
- slider, the right-to-left aware \l visualPosition should be used instead.
+ to \c {0.0 - 1.0}. The \c position is continuously updated while the
+ handle is dragged. For visualizing a slider, the right-to-left aware
+ \l visualPosition should be used instead.
\sa value, visualPosition, valueAt()
*/
@@ -341,6 +342,33 @@ void QQuickSlider::setSnapMode(SnapMode mode)
}
/*!
+ \since QtQuick.Controls 2.2
+ \qmlproperty bool QtQuick.Controls::Slider::live
+
+ This property holds whether the slider provides live updates for the \l value
+ property while the handle is dragged.
+
+ The default value is \c false.
+
+ \sa value
+*/
+bool QQuickSlider::live() const
+{
+ Q_D(const QQuickSlider);
+ return d->live;
+}
+
+void QQuickSlider::setLive(bool live)
+{
+ Q_D(QQuickSlider);
+ if (d->live == live)
+ return;
+
+ d->live = live;
+ emit liveChanged();
+}
+
+/*!
\qmlproperty bool QtQuick.Controls::Slider::pressed
This property holds whether the slider is pressed.
@@ -521,7 +549,10 @@ void QQuickSlider::mouseMoveEvent(QMouseEvent *event)
qreal pos = d->positionAt(event->pos());
if (d->snapMode == SnapAlways)
pos = d->snapPosition(pos);
- d->setPosition(pos);
+ if (d->live)
+ setValue(valueAt(pos));
+ else
+ d->setPosition(pos);
}
}