Warning, /multimedia/elisa/src/qml/VolumeSlider.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 
0005    SPDX-License-Identifier: LGPL-3.0-or-later
0006  */
0007 
0008 import QtQuick 2.7
0009 import QtQuick.Layouts 1.2
0010 import QtQuick.Controls 2.3
0011 import org.kde.kirigami 2.5 as Kirigami
0012 import org.kde.elisa 1.0
0013 
0014 Slider {
0015     id: volumeSlider
0016     property bool muted
0017 
0018     from: 0
0019     to: 100
0020 
0021     enabled: !muted
0022 
0023     readonly property int wheelEffect: 5
0024 
0025     onPressedChanged: {
0026         tooltip.delay = pressed ? 0 : Kirigami.Units.toolTipDelay
0027     }
0028 
0029     MouseArea {
0030         id: sliderMouseArea
0031         anchors.fill: parent
0032         acceptedButtons: Qt.NoButton
0033         hoverEnabled: true
0034         onWheel: wheel => {
0035             // Can't use Slider's built-in increase() and decrease() functions here
0036             // since they go in increments of 0.1 when the slider's stepSize is not
0037             // defined, which is much too slow. And we don't define a stepSize for
0038             // the slider because if we do, it gets gets tickmarks which look ugly.
0039             if (wheel.angleDelta.y > 0) {
0040                 // Increase volume
0041                 volumeSlider.value = Math.min(volumeSlider.to, volumeSlider.value + wheelEffect);
0042 
0043             } else {
0044                 // Decrease volume
0045                 volumeSlider.value = Math.max(volumeSlider.from, volumeSlider.value - wheelEffect);
0046             }
0047         }
0048     }
0049 
0050     ToolTip {
0051         id: tooltip
0052         x: volumeSlider.visualPosition * volumeSlider.width - width / 2
0053         visible: volumeSlider.pressed || sliderMouseArea.containsMouse
0054         // delay is actually handled in volumeSlider.onPressedChanged, because property bindings aren't immediate
0055         delay: volumeSlider.pressed ? 0 : Kirigami.Units.toolTipDelay
0056         closePolicy: Popup.NoAutoClose
0057         timeout: -1
0058         text: i18nc("Volume as a percentage", "%1%", Math.round(volumeSlider.value))
0059     }
0060 }