Warning, /plasma/plasma-bigscreen/kcms/audio-device-chooser/ui/delegates/VolumeObject.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     SPDX-FileCopyrightText: 2019 Aditya Mehra <aix.m@outlook.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 import QtQuick 2.14
0010 import QtQuick.Layouts 1.14
0011 import org.kde.plasma.components 3.0 as PlasmaComponents
0012 import org.kde.kirigami as Kirigami
0013 import org.kde.plasma.private.volume 0.1
0014 
0015 ColumnLayout {
0016     //Layout.fillWidth: true
0017     //Layout.fillHeight: true
0018     //Layout.margins: Kirigami.Units.largeSpacing
0019 
0020     function increaseVal(){
0021         var l = 0
0022         l = slider.position + 0.05
0023         slider.value = slider.valueAt(l);
0024 
0025     }
0026 
0027     function decreaseVal(){
0028         var l = 0
0029         l = slider.position - 0.05
0030         slider.value = slider.valueAt(l);
0031     }
0032 
0033     SinkModel {
0034         id: paSinkModel
0035     }
0036 
0037     SourceModel {
0038         id: paSourceModel
0039     }
0040 
0041     Timer {
0042         id: updateTimer
0043         interval: 200
0044         onTriggered: slider.value = vol
0045     }
0046 
0047     PlasmaComponents.Label {
0048         id: label
0049         visible: text.length > 0
0050         Layout.fillWidth: true
0051         Layout.preferredHeight: Kirigami.Units.gridUnit * 1
0052         wrapMode: Text.WordWrap
0053         //horizontalAlignment: Text.AlignHCenter
0054         //verticalAlignment: Text.AlignVCenter
0055         maximumLineCount: 1
0056         elide: Text.ElideRight
0057         color: Kirigami.Theme.textColor
0058         text: i18n("Adjust Volume")
0059     }
0060 
0061     RowLayout {
0062         Layout.fillWidth: true
0063         Layout.fillHeight: true
0064 
0065         Kirigami.Icon {
0066             Layout.alignment: Qt.AlignHCenter
0067             Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0068             Layout.preferredWidth: Layout.preferredHeight
0069             source: "audio-card"
0070         }
0071 
0072         PlasmaComponents.Slider {
0073             id: slider
0074             Layout.alignment: Qt.AlignVCenter
0075             // Helper properties to allow async slider updates.
0076             // While we are sliding we must not react to value updates
0077             // as otherwise we can easily end up in a loop where value
0078             // changes trigger volume changes trigger value changes.
0079             property int volume: Volume
0080             property bool ignoreValueChange: true
0081             Layout.fillWidth: true
0082             from: PulseAudio.MinimalVolume
0083             to: PulseAudio.NormalVolume
0084             // TODO: implement a way to hide tickmarks
0085             // stepSize: to / (PulseAudio.MaximalVolume / PulseAudio.NormalVolume * 100.0)
0086             visible: HasVolume
0087             enabled: VolumeWritable
0088             opacity: Muted ? 0.5 : 1
0089 
0090             Component.onCompleted: {
0091                 ignoreValueChange = false;
0092             }
0093 
0094             onVolumeChanged: {
0095                 var oldIgnoreValueChange = ignoreValueChange;
0096                 ignoreValueChange = true;
0097                 value = Volume;
0098                 ignoreValueChange = oldIgnoreValueChange;
0099             }
0100 
0101             onValueChanged: {
0102                 Volume = value;
0103             }
0104 
0105             onPressedChanged: {
0106                 if (!pressed) {
0107                     // Make sure to sync the volume once the button was
0108                     // released.
0109                     // Otherwise it might be that the slider is at v10
0110                     // whereas PA rejected the volume change and is
0111                     // still at v15 (e.g.).
0112                     updateTimer.restart();
0113                 }
0114             }
0115         }
0116 
0117         PlasmaComponents.Label {
0118             id: percentLabel
0119             readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value
0120             Layout.preferredWidth: contentWidth + Kirigami.Units.largeSpacing
0121             horizontalAlignment: Text.AlignHCenter
0122             verticalAlignment: Text.AlignVCenter
0123             text: i18nc("volume percentage", "%1%", Math.round(value / PulseAudio.NormalVolume * 100.0))
0124         }
0125     }
0126 }