diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-10-05 15:36:31 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-10-06 08:40:05 +0000 |
commit | 405ef2c0524e6b9b0236bc5d7c0e6e5ed5c82fe8 (patch) | |
tree | 6567e68b8eba596418d2aebf4917541eed1130b6 | |
parent | 47736b3510696ad3fdff1e9460938f29435261f2 (diff) |
Add QQuickRangeSlider::live
[ChangeLog][Controls][RangeSlider] Added a live-property that determines
whether the range slider provides live updates for the first.value and
second.value properties while the respective handle is dragged.
Change-Id: I44d1924078969a5e22aca55625967dd8b5a4abac
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/controls/RangeSlider.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/material/RangeSlider.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/qtquickcontrols2plugin.cpp | 2 | ||||
-rw-r--r-- | src/imports/controls/universal/RangeSlider.qml | 2 | ||||
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickrangeslider.cpp | 46 | ||||
-rw-r--r-- | src/quicktemplates2/qquickrangeslider_p.h | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_rangeslider.qml | 12 |
8 files changed, 60 insertions, 14 deletions
diff --git a/src/imports/controls/RangeSlider.qml b/src/imports/controls/RangeSlider.qml index 14d7e271..60f2207a 100644 --- a/src/imports/controls/RangeSlider.qml +++ b/src/imports/controls/RangeSlider.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.6 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick.Templates 2.2 as T T.RangeSlider { id: control diff --git a/src/imports/controls/material/RangeSlider.qml b/src/imports/controls/material/RangeSlider.qml index c2672703..2a6e2176 100644 --- a/src/imports/controls/material/RangeSlider.qml +++ b/src/imports/controls/material/RangeSlider.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.6 -import QtQuick.Templates 2.1 as T +import QtQuick.Templates 2.2 as T import QtQuick.Controls.Material 2.1 import QtQuick.Controls.Material.impl 2.1 diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 78d9c9b3..97707b49 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -42,6 +42,7 @@ #include <QtQuickControls2/private/qquickcolorimageprovider_p.h> #include <QtQuickTemplates2/private/qquickbuttongroup_p.h> #include <QtQuickTemplates2/private/qquickcontainer_p.h> +#include <QtQuickTemplates2/private/qquickrangeslider_p.h> #include <QtQuickTemplates2/private/qquickslider_p.h> #include <QtQuickTemplates2/private/qquicktumbler_p.h> #include <QtQuickControls2/private/qquicktumblerview_p.h> @@ -143,6 +144,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterType(selector.select(QStringLiteral("ToolSeparator.qml")), uri, 2, 1, "ToolSeparator"); // QtQuick.Controls 2.2 (Qt 5.9) + qmlRegisterRevision<QQuickRangeSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickTumbler, 2>(uri, 2, 2); } diff --git a/src/imports/controls/universal/RangeSlider.qml b/src/imports/controls/universal/RangeSlider.qml index d66e26a7..5c53c053 100644 --- a/src/imports/controls/universal/RangeSlider.qml +++ b/src/imports/controls/universal/RangeSlider.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.6 -import QtQuick.Templates 2.1 as T +import QtQuick.Templates 2.2 as T import QtQuick.Controls.Universal 2.1 T.RangeSlider { diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 56fe8bc1..14d42078 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -198,6 +198,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) qmlRegisterType<QQuickTumbler, 1>(uri, 2, 1, "Tumbler"); // QtQuick.Templates 2.2 (Qt 5.9) + qmlRegisterRevision<QQuickRangeSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickTumbler, 2>(uri, 2, 2); } diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index 34654fe1..fb518b69 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -313,6 +313,7 @@ class QQuickRangeSliderPrivate : public QQuickControlPrivate public: QQuickRangeSliderPrivate() : + live(false), from(defaultFrom), to(defaultTo), stepSize(0), @@ -325,6 +326,7 @@ public: void updateHover(const QPointF &pos); + bool live; qreal from; qreal to; qreal stepSize; @@ -471,8 +473,10 @@ void QQuickRangeSlider::setTo(qreal to) If \l to is greater than \l from, the value of the first handle must be greater than the second, and vice versa. - Unlike \l {first.position}{position}, value is not updated while the - handle is dragged, but rather when it has been released. + Unlike \l {first.position}{position}, value is not updated by default + while the handle is dragged, but rather when it has been released. The + \l live property can be used to make the slider provide live updates + for value. The default value is \c 0.0. \row @@ -533,8 +537,10 @@ QQuickRangeSliderNode *QQuickRangeSlider::first() const If \l to is greater than \l from, the value of the first handle must be greater than the second, and vice versa. - Unlike \l {second.position}{position}, value is not updated while the - handle is dragged, but rather when it has been released. + Unlike \l {second.position}{position}, value is not updated by default + while the handle is dragged, but rather when it has been released. The + \l live property can be used to make the slider provide live updates + for value. The default value is \c 0.0. \row @@ -651,6 +657,33 @@ void QQuickRangeSlider::setOrientation(Qt::Orientation orientation) } /*! + \since QtQuick.Controls 2.2 + \qmlproperty bool QtQuick.Controls::RangeSlider::live + + This property holds whether the slider provides live updates for the \l first.value + and \l second.value properties while the respective handles are dragged. + + The default value is \c false. + + \sa first.value, second.value +*/ +bool QQuickRangeSlider::live() const +{ + Q_D(const QQuickRangeSlider); + return d->live; +} + +void QQuickRangeSlider::setLive(bool live) +{ + Q_D(QQuickRangeSlider); + if (d->live == live) + return; + + d->live = live; + emit liveChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::RangeSlider::setValues(real firstValue, real secondValue) Sets \l first.value and \l second.value with the given arguments. @@ -868,7 +901,10 @@ void QQuickRangeSlider::mouseMoveEvent(QMouseEvent *event) qreal pos = positionAt(this, pressedNode->handle(), event->pos()); if (d->snapMode == SnapAlways) pos = snapPosition(this, pos); - QQuickRangeSliderNodePrivate::get(pressedNode)->setPosition(pos); + if (d->live) + pressedNode->setValue(valueAt(this, pos)); + else + QQuickRangeSliderNodePrivate::get(pressedNode)->setPosition(pos); } } } diff --git a/src/quicktemplates2/qquickrangeslider_p.h b/src/quicktemplates2/qquickrangeslider_p.h index 1b102e87..08e68b0e 100644 --- a/src/quicktemplates2/qquickrangeslider_p.h +++ b/src/quicktemplates2/qquickrangeslider_p.h @@ -65,6 +65,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSlider : public QQuickControl Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) public: explicit QQuickRangeSlider(QQuickItem *parent = nullptr); @@ -94,6 +95,9 @@ public: Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); + bool live() const; + void setLive(bool live); + Q_INVOKABLE void setValues(qreal firstValue, qreal secondValue); Q_SIGNALS: @@ -102,6 +106,7 @@ Q_SIGNALS: void stepSizeChanged(); void snapModeChanged(); void orientationChanged(); + Q_REVISION(2) void liveChanged(); protected: void focusInEvent(QFocusEvent *event) override; diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index 392be018..f9e027d4 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -294,13 +294,15 @@ TestCase { function test_mouse_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal }, - { tag: "vertical", orientation: Qt.Vertical } + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } ] } function test_mouse(data) { - var control = sliderComponent.createObject(testCase, { orientation: data.orientation }) + var control = sliderComponent.createObject(testCase, { orientation: data.orientation, live: data.live }) verify(control) firstPressedSpy.target = control.first @@ -386,7 +388,7 @@ TestCase { compare(firstPressedSpy.count, 5) compare(secondPressedSpy.count, 2) compare(control.first.pressed, true) - compare(control.first.value, 0.0) + compare(control.first.value, data.live ? 0.5 : 0.0) compare(control.first.position, 0.5) compare(control.first.visualPosition, 0.5) compare(control.second.pressed, false) |