summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-29 13:04:10 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-29 13:19:28 +0000
commitda0570d1ddf6c786b4bfdd0a1172b36ecc66f2a2 (patch)
tree210a71ded0651cf6e6cbe110ecdc7cc8a49cd59c
parent661bba4f11666d5d9018a6a1d16a71c324bdf123 (diff)
Dial: add missing wheel handling
[ChangeLog][Controls][Dial] Added support for wheel handling when wheelEnabled is set to true. Change-Id: If0bc2f0ea9d7cde7726739cdfdbd795c908981f0 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickdial.cpp14
-rw-r--r--src/quicktemplates2/qquickdial_p.h2
-rw-r--r--tests/auto/controls/data/tst_dial.qml47
3 files changed, 63 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp
index 79aff781..2b9f83a4 100644
--- a/src/quicktemplates2/qquickdial.cpp
+++ b/src/quicktemplates2/qquickdial.cpp
@@ -606,6 +606,20 @@ void QQuickDial::mouseUngrabEvent()
setPressed(false);
}
+void QQuickDial::wheelEvent(QWheelEvent *event)
+{
+ Q_D(QQuickDial);
+ QQuickControl::wheelEvent(event);
+ if (d->wheelEnabled) {
+ const qreal oldValue = d->value;
+ const QPointF angle = event->angleDelta();
+ const qreal delta = (qFuzzyIsNull(angle.y()) ? angle.x() : angle.y()) / QWheelEvent::DefaultDeltasPerStep;
+ const qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize;
+ setValue(oldValue + step * delta);
+ event->setAccepted(!qFuzzyCompare(d->value, oldValue));
+ }
+}
+
void QQuickDial::mirrorChange()
{
QQuickControl::mirrorChange();
diff --git a/src/quicktemplates2/qquickdial_p.h b/src/quicktemplates2/qquickdial_p.h
index 2d87d6d9..291a6ac2 100644
--- a/src/quicktemplates2/qquickdial_p.h
+++ b/src/quicktemplates2/qquickdial_p.h
@@ -132,6 +132,8 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseUngrabEvent() override;
+ void wheelEvent(QWheelEvent *event) override;
+
void mirrorChange() override;
void componentComplete() override;
diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml
index e6446d3e..d0129755 100644
--- a/tests/auto/controls/data/tst_dial.qml
+++ b/tests/auto/controls/data/tst_dial.qml
@@ -356,4 +356,51 @@ TestCase {
fuzzyCompare(dial.value, data.values[2], fuzz);
fuzzyCompare(dial.position, data.positions[2], fuzz);
}
+
+ function test_wheel_data() {
+ return [
+ { tag: "horizontal", orientation: Qt.Horizontal, dx: 120, dy: 0 },
+ { tag: "vertical", orientation: Qt.Vertical, dx: 0, dy: 120 }
+ ]
+ }
+
+ function test_wheel(data) {
+ var control = dialComponent.createObject(testCase, {wheelEnabled: true, orientation: data.orientation})
+ verify(control)
+
+ compare(control.value, 0.0)
+
+ mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy)
+ compare(control.value, 0.1)
+ compare(control.position, 0.1)
+
+ control.stepSize = 0.2
+
+ mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy)
+ compare(control.value, 0.3)
+ compare(control.position, 0.3)
+
+ control.stepSize = 10.0
+
+ mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy)
+ compare(control.value, 0.0)
+ compare(control.position, 0.0)
+
+ control.to = 10.0
+ control.stepSize = 5.0
+
+ mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy)
+ compare(control.value, 5.0)
+ compare(control.position, 0.5)
+
+ mouseWheel(control, control.width / 2, control.height / 2, 0.5 * data.dx, 0.5 * data.dy)
+ compare(control.value, 7.5)
+ compare(control.position, 0.75)
+
+ mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy)
+ compare(control.value, 2.5)
+ compare(control.position, 0.25)
+
+ control.destroy()
+ }
}