/*SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport org.kde.plasma.plasmoidimport org.kde.plasma.extras as PlasmaExtrasimport org.kde.kirigami as Kirigamiimport org.kde.ksvg as KSvgItem {id: audioStreamIconBoxwidth: Math.round(Math.min(Math.min(iconBox.width, iconBox.height) * 0.4, Kirigami.Units.iconSizes.smallMedium))height: widthanchors {top: frame.topright: frame.rightrightMargin: taskFrame.margins.righttopMargin: Math.round(taskFrame.margins.top * indicatorScale)}readonly property real indicatorScale: 1.2activeFocusOnTab: true// Using States rather than a simple Behavior we can apply different transitions,// which allows us to delay showing the icon but hide it instantly still.states: [State {name: "playing"when: task.playingAudio && !task.mutedPropertyChanges {audioStreamIconBox.opacity: 1audioStreamIcon.source: "audio-volume-high-symbolic" + (Application.layoutDirection === Qt.RightToLeft ? "-rtl" : "")}},State {name: "muted"when: task.mutedPropertyChanges {audioStreamIconBox.opacity: 1audioStreamIcon.source: "audio-volume-muted-symbolic" + (Application.layoutDirection === Qt.RightToLeft ? "-rtl" : "")}}]transitions: [Transition {from: ""to: "playing"SequentialAnimation {// Delay showing the play indicator so we don't flash it for brief sounds.PauseAnimation {duration: !task.delayAudioStreamIndicator || inPopup ? 0 : 2000}NumberAnimation {property: "opacity"duration: Kirigami.Units.longDuration}}},Transition {from: ""to: "muted"SequentialAnimation {NumberAnimation {property: "opacity"duration: Kirigami.Units.longDuration}}},Transition {to: ""SequentialAnimation {PauseAnimation {// don't trigger on double click fullscreen in video playersduration: inPopup ? 0 : Application.styleHints.mouseDoubleClickInterval}NumberAnimation {property: "opacity"duration: Kirigami.Units.longDuration}}}]opacity: 0visible: opacity > 0Keys.onReturnPressed: event => toggleMuted()Keys.onEnterPressed: event => Keys.returnPressed(event);Keys.onSpacePressed: event => Keys.returnPressed(event);Accessible.checkable: trueAccessible.checked: task.mutedAccessible.name: task.muted ? i18nc("@action:button", "Unmute") : i18nc("@action:button", "Mute")Accessible.description: task.muted ? i18nc("@info:tooltip %1 is the window title", "Unmute %1", model.display) : i18nc("@info:tooltip %1 is the window title", "Mute %1", model.display)Accessible.role: Accessible.ButtonHoverHandler {id: hoverHandlerenabled: Plasmoid.configuration.interactiveMute}TapHandler {id: tapHandlergesturePolicy: TapHandler.ReleaseWithinBounds // Exclusive grabenabled: Plasmoid.configuration.interactiveMuteonTapped: (eventPoint, button) => toggleMuted()}PlasmaExtras.Highlight {anchors.fill: audioStreamIconhovered: hoverHandler.hovered || parent.activeFocuspressed: tapHandler.pressed}Kirigami.Icon {id: audioStreamIcon// Need audio indicator twice, to keep iconBox in the center.readonly property real requiredSpace: Math.min(iconBox.width, iconBox.height)+ Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium) * 2source: "audio-volume-high-symbolic" + (Application.layoutDirection === Qt.RightToLeft ? "-rtl" : "")selected: tapHandler.pressedheight: Math.round(Math.min(parent.height * audioStreamIconBox.indicatorScale, Kirigami.Units.iconSizes.smallMedium))width: heightanchors {verticalCenter: parent.verticalCenterhorizontalCenter: parent.horizontalCenter}states: [State {name: "verticalIconsOnly"when: tasks.vertical && frame.width < audioStreamIcon.requiredSpacePropertyChanges {audioStreamIconBox.anchors.rightMargin: Math.round(taskFrame.margins.right * indicatorScale)}},State {name: "horizontal"when: frame.width > audioStreamIcon.requiredSpaceAnchorChanges {target: audioStreamIconBoxanchors.top: undefinedanchors.verticalCenter: frame.verticalCenter}PropertyChanges {audioStreamIconBox.width: Kirigami.Units.iconSizes.roundedIconSize(Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium))audioStreamIcon.height: audioStreamIcon.parent.heightaudioStreamIcon.width: audioStreamIcon.parent.width}},State {name: "vertical"when: frame.height > audioStreamIcon.requiredSpaceAnchorChanges {target: audioStreamIconBoxanchors.right: undefinedanchors.horizontalCenter: frame.horizontalCenter}PropertyChanges {audioStreamIconBox.anchors.topMargin: taskFrame.margins.topaudioStreamIconBox.width: Kirigami.Units.iconSizes.roundedIconSize(Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium))audioStreamIcon.height: audioStreamIcon.parent.heightaudioStreamIcon.width: audioStreamIcon.parent.width}}]}}