Warning, /plasma/plasma-pa/src/kcm/ui/VolumeSlider.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org> 0003 SPDX-FileCopyrightText: 2019 Sefa Eyeoglu <contact@scrumplex.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Layouts 0010 import QtQuick.Controls as QQC2 0011 import org.kde.kirigami as Kirigami 0012 0013 import org.kde.plasma.private.volume 0014 0015 RowLayout { 0016 id: sliderRow 0017 0018 signal moved() 0019 0020 property alias value: slider.value 0021 0022 property int channel: -1 0023 0024 QQC2.Slider { 0025 id: slider 0026 0027 Layout.fillWidth: true 0028 0029 value: Volume 0030 from: PulseAudio.MinimalVolume 0031 to: config.raiseMaximumVolume ? PulseAudio.MaximalVolume /* 150 */ : PulseAudio.NormalVolume /* 100 */ 0032 property real myStepSize: PulseAudio.NormalVolume / 100.0 * config.volumeStep 0033 // qqc2-desktop-stlye implements scrolling via inscrease()/decrease() functions 0034 // they default to steps of 0.1 when stepSize is not set 0035 // override them to get scrolling working 0036 function increase () { value = value + myStepSize } 0037 function decrease () { value = value - myStepSize } 0038 visible: HasVolume 0039 enabled: VolumeWritable 0040 opacity: Muted ? 0.5 : 1 0041 onMoved: { 0042 // Since it is not possible to use stepSize without tickmarks being displayed, force 1% steps 0043 // Unfortunately without stepSize, it cannot snap visually whilst scrolling by changing value instead of Volume as it breaks the binding 0044 let volume = Math.round(value * 100 / PulseAudio.NormalVolume) * PulseAudio.NormalVolume / 100 0045 if (channel == -1) { 0046 Volume = volume 0047 Muted = volume === 0; 0048 } else { 0049 delegate.pulseObject.setChannelVolume(channel, volume); 0050 0051 // volumes are updated async, so we'll just assume it worked here 0052 let newChannelVolumes = ChannelVolumes; 0053 newChannelVolumes[index] = value; 0054 Muted = newChannelVolumes.every(volume => volume === 0); 0055 } 0056 0057 sliderRow.moved() 0058 } 0059 0060 } 0061 0062 QQC2.Label { 0063 id: percentText 0064 readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value 0065 readonly property real displayValue: Math.round(value / PulseAudio.NormalVolume * 100.0) 0066 Layout.alignment: Qt.AlignHCenter 0067 Layout.minimumWidth: percentMetrics.advanceWidth 0068 horizontalAlignment: Qt.AlignRight 0069 text: i18ndc("kcm_pulseaudio", "volume percentage", "%1%", displayValue) 0070 // Display a subtle visual indication that the volume might be 0071 // dangerously high 0072 // ------------------------------------------------ 0073 // Keep this in sync with the copies in ListItemBase.qml 0074 // and plasma-workspace:OSDItem.qml 0075 color: { 0076 if (displayValue <= 100) { 0077 return Kirigami.Theme.textColor 0078 } else if (displayValue > 100 && displayValue <= 125) { 0079 return Kirigami.Theme.neutralTextColor 0080 } else { 0081 return Kirigami.Theme.negativeTextColor 0082 } 0083 } 0084 } 0085 0086 TextMetrics { 0087 id: percentMetrics 0088 font: percentText.font 0089 text: i18ndc("kcm_pulseaudio", "only used for sizing, should be widest possible string", "100%") 0090 } 0091 }