1 /****************************************************************************************
2 * Copyright (c) 2017 Malte Veerman <malte.veerman@gmail.com>                           *
3 *                                                                                      *
4 * This program is free software; you can redistribute it and/or modify it under        *
5 * the terms of the GNU General Public License as published by the Free Software        *
6 * Foundation; either version 2 of the License, or (at your option) any later           *
7 * version.                                                                             *
8 *                                                                                      *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12 *                                                                                      *
13 * You should have received a copy of the GNU General Public License along with         *
14 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15 ****************************************************************************************/
16
17import QtQuick 2.4
18import QtQuick.Controls 2.0
19import QtQuick.Dialogs 1.2 as Dialogs // QtQuick.Controls Dialogs only work properly with ApplicationWindow
20import QtQuick.Layouts 1.0
21import QtQml.Models 2.1
22import org.kde.kirigami 2.0 as Kirigami
23import org.kde.amarok.qml 1.0 as AmarokQml
24import org.kde.amarok.analyzer 1.0
25
26AmarokQml.Applet {
27    id: applet
28
29    BlockAnalyzer {
30        id: blocky
31
32        anchors.fill: parent
33    }
34
35    configDialog: Dialogs.Dialog {
36        id: dialog
37
38        title: i18nc("The title of the analyzer config dialog", "%1 config", applet.name)
39        width: Kirigami.Units.largeSpacing * 25
40        standardButtons: Dialogs.StandardButton.Ok | Dialogs.StandardButton.Apply | Dialogs.StandardButton.Cancel
41
42        function applyChanges() {
43            blocky.columnWidth = columnWidthSlider.trueValue;
44            blocky.showFadebars = showFadebarsBox.checked;
45            blocky.fallSpeed = fallSpeedSlider.value;
46//             blocky.windowFunction = windowFunctionCombo.currentIndex;
47            blocky.minimumFrequency = freqSlider.minValue;
48            blocky.maximumFrequency = freqSlider.maxValue;
49            blocky.sampleSize = sampleSizeSlider.sampleSize;
50        }
51
52        onAccepted: applyChanges();
53        onApply: applyChanges();
54
55        Column {
56            width: parent.width
57            spacing: Kirigami.Units.smallSpacing
58
59            RowLayout {
60                width: parent.width
61
62                Label {
63                    Layout.alignment: Qt.AlignLeft
64                    text: i18n("Bar width:")
65                }
66                Slider {
67                    id: columnWidthSlider
68
69                    readonly property int trueValue: value + 1 // Slider buggy if you set "from"" to 1
70
71                    Layout.alignment: Qt.AlignRight
72                    Layout.fillWidth: true
73                    from: 0
74                    to: 19
75                    stepSize: 1
76                    value: blocky.columnWidth - 1
77
78                    ToolTip {
79                        text: i18np("%1 pixel", "%1 pixels", columnWidthSlider.trueValue)
80                        parent: columnWidthSlider.handle
81                        x: columnWidthSlider.visualPosition * columnWidthSlider.width - width / 2
82                        visible: columnWidthSlider.pressed
83                    }
84                }
85            }
86            RowLayout {
87                width: parent.width
88
89                Label {
90                    Layout.alignment: Qt.AlignLeft
91                    text: i18n("Show fadebars:")
92                }
93                CheckBox {
94                    id: showFadebarsBox
95
96                    Layout.alignment: Qt.AlignRight
97                    Layout.fillWidth: true
98                    checked: blocky.showFadebars
99                }
100            }
101            RowLayout {
102                width: parent.width
103
104                Label {
105                    Layout.alignment: Qt.AlignLeft
106                    text: i18n("Bars fall speed:")
107                }
108                Slider {
109                    id: fallSpeedSlider
110
111                    Layout.alignment: Qt.AlignRight
112                    Layout.fillWidth: true
113                    from: 0
114                    to: 4
115                    stepSize: 1
116                    value: blocky.fallSpeed
117                }
118            }
119            RowLayout {
120                width: parent.width
121
122                Label {
123                    Layout.alignment: Qt.AlignLeft
124                    text: i18n("Frequency range:")
125                }
126                RangeSlider {
127                    id: freqSlider
128
129                    readonly property real exp: Math.pow(1000, 1.0/100)
130                    readonly property real minValue: 20 * Math.pow(exp, first.value)
131                    readonly property real maxValue: 20 * Math.pow(exp, second.value)
132
133                    Layout.alignment: Qt.AlignRight
134                    Layout.fillWidth: true
135
136                    first.value: Math.log(blocky.minimumFrequency / 20) / Math.log(exp)
137                    second.value: Math.log(blocky.maximumFrequency / 20) / Math.log(exp)
138                    from: 0
139                    to: 100
140
141                    ToolTip {
142                        text: i18n("%1 Hz", Math.round(freqSlider.minValue))
143                        parent: freqSlider.first.handle
144                        visible: freqSlider.first.pressed
145                    }
146                    ToolTip {
147                        text: i18n("%1 Hz", Math.round(freqSlider.maxValue))
148                        parent: freqSlider.second.handle
149                        visible: freqSlider.second.pressed
150                    }
151                }
152            }
153            RowLayout {
154                width: parent.width
155
156                Label {
157                    Layout.alignment: Qt.AlignLeft
158                    text: i18n("Sample size:")
159                }
160                Slider {
161                    id: sampleSizeSlider
162
163                    readonly property int sampleSize: 1024 * Math.pow(2, value)
164
165                    Layout.alignment: Qt.AlignRight
166                    Layout.fillWidth: true
167                    from: 0
168                    to: 4
169                    stepSize: 1
170                    value: {
171                        if (blocky.sampleSize <= 1024)
172                            return 0;
173                        else if (blocky.sampleSize <=  2048)
174                            return 1;
175                        else if (blocky.sampleSize <= 4096)
176                            return 2;
177                        else if (blocky.sampleSize <= 8192)
178                            return 3;
179                        return 4;
180                    }
181                    snapMode: Slider.SnapAlways
182
183                    ToolTip {
184                        text: Number(sampleSizeSlider.sampleSize).toLocaleString(Qt.locale(), 'f', 0)
185                        parent: sampleSizeSlider.handle
186                        x: sampleSizeSlider.visualPosition * sampleSizeSlider.width - width / 2
187                        visible: sampleSizeSlider.pressed
188                    }
189                }
190            }
191//             RowLayout {
192//                 width: parent.width
193//
194//                 Label {
195//                     Layout.alignment: Qt.AlignLeft
196//                     text: i18n("Window function:")
197//                 }
198//                 ComboBox {
199//                     id: windowFunctionCombo
200//
201//                     Layout.alignment: Qt.AlignRight
202//                     Layout.fillWidth: true
203//                     currentIndex: blocky.windowFunction
204//                     model: [i18n("Rectangular"), i18n("Hann"), i18n("Nuttall"), i18n("Lanczos"), i18n("Sine")]
205//                 }
206//             }
207        }
208    }
209}
210