Warning, /plasma/plasma-desktop/applets/taskmanager/package/contents/ui/AudioStream.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 0009 import org.kde.plasma.extras as PlasmaExtras 0010 import org.kde.kirigami 2.20 as Kirigami 0011 import org.kde.ksvg 1.0 as KSvg 0012 0013 Item { 0014 id: audioStreamIconBox 0015 0016 width: Math.min(Math.min(iconBox.width, iconBox.height) * 0.4, Kirigami.Units.iconSizes.smallMedium) 0017 height: width 0018 anchors { 0019 top: frame.top 0020 right: frame.right 0021 rightMargin: taskFrame.margins.right 0022 topMargin: Math.round(taskFrame.margins.top * indicatorScale) 0023 } 0024 0025 readonly property real indicatorScale: 1.2 0026 0027 activeFocusOnTab: true 0028 0029 // Using States rather than a simple Behavior we can apply different transitions, 0030 // which allows us to delay showing the icon but hide it instantly still. 0031 states: [ 0032 State { 0033 name: "playing" 0034 when: task.playingAudio && !task.muted 0035 PropertyChanges { 0036 target: audioStreamIconBox 0037 opacity: 1 0038 } 0039 PropertyChanges { 0040 target: audioStreamIcon 0041 source: "audio-volume-high-symbolic" 0042 } 0043 }, 0044 State { 0045 name: "muted" 0046 when: task.muted 0047 PropertyChanges { 0048 target: audioStreamIconBox 0049 opacity: 1 0050 } 0051 PropertyChanges { 0052 target: audioStreamIcon 0053 source: "audio-volume-muted-symbolic" 0054 } 0055 } 0056 ] 0057 0058 transitions: [ 0059 Transition { 0060 from: "" 0061 to: "playing" 0062 SequentialAnimation { 0063 // Delay showing the play indicator so we don't flash it for brief sounds. 0064 PauseAnimation { 0065 duration: !task.delayAudioStreamIndicator || inPopup ? 0 : 2000 0066 } 0067 NumberAnimation { 0068 property: "opacity" 0069 duration: Kirigami.Units.longDuration 0070 } 0071 } 0072 }, 0073 Transition { 0074 from: "" 0075 to: "muted" 0076 SequentialAnimation { 0077 NumberAnimation { 0078 property: "opacity" 0079 duration: Kirigami.Units.longDuration 0080 } 0081 } 0082 }, 0083 Transition { 0084 to: "" 0085 NumberAnimation { 0086 property: "opacity" 0087 duration: Kirigami.Units.longDuration 0088 } 0089 } 0090 ] 0091 0092 opacity: 0 0093 visible: opacity > 0 0094 0095 Keys.onReturnPressed: toggleMuted() 0096 Keys.onEnterPressed: Keys.returnPressed(event); 0097 Keys.onSpacePressed: Keys.returnPressed(event); 0098 0099 Accessible.checkable: true 0100 Accessible.checked: task.muted 0101 Accessible.name: task.muted ? i18nc("@action:button", "Unmute") : i18nc("@action:button", "Mute") 0102 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) 0103 Accessible.role: Accessible.Button 0104 0105 HoverHandler { 0106 id: hoverHandler 0107 } 0108 0109 TapHandler { 0110 id: tapHandler 0111 gesturePolicy: TapHandler.ReleaseWithinBounds // Exclusive grab 0112 onTapped: toggleMuted() 0113 } 0114 0115 PlasmaExtras.Highlight { 0116 anchors.fill: audioStreamIcon 0117 hovered: hoverHandler.hovered || parent.activeFocus 0118 pressed: tapHandler.pressed 0119 } 0120 0121 Kirigami.Icon { 0122 id: audioStreamIcon 0123 0124 // Need audio indicator twice, to keep iconBox in the center. 0125 readonly property var requiredSpace: Math.min(iconBox.width, iconBox.height) 0126 + Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium) * 2 0127 source: "audio-volume-high-symbolic" 0128 selected: tapHandler.pressed 0129 0130 height: Math.round(Math.min(parent.height * indicatorScale, Kirigami.Units.iconSizes.smallMedium)) 0131 width: height 0132 0133 anchors { 0134 verticalCenter: parent.verticalCenter 0135 horizontalCenter: parent.horizontalCenter 0136 } 0137 0138 states: [ 0139 State { 0140 name: "verticalIconsOnly" 0141 when: tasks.vertical && frame.width < audioStreamIcon.requiredSpace 0142 0143 PropertyChanges { 0144 target: audioStreamIconBox 0145 anchors.rightMargin: Math.round(taskFrame.margins.right * indicatorScale) 0146 } 0147 }, 0148 0149 State { 0150 name: "horizontal" 0151 when: frame.width > audioStreamIcon.requiredSpace 0152 0153 AnchorChanges { 0154 target: audioStreamIconBox 0155 0156 anchors.top: undefined 0157 anchors.verticalCenter: frame.verticalCenter 0158 } 0159 0160 PropertyChanges { 0161 target: audioStreamIconBox 0162 width: Kirigami.Units.iconSizes.roundedIconSize(Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium)) 0163 } 0164 0165 PropertyChanges { 0166 target: audioStreamIcon 0167 0168 height: parent.height 0169 width: parent.width 0170 } 0171 }, 0172 0173 State { 0174 name: "vertical" 0175 when: frame.height > audioStreamIcon.requiredSpace 0176 0177 AnchorChanges { 0178 target: audioStreamIconBox 0179 0180 anchors.right: undefined 0181 anchors.horizontalCenter: frame.horizontalCenter 0182 } 0183 0184 PropertyChanges { 0185 target: audioStreamIconBox 0186 0187 anchors.topMargin: taskFrame.margins.top 0188 width: Kirigami.Units.iconSizes.roundedIconSize(Math.min(Math.min(iconBox.width, iconBox.height), Kirigami.Units.iconSizes.smallMedium)) 0189 } 0190 0191 PropertyChanges { 0192 target: audioStreamIcon 0193 0194 height: parent.height 0195 width: parent.width 0196 } 0197 } 0198 ] 0199 } 0200 }