Warning, /multimedia/kasts/src/qml/VolumeSlider.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * SPDX-FileCopyrightText: 2023 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Controls as Controls 0009 import QtQuick.Layouts 0010 import QtQml.Models 0011 0012 import org.kde.kirigami as Kirigami 0013 import org.kde.kmediasession 0014 0015 import org.kde.kasts 0016 0017 Controls.Slider { 0018 id: volumeSlider 0019 height: Kirigami.Units.gridUnit * 7 0020 Layout.alignment: Qt.AlignHCenter 0021 Layout.preferredHeight: height 0022 Layout.maximumHeight: height 0023 Layout.topMargin: Kirigami.Units.smallSpacing 0024 orientation: Qt.Vertical 0025 padding: 0 0026 enabled: !AudioManager.muted && AudioManager.PlaybackState != AudioManager.StoppedState && AudioManager.canPlay 0027 from: 0 0028 to: 100 0029 value: AudioManager.volume 0030 onMoved: AudioManager.volume = value 0031 0032 onPressedChanged: { 0033 tooltip.delay = pressed ? 0 : Kirigami.Units.toolTipDelay 0034 } 0035 0036 readonly property int wheelEffect: 5 0037 0038 Controls.ToolTip { 0039 id: tooltip 0040 x: volumeSlider.x - volumeSlider.width / 2 - width 0041 y: volumeSlider.visualPosition * volumeSlider.height - height / 2 0042 visible: volumeSlider.pressed || sliderMouseArea.containsMouse 0043 // delay is actually handled in volumeSlider.onPressedChanged, because property bindings aren't immediate 0044 delay: volumeSlider.pressed ? 0 : Kirigami.Units.toolTipDelay 0045 closePolicy: Controls.Popup.NoAutoClose 0046 timeout: -1 0047 text: i18nc("Volume as a percentage", "%1%", Math.round(volumeSlider.value)) 0048 } 0049 0050 MouseArea { 0051 id: sliderMouseArea 0052 anchors.fill: parent 0053 acceptedButtons: Qt.NoButton 0054 hoverEnabled: true 0055 onWheel: (wheel) => { 0056 // Can't use Slider's built-in increase() and decrease() functions here 0057 // since they go in increments of 0.1 when the slider's stepSize is not 0058 // defined, which is much too slow. And we don't define a stepSize for 0059 // the slider because if we do, it gets gets tickmarks which look ugly. 0060 if (wheel.angleDelta.y > 0) { 0061 // Increase volume 0062 volumeSlider.value = Math.min(volumeSlider.to, volumeSlider.value + volumeSlider.wheelEffect); 0063 0064 } else { 0065 // Decrease volume 0066 volumeSlider.value = Math.max(volumeSlider.from, volumeSlider.value - volumeSlider.wheelEffect); 0067 } 0068 AudioManager.volume = volumeSlider.value 0069 } 0070 } 0071 } 0072