/*SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuick 2.15import org.kde.plasma.core 2.0 as PlasmaCoreMouseArea {id: audioStreamIconBoxactiveFocusOnTab: truehoverEnabled: trueonClicked: toggleMuted()// 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 {target: audioStreamIconBoxopacity: 1}PropertyChanges {target: audioStreamIconelementId: "audio-volume-high"}},State {name: "muted"when: task.mutedPropertyChanges {target: audioStreamIconBoxopacity: 1}PropertyChanges {target: audioStreamIconelementId: "audio-volume-muted"}}]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: PlasmaCore.Units.longDuration}}},Transition {from: ""to: "muted"SequentialAnimation {NumberAnimation {property: "opacity"duration: PlasmaCore.Units.longDuration}}},Transition {to: ""NumberAnimation {property: "opacity"duration: PlasmaCore.Units.longDuration}}]opacity: 0visible: opacity > 0Keys.onReturnPressed: toggleMuted()Keys.onEnterPressed: Keys.onReturnPressed(event);Keys.onSpacePressed: Keys.onReturnPressed(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.ButtonPlasmaCore.FrameSvgItem {anchors.fill: audioStreamIconvisible: parent.containsMouse || parent.activeFocusimagePath: "widgets/viewitem"prefix: "hover"}PlasmaCore.Svg {id: audioSvgimagePath: "icons/audio"}PlasmaCore.SvgItem {id: audioStreamIcon// Need audio indicator twice, to keep iconBox in the center.readonly property var requiredSpace: Math.min(iconBox.width, iconBox.height)+ Math.min(Math.min(iconBox.width, iconBox.height), PlasmaCore.Units.iconSizes.smallMedium) * 2svg: audioSvgsmooth: falseheight: Math.round(Math.min(parent.height * indicatorScale, PlasmaCore.Units.iconSizes.smallMedium))width: heightanchors {verticalCenter: parent.verticalCenterhorizontalCenter: parent.horizontalCenter}states: [State {name: "verticalIconsOnly"when: tasks.vertical && frame.width < audioStreamIcon.requiredSpacePropertyChanges {target: audioStreamIconLoaderanchors.rightMargin: Math.round(taskFrame.margins.right * indicatorScale)}},State {name: "horizontal"when: frame.width > audioStreamIcon.requiredSpaceAnchorChanges {target: audioStreamIconLoaderanchors.top: undefinedanchors.verticalCenter: frame.verticalCenter}PropertyChanges {target: audioStreamIconLoaderwidth: PlasmaCore.Units.roundToIconSize(Math.min(Math.min(iconBox.width, iconBox.height), PlasmaCore.Units.iconSizes.smallMedium))}PropertyChanges {target: audioStreamIconheight: parent.heightwidth: parent.width}},State {name: "vertical"when: frame.height > audioStreamIcon.requiredSpaceAnchorChanges {target: audioStreamIconLoaderanchors.right: undefinedanchors.horizontalCenter: frame.horizontalCenter}PropertyChanges {target: audioStreamIconLoaderanchors.topMargin: taskFrame.margins.topwidth: PlasmaCore.Units.roundToIconSize(Math.min(Math.min(iconBox.width, iconBox.height), PlasmaCore.Units.iconSizes.smallMedium))}PropertyChanges {target: audioStreamIconheight: parent.heightwidth: parent.width}}]}}