diff options
-rw-r--r-- | src/imports/controls/Dial.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/material/Dial.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/qtquickcontrols2plugin.cpp | 2 | ||||
-rw-r--r-- | src/imports/controls/universal/Dial.qml | 2 | ||||
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdial.cpp | 46 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdial_p.h | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_dial.qml | 18 |
8 files changed, 63 insertions, 17 deletions
diff --git a/src/imports/controls/Dial.qml b/src/imports/controls/Dial.qml index cc202772..027a6fb5 100644 --- a/src/imports/controls/Dial.qml +++ b/src/imports/controls/Dial.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.Dial { id: control diff --git a/src/imports/controls/material/Dial.qml b/src/imports/controls/material/Dial.qml index 7fbf351c..078a45c3 100644 --- a/src/imports/controls/material/Dial.qml +++ b/src/imports/controls/material/Dial.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 97707b49..772429a5 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/qquickdial_p.h> #include <QtQuickTemplates2/private/qquickrangeslider_p.h> #include <QtQuickTemplates2/private/qquickslider_p.h> #include <QtQuickTemplates2/private/qquicktumbler_p.h> @@ -144,6 +145,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<QQuickDial, 2>(uri, 2, 2); 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/Dial.qml b/src/imports/controls/universal/Dial.qml index 64dca3da..4e90bab5 100644 --- a/src/imports/controls/universal/Dial.qml +++ b/src/imports/controls/universal/Dial.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.Dial { diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 14d42078..e9ee1037 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<QQuickDial, 2>(uri, 2, 2); qmlRegisterRevision<QQuickRangeSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickSlider, 2>(uri, 2, 2); qmlRegisterRevision<QQuickTumbler, 2>(uri, 2, 2); diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp index 48d02faa..eb60c93c 100644 --- a/src/quicktemplates2/qquickdial.cpp +++ b/src/quicktemplates2/qquickdial.cpp @@ -95,6 +95,7 @@ public: pressed(false), snapMode(QQuickDial::NoSnap), wrap(false), + live(false), handle(nullptr) { } @@ -116,6 +117,7 @@ public: QPoint pressPoint; QQuickDial::SnapMode snapMode; bool wrap; + bool live; QQuickItem *handle; }; @@ -246,11 +248,12 @@ void QQuickDial::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. The value is updated after the value has been chosen - and the dial has been released. + Unlike the \l position property, the \c value is not updated by default + while the handle is dragged. The value is updated after the value has + been chosen and the dial has been released. The \l live property can be + used to make the dial provide live updates for the \c value property. - \sa position + \sa position, live */ qreal QQuickDial::value() const { @@ -445,6 +448,33 @@ void QQuickDial::setPressed(bool pressed) } /*! + \since QtQuick.Controls 2.2 + \qmlproperty bool QtQuick.Controls::Dial::live + + This property holds whether the dial provides live updates for the \l value + property while the handle is dragged. + + The default value is \c false. + + \sa value +*/ +bool QQuickDial::live() const +{ + Q_D(const QQuickDial); + return d->live; +} + +void QQuickDial::setLive(bool live) +{ + Q_D(QQuickDial); + if (d->live == live) + return; + + d->live = live; + emit liveChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::Dial::increase() Increases the value by \l stepSize, or \c 0.1 if stepSize is not defined. @@ -571,8 +601,12 @@ void QQuickDial::mouseMoveEvent(QMouseEvent *event) if (d->snapMode == SnapAlways) pos = d->snapPosition(pos); - if (d->wrap || (!d->wrap && !d->isLargeChange(event->pos(), pos))) - d->setPosition(pos); + if (d->wrap || (!d->wrap && !d->isLargeChange(event->pos(), pos))) { + if (d->live) + setValue(d->valueAt(pos)); + else + d->setPosition(pos); + } } } diff --git a/src/quicktemplates2/qquickdial_p.h b/src/quicktemplates2/qquickdial_p.h index 2d87d6d9..17a44b7a 100644 --- a/src/quicktemplates2/qquickdial_p.h +++ b/src/quicktemplates2/qquickdial_p.h @@ -69,6 +69,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDial : public QQuickControl Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged FINAL) Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) public: @@ -106,6 +107,9 @@ public: bool isPressed() const; void setPressed(bool pressed); + bool live() const; + void setLive(bool live); + QQuickItem *handle() const; void setHandle(QQuickItem *handle); @@ -123,6 +127,7 @@ Q_SIGNALS: void snapModeChanged(); void wrapChanged(); void pressedChanged(); + Q_REVISION(2) void liveChanged(); void handleChanged(); protected: diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml index e6446d3e..6dd65593 100644 --- a/tests/auto/controls/data/tst_dial.qml +++ b/tests/auto/controls/data/tst_dial.qml @@ -172,9 +172,10 @@ TestCase { function test_dragging_data() { return [ - { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0 }, - { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0 }, - { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0 } + { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: false }, + { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0, live: false }, + { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0, live: false }, + { tag: "live", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: true } ] } @@ -183,32 +184,35 @@ TestCase { verify(dial.wrap); dial.from = data.from; dial.to = data.to; + dial.live = data.live; valueSpy.target = dial; verify(valueSpy.valid); + var minimumExpectedValueCount = data.live ? 2 : 1; + // drag to the left mouseDrag(dial, dial.width / 2, dial.height / 2, -dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.leftValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); // drag to the top mouseDrag(dial, dial.width / 2, dial.height / 2, 0, -dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.topValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); // drag to the right mouseDrag(dial, dial.width / 2, dial.height / 2, dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.rightValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); // drag to the bottom (* 0.6 to ensure we don't go over to the minimum position) mouseDrag(dial, dial.width / 2, dial.height / 2, 10, dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.bottomValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); } |