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 
0005     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0006 */
0007 
0008 
0009 import QtQuick 2.6
0010 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
0011 import QtQuick.Templates 2.15 as T
0012 import org.kde.kirigami 2.4 as Kirigami
0013 
0014 T.Slider {
0015     id: controlRoot
0016     Kirigami.Theme.colorSet: Kirigami.Theme.Button
0017 
0018     implicitWidth: background.horizontal ? Kirigami.Units.gridUnit * 12 : background.implicitWidth
0019     implicitHeight: background.horizontal ? background.implicitHeight : Kirigami.Units.gridUnit * 12
0020 
0021     hoverEnabled: true
0022     LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0023 
0024     handle: Item {
0025         anchors.verticalCenter: controlRoot.verticalCenter
0026     }
0027 
0028     snapMode: T.Slider.SnapOnRelease
0029 
0030     background: StylePrivate.StyleItem {
0031         // Rescale for extra precision. Adapts to the range of `from` & `to` to avoid integer overflow.
0032         property int factor: (Math.abs(controlRoot.from) < 100000 && Math.abs(controlRoot.to) < 100000)
0033             ? 10000 : 1
0034 
0035         control: controlRoot
0036         elementType: "slider"
0037         sunken: controlRoot.pressed
0038         implicitWidth: 200
0039         contentWidth: horizontal ? controlRoot.implicitWidth : (Kirigami.Settings.tabletMode ? 24 : 22)
0040         contentHeight: horizontal ? (Kirigami.Settings.tabletMode ? 24 : 22) : controlRoot.implicitHeight
0041         anchors.verticalCenter: controlRoot.verticalCenter
0042 
0043         maximum: factor * controlRoot.to
0044         minimum: factor * controlRoot.from
0045         step: factor * controlRoot.stepSize
0046         value: factor * controlRoot.value
0047         horizontal: controlRoot.orientation === Qt.Horizontal
0048         enabled: controlRoot.enabled
0049         hasFocus: controlRoot.activeFocus
0050         hover: controlRoot.hovered
0051         activeControl: controlRoot.stepSize > 0 ? "ticks" : ""
0052 
0053         // `wheelEnabled: true` doesn't work since it doesn't snap to tickmarks,
0054         // so we have to implement the scroll handling ourselves. See
0055         // https://bugreports.qt.io/browse/QTBUG-93081
0056         MouseArea {
0057             property int wheelDelta: 0
0058 
0059             anchors {
0060                 fill: parent
0061                 leftMargin: controlRoot.leftPadding
0062                 rightMargin: controlRoot.rightPadding
0063             }
0064 
0065             acceptedButtons: Qt.NoButton
0066 
0067             onWheel: {
0068                 const lastValue = controlRoot.value
0069                 const delta = wheel.angleDelta.y || wheel.angleDelta.x
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.decrease();
0076                 }
0077                 while (wheelDelta <= -120) {
0078                     wheelDelta += 120;
0079                     controlRoot.increase();
0080                 }
0081                 if (lastValue !== controlRoot.value) {
0082                     controlRoot.moved();
0083                 }
0084             }
0085         }
0086     }
0087 }