Warning, /multimedia/elisa/src/qml/AccessibleSlider.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 SPDX-FileCopyrightText: 2021 (c) Devin Lin <espidev@gmail.com>
0004 SPDX-FileCopyrightText: 2024 (c) Jack Hill <jackhill3103@gmail.com>
0005
0006 SPDX-License-Identifier: LGPL-3.0-or-later
0007 */
0008
0009 import QtQuick
0010 import QtQuick.Controls as QQC2
0011
0012 /**
0013 * A slider that allows setting different step sizes for arrow keys and mouse wheels.
0014 *
0015 * Setting `stepSize` gives the slider tickmarks, which look unappealing for lots of steps.
0016 * If `stepSize` is not set then the Slider's built-in increase() and decrease() functions
0017 * use increments of 0.1, which is much too small for our usage. Hence we have our own
0018 * implementation here. This also means we can define separate step sizes for the arrow keys
0019 * and mouse wheel.
0020 *
0021 * NOTE: The Accessible attached property reads `stepSize` to the user, which may not be used
0022 * when incrementing/decrementing.
0023 */
0024 QQC2.Slider {
0025 id: root
0026
0027 /**
0028 * The step size for arrow keys
0029 */
0030 property real keyStepSize: stepSize
0031
0032 /**
0033 * The step size for the mouse wheel
0034 */
0035 property real wheelStepSize: stepSize
0036
0037 readonly property real __keyStepSize: keyStepSize === null ? 0 : keyStepSize
0038 readonly property real __wheelStepSize: wheelStepSize === null ? 0 : wheelStepSize
0039
0040 function __move(step: real) {
0041 value = Math.max(from, Math.min(value + step, to))
0042 moved()
0043 }
0044
0045 Accessible.onDecreaseAction: __move(-__keyStepSize)
0046 Accessible.onIncreaseAction: __move(__keyStepSize)
0047 Keys.onLeftPressed: __move(-__keyStepSize)
0048 Keys.onRightPressed: __move(__keyStepSize)
0049
0050 MouseArea {
0051 anchors.fill: parent
0052 acceptedButtons: Qt.NoButton
0053 onWheel: wheel => root.__move(root.__wheelStepSize * (wheel.angleDelta.y > 0 ? 1 : -1))
0054 }
0055 }