Warning, /plasma/plasma-mobile/components/mobileshell/qml/volumeosd/VolumeOSD.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org> 0003 * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de> 0004 * SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Controls as Controls 0011 import QtQuick.Layouts 0012 import QtQuick.Window 0013 0014 import org.kde.kirigami 2.20 as Kirigami 0015 import org.kde.plasma.components 3.0 as PlasmaComponents 0016 import org.kde.plasma.private.nanoshell 2.0 as NanoShell 0017 import org.kde.plasma.private.mobileshell as MobileShell 0018 import org.kde.plasma.private.mobileshell.state as MobileShellState 0019 0020 NanoShell.FullScreenOverlay { 0021 id: window 0022 0023 // used by context menus opened in the applet to not autoclose the osd 0024 property bool suppressActiveClose: false 0025 0026 // whether the applet is showing all devices 0027 property bool showFullApplet: false 0028 0029 visible: false 0030 0031 color: showFullApplet ? Qt.rgba(0, 0, 0, 0.6) : "transparent" 0032 Behavior on color { 0033 ColorAnimation {} 0034 } 0035 0036 function showOverlay() { 0037 if (!window.visible) { 0038 window.showFullApplet = false; 0039 window.showFullScreen(); 0040 hideTimer.restart(); 0041 } else if (!window.showFullApplet) { // don't autohide applet when the full applet is showing 0042 hideTimer.restart(); 0043 } 0044 } 0045 0046 onActiveChanged: { 0047 if (!active && !suppressActiveClose) { 0048 hideTimer.stop(); 0049 hideTimer.triggered(); 0050 } 0051 } 0052 0053 Timer { 0054 id: hideTimer 0055 interval: 3000 0056 running: false 0057 onTriggered: { 0058 window.close(); 0059 window.showFullApplet = false; 0060 } 0061 } 0062 0063 Flickable { 0064 id: flickable 0065 anchors.fill: parent 0066 contentHeight: cards.implicitHeight 0067 boundsBehavior: window.showFullApplet ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds 0068 0069 pressDelay: 50 0070 0071 MouseArea { 0072 // capture taps behind cards to close 0073 anchors.left: parent.left 0074 anchors.right: parent.right 0075 width: parent.width 0076 height: Math.max(cards.implicitHeight, window.height) 0077 onReleased: { 0078 hideTimer.stop(); 0079 hideTimer.triggered(); 0080 } 0081 0082 ColumnLayout { 0083 id: cards 0084 width: parent.width 0085 anchors.left: parent.left 0086 anchors.right: parent.right 0087 spacing: 0 0088 0089 // osd card 0090 PopupCard { 0091 id: osd 0092 Layout.topMargin: Kirigami.Units.gridUnit 0093 Layout.alignment: Qt.AlignHCenter 0094 0095 contentItem: RowLayout { 0096 id: containerLayout 0097 spacing: Kirigami.Units.smallSpacing 0098 0099 anchors.leftMargin: Kirigami.Units.smallSpacing * 2 0100 anchors.rightMargin: Kirigami.Units.smallSpacing 0101 0102 PlasmaComponents.ToolButton { 0103 icon.name: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high" 0104 text: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute") 0105 display: Controls.AbstractButton.IconOnly 0106 Layout.alignment: Qt.AlignVCenter 0107 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0108 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0109 Layout.rightMargin: Kirigami.Units.smallSpacing 0110 onClicked: muteVolume() 0111 } 0112 0113 PlasmaComponents.ProgressBar { 0114 id: volumeSlider 0115 Layout.fillWidth: true 0116 Layout.alignment: Qt.AlignVCenter 0117 Layout.rightMargin: Kirigami.Units.smallSpacing * 2 0118 value: MobileShell.AudioInfo.volumeValue 0119 from: 0 0120 to: MobileShell.AudioInfo.maxVolumePercent 0121 Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } } 0122 } 0123 0124 // Get the width of a three-digit number so we can size the label 0125 // to the maximum width to avoid the progress bar resizing itself 0126 TextMetrics { 0127 id: widestLabelSize 0128 text: i18n("100%") 0129 font: percentageLabel.font 0130 } 0131 0132 Kirigami.Heading { 0133 id: percentageLabel 0134 Layout.preferredWidth: widestLabelSize.width 0135 Layout.alignment: Qt.AlignVCenter 0136 Layout.rightMargin: Kirigami.Units.smallSpacing 0137 level: 3 0138 text: i18nc("Percentage value", "%1%", MobileShell.AudioInfo.volumeValue) 0139 0140 // Display a subtle visual indication that the volume might be 0141 // dangerously high 0142 // ------------------------------------------------ 0143 // Keep this in sync with the copies in plasma-pa:ListItemBase.qml 0144 // and plasma-pa:VolumeSlider.qml 0145 color: { 0146 if (MobileShell.AudioInfo.volumeValue <= 100) { 0147 return Kirigami.Theme.textColor 0148 } else if (MobileShell.AudioInfo.volumeValue > 100 && MobileShell.AudioInfo.volumeValue <= 125) { 0149 return Kirigami.Theme.neutralTextColor 0150 } else { 0151 return Kirigami.Theme.negativeTextColor 0152 } 0153 } 0154 } 0155 0156 PlasmaComponents.ToolButton { 0157 icon.name: "configure" 0158 text: i18n("Open audio settings") 0159 visible: opacity !== 0 0160 opacity: showFullApplet ? 1 : 0 0161 display: Controls.AbstractButton.IconOnly 0162 Layout.alignment: Qt.AlignVCenter 0163 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0164 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0165 Layout.rightMargin: Kirigami.Units.smallSpacing 0166 0167 Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration } } 0168 0169 onClicked: { 0170 let coords = mapToItem(flickable, 0, 0); 0171 MobileShellState.ShellDBusClient.openAppLaunchAnimation("audio-volume-high", i18n("Audio Settings"), coords.x, coords.y, Kirigami.Units.iconSizes.medium); 0172 MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_pulseaudio"); 0173 } 0174 } 0175 0176 PlasmaComponents.ToolButton { 0177 icon.name: window.showFullApplet ? "arrow-up" : "arrow-down" 0178 text: i18n("Toggle showing audio streams") 0179 display: Controls.AbstractButton.IconOnly 0180 Layout.alignment: Qt.AlignVCenter 0181 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0182 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0183 onClicked: { 0184 window.showFullApplet = !window.showFullApplet 0185 // don't autohide applet when full applet is shown 0186 if (window.showFullApplet) { 0187 hideTimer.stop(); 0188 } else { 0189 hideTimer.restart(); 0190 } 0191 } 0192 } 0193 } 0194 } 0195 0196 // other applet cards 0197 AudioApplet { 0198 id: applet 0199 Layout.topMargin: Kirigami.Units.gridUnit 0200 Layout.alignment: Qt.AlignHCenter 0201 Layout.preferredWidth: cards.width 0202 opacity: window.showFullApplet ? 1 : 0 0203 visible: opacity !== 0 0204 transform: Translate { 0205 y: window.showFullApplet ? 0 : -Kirigami.Units.gridUnit 0206 Behavior on y { NumberAnimation {} } 0207 } 0208 0209 Behavior on opacity { NumberAnimation {} } 0210 } 0211 } 0212 } 0213 } 0214 }