Slider: add wheel support
Change-Id: I413d8c853bfe3cc748584dfebd28172ead89d638 Task-number: QTBUG-50221 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
This commit is contained in:
parent
1d5b91dd2c
commit
d0ab538c1f
|
@ -565,6 +565,20 @@ void QQuickSlider::mouseUngrabEvent()
|
|||
setPressed(false);
|
||||
}
|
||||
|
||||
void QQuickSlider::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
Q_D(QQuickSlider);
|
||||
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 QQuickSlider::mirrorChange()
|
||||
{
|
||||
QQuickControl::mirrorChange();
|
||||
|
|
|
@ -133,6 +133,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;
|
||||
|
||||
|
|
|
@ -471,4 +471,51 @@ TestCase {
|
|||
|
||||
control.destroy()
|
||||
}
|
||||
|
||||
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 = slider.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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue