Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/Slider.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
0003 SPDX-FileCopyrightText: 2017 The Qt Company Ltd.
0004 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0005
0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0007 */
0008
0009 import QtQuick
0010 import QtQuick.Templates as T
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.desktop.private as Private
0013 import org.kde.qqc2desktopstyle.private as StylePrivate
0014
0015 T.Slider {
0016 id: controlRoot
0017
0018 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0019
0020 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0021 implicitContentWidth + leftPadding + rightPadding)
0022 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0023 implicitContentHeight + topPadding + bottomPadding)
0024
0025 hoverEnabled: true
0026
0027 handle: Private.DefaultSliderHandle {
0028 control: controlRoot
0029 }
0030
0031 snapMode: T.Slider.SnapOnRelease
0032
0033 background: StylePrivate.StyleItem {
0034 control: controlRoot
0035 elementType: "slider"
0036 sunken: controlRoot.pressed
0037
0038 minimum: 0
0039 maximum: 100000
0040 step: 100000 * (controlRoot.stepSize / (controlRoot.to - controlRoot.from))
0041 value: 100000 * position
0042
0043 horizontal: controlRoot.orientation === Qt.Horizontal
0044 enabled: controlRoot.enabled
0045 hasFocus: controlRoot.activeFocus
0046 hover: controlRoot.hovered
0047 activeControl: controlRoot.stepSize > 0 ? "ticks" : ""
0048
0049 // `wheelEnabled: true` doesn't work since it doesn't snap to tickmarks,
0050 // so we have to implement the scroll handling ourselves. See
0051 // https://bugreports.qt.io/browse/QTBUG-93081
0052 MouseArea {
0053 property int wheelDelta: 0
0054
0055 anchors {
0056 fill: parent
0057 leftMargin: controlRoot.leftPadding
0058 rightMargin: controlRoot.rightPadding
0059 }
0060 LayoutMirroring.enabled: false
0061
0062 acceptedButtons: Qt.NoButton
0063
0064 onWheel: wheel => {
0065 const lastValue = controlRoot.value
0066 // We want a positive delta to increase the slider for up/right scrolling,
0067 // independently of the scrolling inversion setting
0068 // The x-axis is also inverted (scrolling right produce negative values)
0069 const delta = (wheel.angleDelta.y || -wheel.angleDelta.x) * (wheel.inverted ? -1 : 1)
0070 wheelDelta += delta;
0071 // magic number 120 for common "one click"
0072 // See: https://doc.qt.io/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
0073 while (wheelDelta >= 120) {
0074 wheelDelta -= 120;
0075 controlRoot.increase();
0076 }
0077 while (wheelDelta <= -120) {
0078 wheelDelta += 120;
0079 controlRoot.decrease();
0080 }
0081 if (lastValue !== controlRoot.value) {
0082 controlRoot.moved();
0083 }
0084 }
0085 }
0086 }
0087 }