Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/main.qml
Show All 29 Lines | |||||
30 | import org.kde.plasma.private.volume 0.1 | 30 | import org.kde.plasma.private.volume 0.1 | ||
31 | 31 | | |||
32 | import "../code/icon.js" as Icon | 32 | import "../code/icon.js" as Icon | ||
33 | 33 | | |||
34 | Item { | 34 | Item { | ||
35 | id: main | 35 | id: main | ||
36 | 36 | | |||
37 | property bool volumeFeedback: Plasmoid.configuration.volumeFeedback | 37 | property bool volumeFeedback: Plasmoid.configuration.volumeFeedback | ||
38 | property int maxVolumeValue: Math.round(Plasmoid.configuration.maximumVolume * PulseAudio.NormalVolume / 100.0) | 38 | property int raiseMaxVolumeValue: 150 | ||
39 | property int maxVolumeValue: Math.round(raiseMaxVolumeValue * PulseAudio.NormalVolume / 100.0) | ||||
40 | property int currentMaxVolumeValue: plasmoid.configuration.raiseMaximumVolume ? maxVolumeValue : PulseAudio.NormalVolume | ||||
39 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | 41 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | ||
40 | property string displayName: i18n("Audio Volume") | 42 | property string displayName: i18n("Audio Volume") | ||
41 | property QtObject draggedStream: null | 43 | property QtObject draggedStream: null | ||
42 | 44 | | |||
43 | // DEFAULT_SINK_NAME in module-always-sink.c | 45 | // DEFAULT_SINK_NAME in module-always-sink.c | ||
44 | readonly property string dummyOutputName: "auto_null" | 46 | readonly property string dummyOutputName: "auto_null" | ||
45 | 47 | | |||
46 | Layout.minimumHeight: units.gridUnit * 8 | 48 | Layout.minimumHeight: units.gridUnit * 8 | ||
Show All 28 Lines | 69 | Plasmoid.toolTipSubText: { | |||
75 | return "" | 77 | return "" | ||
76 | } | 78 | } | ||
77 | 79 | | |||
78 | function isDummyOutput(output) { | 80 | function isDummyOutput(output) { | ||
79 | return output && output.name === dummyOutputName; | 81 | return output && output.name === dummyOutputName; | ||
80 | } | 82 | } | ||
81 | 83 | | |||
82 | function boundVolume(volume) { | 84 | function boundVolume(volume) { | ||
83 | return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue)); | 85 | return Math.max(PulseAudio.MinimalVolume, Math.min(volume, currentMaxVolumeValue)); | ||
84 | } | 86 | } | ||
85 | 87 | | |||
86 | function volumePercent(volume, max) { | 88 | function volumePercent(volume, max) { | ||
87 | if (!max) { | 89 | if (!max) { | ||
88 | max = PulseAudio.NormalVolume; | 90 | max = PulseAudio.NormalVolume; | ||
89 | } | 91 | } | ||
90 | return Math.round(volume / max * 100.0); | 92 | return Math.round(volume / max * 100.0); | ||
91 | } | 93 | } | ||
92 | 94 | | |||
93 | function increaseVolume() { | 95 | function increaseVolume() { | ||
94 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | 96 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | ||
95 | return; | 97 | return; | ||
96 | } | 98 | } | ||
97 | var volume = boundVolume(paSinkModel.preferredSink.volume + volumeStep); | 99 | var volume = boundVolume(paSinkModel.preferredSink.volume + volumeStep); | ||
98 | var percent = volumePercent(volume, maxVolumeValue); | 100 | var percent = volumePercent(volume, currentMaxVolumeValue); | ||
99 | paSinkModel.preferredSink.muted = percent == 0; | 101 | paSinkModel.preferredSink.muted = percent == 0; | ||
100 | paSinkModel.preferredSink.volume = volume; | 102 | paSinkModel.preferredSink.volume = volume; | ||
101 | osd.show(percent); | 103 | osd.show(percent); | ||
102 | playFeedback(); | 104 | playFeedback(); | ||
103 | } | 105 | } | ||
104 | 106 | | |||
105 | function decreaseVolume() { | 107 | function decreaseVolume() { | ||
106 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | 108 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | ||
107 | return; | 109 | return; | ||
108 | } | 110 | } | ||
109 | var volume = boundVolume(paSinkModel.preferredSink.volume - volumeStep); | 111 | var volume = boundVolume(paSinkModel.preferredSink.volume - volumeStep); | ||
110 | var percent = volumePercent(volume, maxVolumeValue); | 112 | var percent = volumePercent(volume, currentMaxVolumeValue); | ||
111 | paSinkModel.preferredSink.muted = percent == 0; | 113 | paSinkModel.preferredSink.muted = percent == 0; | ||
112 | paSinkModel.preferredSink.volume = volume; | 114 | paSinkModel.preferredSink.volume = volume; | ||
113 | osd.show(percent); | 115 | osd.show(percent); | ||
114 | playFeedback(); | 116 | playFeedback(); | ||
115 | } | 117 | } | ||
116 | 118 | | |||
117 | function muteVolume() { | 119 | function muteVolume() { | ||
118 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | 120 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | ||
119 | return; | 121 | return; | ||
120 | } | 122 | } | ||
121 | var toMute = !paSinkModel.preferredSink.muted; | 123 | var toMute = !paSinkModel.preferredSink.muted; | ||
122 | paSinkModel.preferredSink.muted = toMute; | 124 | paSinkModel.preferredSink.muted = toMute; | ||
123 | osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, maxVolumeValue)); | 125 | osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue)); | ||
124 | if (!toMute) { | 126 | if (!toMute) { | ||
125 | playFeedback(); | 127 | playFeedback(); | ||
126 | } | 128 | } | ||
127 | } | 129 | } | ||
128 | 130 | | |||
129 | function increaseMicrophoneVolume() { | 131 | function increaseMicrophoneVolume() { | ||
130 | if (!paSourceModel.defaultSource) { | 132 | if (!paSourceModel.defaultSource) { | ||
131 | return; | 133 | return; | ||
▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Line(s) | 530 | PlasmaCore.SvgItem { | |||
531 | Layout.topMargin: 0 - units.smallSpacing / 2 | 533 | Layout.topMargin: 0 - units.smallSpacing / 2 | ||
532 | Layout.leftMargin: 0 - units.smallSpacing * 1.5 | 534 | Layout.leftMargin: 0 - units.smallSpacing * 1.5 | ||
533 | Layout.rightMargin: Layout.leftMargin | 535 | Layout.rightMargin: Layout.leftMargin | ||
534 | svg: lineSvg | 536 | svg: lineSvg | ||
535 | } | 537 | } | ||
536 | 538 | | |||
537 | RowLayout { | 539 | RowLayout { | ||
538 | 540 | | |||
541 | PlasmaComponents3.CheckBox { | ||||
542 | id: raiseMaximumVolumeCheckbox | ||||
543 | // Align center, with the devices mute icon. Calculating the size based on SmallToolButton.qml. '4' is margin in ListItem. | ||||
ngraham: Don't override this; if it looks bad with the default value, we should fix that in the checkbox… | |||||
544 | Layout.leftMargin: LayoutMirroring.enabled ? 0 : Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + 4 | ||||
This could evaluate to a fractional number. You probably want units.largeSpacing here (the spacing doesn't have to be literally identical to the mockup; it's more important to use standard spacing values) ngraham: This could evaluate to a fractional number. You probably want `units.largeSpacing` here (the… | |||||
545 | Layout.rightMargin: !LayoutMirroring.enabled ? 0 : Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + 4 | ||||
546 | spacing: Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + units.smallSpacing | ||||
Always use onToggled to handle user input, never onCheckedChanged If you're deliberately using onCheckedChanged because it has the side effect of evaluating the logic in here when the applet is first loaded, then don't do that, and instead explicitly call that logic in an onCompleted block ngraham: Always use `onToggled` to handle user input, never `onCheckedChanged`
If you're deliberately… | |||||
547 | checked: plasmoid.configuration.raiseMaximumVolume | ||||
548 | onToggled: { | ||||
549 | plasmoid.configuration.raiseMaximumVolume = checked | ||||
550 | if (!checked) { | ||||
551 | for (var i = 0; i < paSinkModel.rowCount(); i++) { | ||||
552 | if (paSinkModel.data(paSinkModel.index(i, 0), paSinkModel.role("Volume")) > PulseAudio.NormalVolume) { | ||||
553 | paSinkModel.setData(paSinkModel.index(i, 0), PulseAudio.NormalVolume, paSinkModel.role("Volume")); | ||||
554 | } | ||||
555 | } | ||||
556 | } | ||||
557 | } | ||||
558 | text: i18n("Raise maximum volume") | ||||
559 | enabled: false // Intentionally disabled, see D26256 | ||||
560 | } | ||||
561 | | ||||
539 | Item { | 562 | Item { | ||
540 | Layout.fillWidth: true | 563 | Layout.fillWidth: true | ||
541 | } | 564 | } | ||
542 | 565 | | |||
543 | PlasmaComponents.ToolButton { | 566 | PlasmaComponents.ToolButton { | ||
544 | tooltip: plasmoid.action("configure").text | 567 | tooltip: plasmoid.action("configure").text | ||
545 | iconName: "configure" | 568 | iconName: "configure" | ||
546 | Accessible.name: tooltip | 569 | Accessible.name: tooltip | ||
Show All 9 Lines |
Don't override this; if it looks bad with the default value, we should fix that in the checkbox control itself