diff options
| -rw-r--r-- | src/controls/Private/qquickrangemodel.cpp | 18 | ||||
| -rw-r--r-- | src/controls/Private/qquickrangemodel_p.h | 2 | ||||
| -rw-r--r-- | src/controls/Slider.qml | 16 | ||||
| -rw-r--r-- | tests/auto/controls/data/tst_slider.qml | 14 |
4 files changed, 43 insertions, 7 deletions
diff --git a/src/controls/Private/qquickrangemodel.cpp b/src/controls/Private/qquickrangemodel.cpp index ee1ade32c..356fe0804 100644 --- a/src/controls/Private/qquickrangemodel.cpp +++ b/src/controls/Private/qquickrangemodel.cpp @@ -521,4 +521,22 @@ void QQuickRangeModel::toMaximum() setValue(d->maximum); } +void QQuickRangeModel::increaseSingleStep() +{ + Q_D(const QQuickRangeModel); + if (qFuzzyIsNull(d->stepSize)) + setValue(value() + (d->maximum - d->minimum)/10.0); + else + setValue(value() + d->stepSize); +} + +void QQuickRangeModel::decreaseSingleStep() +{ + Q_D(const QQuickRangeModel); + if (qFuzzyIsNull(d->stepSize)) + setValue(value() - (d->maximum - d->minimum)/10.0); + else + setValue(value() - d->stepSize); +} + QT_END_NAMESPACE diff --git a/src/controls/Private/qquickrangemodel_p.h b/src/controls/Private/qquickrangemodel_p.h index a15843d70..6a05f22a1 100644 --- a/src/controls/Private/qquickrangemodel_p.h +++ b/src/controls/Private/qquickrangemodel_p.h @@ -97,6 +97,8 @@ public Q_SLOTS: void toMaximum(); void setValue(qreal value); void setPosition(qreal position); + void increaseSingleStep(); + void decreaseSingleStep(); Q_SIGNALS: void valueChanged(qreal value); diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml index ffea986c4..2838ed7e6 100644 --- a/src/controls/Slider.qml +++ b/src/controls/Slider.qml @@ -177,13 +177,21 @@ Control { activeFocusOnTab: true Accessible.role: Accessible.Slider + /*! \internal */ + function accessibleIncreaseAction() { + range.increaseSingleStep() + } + /*! \internal */ + function accessibleDecreaseAction() { + range.decreaseSingleStep() + } style: Qt.createComponent(Settings.style + "/SliderStyle.qml", slider) - Keys.onRightPressed: if (__horizontal) value += (maximumValue - minimumValue)/10.0 - Keys.onLeftPressed: if (__horizontal) value -= (maximumValue - minimumValue)/10.0 - Keys.onUpPressed: if (!__horizontal) value += (maximumValue - minimumValue)/10.0 - Keys.onDownPressed: if (!__horizontal) value -= (maximumValue - minimumValue)/10.0 + Keys.onRightPressed: if (__horizontal) range.increaseSingleStep() + Keys.onLeftPressed: if (__horizontal) range.decreaseSingleStep() + Keys.onUpPressed: if (!__horizontal) range.increaseSingleStep() + Keys.onDownPressed: if (!__horizontal) range.decreaseSingleStep() RangeModel { id: range diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index e56145668..3836fdde4 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -100,12 +100,20 @@ Item { slider.minimumValue = 0 slider.value = 1 slider.stepSize = 1 - var keyStep = 2 // (maximumValue - minimumValue)/10.0 keyPress(Qt.Key_Right) keyPress(Qt.Key_Right) - compare(slider.value, 1 + keyStep * 2) + compare(slider.value, 1 + slider.stepSize * 2) keyPress(Qt.Key_Left) - compare(slider.value, 1 + keyStep) + compare(slider.value, 1 + slider.stepSize) + + slider.stepSize = 5 + slider.value = 15 + keyPress(Qt.Key_Right) + compare(slider.value, 20) + keyPress(Qt.Key_Right) + compare(slider.value, 20) + keyPress(Qt.Key_Left) + compare(slider.value, 15) slider.destroy() } |
