shift-shell/components/mobileshell/qml/volumeosd/VolumeOSD.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

229 lines
9.3 KiB
QML
Raw Normal View History

2021-06-05 03:40:54 +00:00
/*
* SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
* SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
import QtQuick.Window
2023-03-03 05:48:24 +00:00
import Qt5Compat.GraphicalEffects
2021-06-05 03:40:54 +00:00
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtra
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtra
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import org.kde.plasma.private.mobileshell.state 1.0 as MobileShellState
2021-06-05 03:40:54 +00:00
import "../dataproviders" as DataProviders
Window {
2021-06-05 03:40:54 +00:00
id: window
required property int volume
// used by context menus opened in the applet to not autoclose the osd
property bool suppressActiveClose: false
// whether the applet is showing all devices
property bool showFullApplet: false
2021-06-05 03:40:54 +00:00
visible: false
2021-06-05 03:40:54 +00:00
color: showFullApplet ? Qt.rgba(0, 0, 0, 0.6) : "transparent"
Behavior on color {
ColorAnimation {}
}
function showOverlay() {
if (!window.visible) {
window.showFullApplet = false;
window.showFullScreen();
2021-06-05 03:40:54 +00:00
hideTimer.restart();
} else if (!window.showFullApplet) { // don't autohide applet when the full applet is showing
hideTimer.restart();
}
}
onActiveChanged: {
if (!active && !suppressActiveClose) {
hideTimer.stop();
hideTimer.triggered();
}
}
Timer {
id: hideTimer
interval: 3000
running: false
onTriggered: {
window.close();
window.showFullApplet = false;
}
}
DataProviders.AudioInfo {
id: audioInfo
}
2021-06-05 03:40:54 +00:00
Flickable {
id: flickable
anchors.fill: parent
contentHeight: cards.implicitHeight
boundsBehavior: window.showFullApplet ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
2021-06-05 03:40:54 +00:00
pressDelay: 50
2021-06-05 03:40:54 +00:00
MouseArea {
// capture taps behind cards to close
anchors.left: parent.left
anchors.right: parent.right
width: parent.width
height: Math.max(cards.implicitHeight, window.height)
onReleased: {
hideTimer.stop();
hideTimer.triggered();
}
2021-06-05 03:40:54 +00:00
ColumnLayout {
id: cards
width: parent.width
anchors.left: parent.left
anchors.right: parent.right
spacing: 0
2021-06-05 03:40:54 +00:00
// osd card
PopupCard {
id: osd
Layout.topMargin: PlasmaCore.Units.largeSpacing
Layout.alignment: Qt.AlignHCenter
2021-06-05 03:40:54 +00:00
contentItem: RowLayout {
id: containerLayout
spacing: PlasmaCore.Units.smallSpacing
anchors.leftMargin: PlasmaCore.Units.smallSpacing * 2
anchors.rightMargin: PlasmaCore.Units.smallSpacing
2021-06-05 03:40:54 +00:00
PlasmaComponents.ToolButton {
icon.name: !audioInfo.paSinkModel.preferredSink || audioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high"
text: !audioInfo.paSinkModel.preferredSink || audioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute")
2021-06-05 03:40:54 +00:00
display: Controls.AbstractButton.IconOnly
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
Layout.rightMargin: PlasmaCore.Units.smallSpacing
onClicked: muteVolume()
}
2021-06-05 03:40:54 +00:00
PlasmaComponents.ProgressBar {
id: volumeSlider
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: PlasmaCore.Units.smallSpacing * 2
value: window.volume
from: 0
to: 100
Behavior on value { NumberAnimation { duration: PlasmaCore.Units.shortDuration } }
}
2021-06-05 03:40:54 +00:00
// Get the width of a three-digit number so we can size the label
// to the maximum width to avoid the progress bar resizing itself
TextMetrics {
id: widestLabelSize
text: i18n("100%")
font: percentageLabel.font
}
PlasmaExtra.Heading {
id: percentageLabel
Layout.preferredWidth: widestLabelSize.width
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: PlasmaCore.Units.smallSpacing
level: 3
text: i18nc("Percentage value", "%1%", window.volume)
2021-06-05 03:40:54 +00:00
// Display a subtle visual indication that the volume might be
// dangerously high
// ------------------------------------------------
// Keep this in sync with the copies in plasma-pa:ListItemBase.qml
// and plasma-pa:VolumeSlider.qml
color: {
if (volumeSlider.value <= 100) {
return PlasmaCore.Theme.textColor
} else if (volumeSlider.value > 100 && volumeSlider.value <= 125) {
return PlasmaCore.Theme.neutralTextColor
} else {
return PlasmaCore.Theme.negativeTextColor
}
}
}
2021-06-05 03:40:54 +00:00
PlasmaComponents.ToolButton {
icon.name: "configure"
text: i18n("Open audio settings")
visible: opacity !== 0
opacity: showFullApplet ? 1 : 0
display: Controls.AbstractButton.IconOnly
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
Layout.rightMargin: PlasmaCore.Units.smallSpacing
2021-06-05 03:40:54 +00:00
Behavior on opacity { NumberAnimation { duration: PlasmaCore.Units.shortDuration } }
2021-06-05 03:40:54 +00:00
onClicked: {
let coords = mapToItem(flickable, 0, 0);
MobileShellState.ShellDBusClient.openAppLaunchAnimation("audio-volume-high", i18n("Audio Settings"), coords.x, coords.y, PlasmaCore.Units.iconSizes.medium);
2022-04-07 00:32:23 +00:00
MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_pulseaudio");
2021-06-05 03:40:54 +00:00
}
}
2021-06-05 03:40:54 +00:00
PlasmaComponents.ToolButton {
icon.name: window.showFullApplet ? "arrow-up" : "arrow-down"
text: i18n("Toggle showing audio streams")
display: Controls.AbstractButton.IconOnly
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
onClicked: {
window.showFullApplet = !window.showFullApplet
// don't autohide applet when full applet is shown
if (window.showFullApplet) {
hideTimer.stop();
} else {
hideTimer.restart();
}
}
}
}
}
// other applet cards
AudioApplet {
id: applet
Layout.topMargin: PlasmaCore.Units.largeSpacing
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: cards.width
audioInfo: audioInfo
2021-06-05 03:40:54 +00:00
opacity: window.showFullApplet ? 1 : 0
visible: opacity !== 0
transform: Translate {
2021-06-05 03:40:54 +00:00
y: window.showFullApplet ? 0 : -PlasmaCore.Units.gridUnit
Behavior on y { NumberAnimation {} }
}
2021-06-05 03:40:54 +00:00
Behavior on opacity { NumberAnimation {} }
}
}
}
}
}