Changeset View
Changeset View
Standalone View
Standalone View
src/kcm/package/contents/ui/VolumeSlider.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | Copyright 2014-2015 Harald Sitter <sitter@kde.org> | 2 | Copyright 2014-2015 Harald Sitter <sitter@kde.org> | ||
3 | Copyright 2019 Sefa Eyeoglu <contact@scrumplex.net> | ||||
3 | 4 | | |||
4 | This program is free software; you can redistribute it and/or | 5 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU General Public License as | 6 | modify it under the terms of the GNU General Public License as | ||
6 | published by the Free Software Foundation; either version 2 of | 7 | published by the Free Software Foundation; either version 2 of | ||
7 | the License or (at your option) version 3 or any later version | 8 | the License or (at your option) version 3 or any later version | ||
8 | accepted by the membership of KDE e.V. (or its successor approved | 9 | accepted by the membership of KDE e.V. (or its successor approved | ||
9 | by the membership of KDE e.V.), which shall act as a proxy | 10 | by the membership of KDE e.V.), which shall act as a proxy | ||
10 | defined in Section 14 of version 3 of the license. | 11 | defined in Section 14 of version 3 of the license. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
16 | 17 | | |||
17 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | import QtQuick 2.4 | 22 | import QtQuick 2.4 | ||
22 | import QtQuick.Layouts 1.0 | 23 | import QtQuick.Layouts 1.0 | ||
23 | import QtQuick.Controls 2.0 | 24 | import QtQuick.Controls 2.5 as QQC2 | ||
24 | 25 | | |||
25 | import org.kde.plasma.private.volume 0.1 | 26 | import org.kde.plasma.private.volume 0.1 | ||
26 | 27 | | |||
27 | RowLayout { | 28 | RowLayout { | ||
28 | Layout.bottomMargin: hundredPercentLabel.height | 29 | Layout.bottomMargin: hundredPercentLabel.height | ||
29 | 30 | | |||
30 | Slider { | 31 | QQC2.Slider { | ||
31 | id: slider | 32 | id: slider | ||
32 | 33 | | |||
33 | // Helper properties to allow async slider updates. | 34 | // Helper properties to allow async slider updates. | ||
34 | // While we are sliding we must not react to value updates | 35 | // While we are sliding we must not react to value updates | ||
35 | // as otherwise we can easily end up in a loop where value | 36 | // as otherwise we can easily end up in a loop where value | ||
36 | // changes trigger volume changes trigger value changes. | 37 | // changes trigger volume changes trigger value changes. | ||
37 | property int volume: Volume | 38 | property int volume: Volume | ||
38 | property bool ignoreValueChange: true | 39 | property bool ignoreValueChange: true | ||
39 | 40 | | |||
40 | Layout.fillWidth: true | 41 | Layout.fillWidth: true | ||
41 | from: PulseAudio.MinimalVolume | 42 | from: PulseAudio.MinimalVolume | ||
42 | to: PulseAudio.MaximalVolume | 43 | to: PulseAudio.MaximalVolume | ||
44 | // TODO: implement a way to hide tickmarks | ||||
ngraham: Hmm, I don't like how this makes tickmarks appear. If you need to round the value, you can do… | |||||
I have removed this now as I can't replicate the same behavior as the applet. Added a TODO for the future sefaeyeoglu: I have removed this now as I can't replicate the same behavior as the applet. Added a TODO for… | |||||
45 | // stepSize: to / (PulseAudio.MaximalVolume / PulseAudio.NormalVolume * 100.0) | ||||
43 | visible: HasVolume | 46 | visible: HasVolume | ||
44 | enabled: VolumeWritable | 47 | enabled: VolumeWritable | ||
45 | opacity: Muted ? 0.5 : 1 | 48 | opacity: Muted ? 0.5 : 1 | ||
46 | 49 | | |||
47 | Component.onCompleted: { | 50 | Component.onCompleted: { | ||
48 | ignoreValueChange = false; | 51 | ignoreValueChange = false; | ||
49 | } | 52 | } | ||
50 | 53 | | |||
Show All 21 Lines | 73 | if (!pressed) { | |||
72 | // released. | 75 | // released. | ||
73 | // Otherwise it might be that the slider is at v10 | 76 | // Otherwise it might be that the slider is at v10 | ||
74 | // whereas PA rejected the volume change and is | 77 | // whereas PA rejected the volume change and is | ||
75 | // still at v15 (e.g.). | 78 | // still at v15 (e.g.). | ||
76 | updateTimer.restart(); | 79 | updateTimer.restart(); | ||
77 | } | 80 | } | ||
78 | } | 81 | } | ||
79 | 82 | | |||
80 | Label { | 83 | QQC2.Label { | ||
81 | id: hundredPercentLabel | 84 | id: hundredPercentLabel | ||
82 | readonly property real hundredPos: (slider.width / slider.maximumValue) * PulseAudio.NormalVolume | 85 | readonly property real hundredPos: (slider.width / slider.to) * PulseAudio.NormalVolume | ||
83 | z: slider.z - 1 | 86 | z: slider.z - 1 | ||
84 | x: (Qt.application.layoutDirection == Qt.RightToLeft ? slider.width - hundredPos : hundredPos) - width / 2 | 87 | x: (Qt.application.layoutDirection == Qt.RightToLeft ? slider.width - hundredPos : hundredPos) - width / 2 | ||
85 | y: slider.height / 1.2 | 88 | y: slider.height | ||
86 | opacity: 0.5 | 89 | opacity: 0.5 | ||
87 | font.pixelSize: slider.height / 2.2 | 90 | font.pixelSize: slider.height / 2.2 | ||
88 | text: i18nd("kcm_pulseaudio", "100%") | 91 | text: i18nd("kcm_pulseaudio", "100%") | ||
89 | } | 92 | } | ||
90 | 93 | | |||
91 | Timer { | 94 | Timer { | ||
92 | id: updateTimer | 95 | id: updateTimer | ||
93 | interval: 200 | 96 | interval: 200 | ||
94 | onTriggered: slider.value = Volume | 97 | onTriggered: slider.value = Volume | ||
95 | } | 98 | } | ||
96 | } | 99 | } | ||
97 | 100 | | |||
98 | Label { | 101 | QQC2.Label { | ||
99 | id: percentText | 102 | id: percentText | ||
100 | readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value | 103 | readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value | ||
101 | Layout.alignment: Qt.AlignHCenter | 104 | Layout.alignment: Qt.AlignHCenter | ||
102 | Layout.minimumWidth: percentMetrics.advanceWidth | 105 | Layout.minimumWidth: percentMetrics.advanceWidth | ||
103 | horizontalAlignment: Qt.AlignRight | 106 | horizontalAlignment: Qt.AlignRight | ||
104 | text: i18ndc("kcm_pulseaudio", "volume percentage", "%1%", Math.round(value / PulseAudio.NormalVolume * 100.0)) | 107 | text: i18ndc("kcm_pulseaudio", "volume percentage", "%1%", Math.round(value / PulseAudio.NormalVolume * 100.0)) | ||
105 | } | 108 | } | ||
106 | 109 | | |||
107 | TextMetrics { | 110 | TextMetrics { | ||
108 | id: percentMetrics | 111 | id: percentMetrics | ||
109 | font: percentText.font | 112 | font: percentText.font | ||
110 | text: i18ndc("kcm_pulseaudio", "only used for sizing, should be widest possible string", "100%") | 113 | text: i18ndc("kcm_pulseaudio", "only used for sizing, should be widest possible string", "100%") | ||
111 | } | 114 | } | ||
112 | } | 115 | } |
Hmm, I don't like how this makes tickmarks appear. If you need to round the value, you can do that in onMoved: { blabla; }, or just round the value of the label itself.