Debian Codegraph @

src/qml/FVControl.qml

raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 import QtQuick 2.15
5 import QtQuick.Controls 2.15
6 import QtQuick.Layouts 1.15
7 import "Style.js" as Style
8
9 Pane {
10 id: control
11
12 padding: Style.g_padding
13 background: Rectangle {
14 border.color: Style.FVControl.border_color
15 border.width: 2
16 color: "#00000000"
17 }
18
19 property alias title: title.text
20 property alias voltManual: manualVolt.checked
21
22 signal activeStateChanged(int index, bool active)
23 signal someStateChanged(int index, int freq, int volt)
24
25 function setFVStates(states, activeStates, freqMin, freqMax, voltMin, voltMax) {
26 stateModel.clear()
27
28 for (var i = 0; i < states.length; i += 3) {
29
30 var activeState = false
31 for (var j = 0; j < activeStates.length; ++j)
32 if (activeStates[j] === states[i]) {
33 activeState = true
34 break
35 }
36
37 stateModel.append({"_index": states[i],
38 "_active": activeState,
39 "_freq": states[i + 1],
40 "_freqMin": freqMin,
41 "_freqMax": freqMax,
42 "_volt": states[i + 2],
43 "_voltMin": voltMin,
44 "_voltMax": voltMax})
45 }
46 }
47
48 function updateFVState(index, freq, volt) {
49 for (var i = 0; i < stateModel.count; ++i) {
50 if (stateModel.get(i)._index === index) {
51 stateModel.set(i, {"_freq": freq, "_volt": volt})
52 break
53 }
54 }
55 }
56
57 function setFreqRange(min, max) {
58 for (var i = 0; i < stateModel.count; ++i)
59 stateModel.set(i, {"_freqMin": min, "_freqMax": max})
60 }
61
62 function setVoltRange(min, max) {
63 for (var i = 0; i < stateModel.count; ++i)
64 stateModel.set(i, {"_voltMin": min, "_voltMax": max})
65 }
66
67 function activeStates(indices) {
68 if (indices.length > 0) {
69 var activeStatesCount = 0;
70 for (var i = 0; i < stateModel.count; ++i) {
71 var stateIndex = stateModel.get(i)._index
72
73 var activeState = false
74 for (var j = 0; j < indices.length; ++j)
75 if (indices[j] === stateIndex) {
76 activeState = true
77 ++activeStatesCount
78 break
79 }
80
81 stateModel.set(i, {"_active": activeState})
82 }
83
84 stateModel.activeStatesCount = activeStatesCount
85 }
86 }
87
88 TextMetrics {
89 id: tFMetrics
90 text: "9999"
91 }
92
93 ListModel {
94 id: stateModel
95
96 property int activeStatesCount: 0
97 }
98
99 Component {
100 id: stateCtl
101
102 ColumnLayout {
103 Label {
104 text: qsTr("STATE") + " " + _index
105 enabled: stateCkb.checked
106 Layout.alignment: Qt.AlignHCenter
107 }
108
109 CheckBox {
110 id: stateCkb
111 checked: _active
112 enabled: stateModel.activeStatesCount === 1 && !checked ||
113 stateModel.activeStatesCount > 1
114
115 Layout.alignment: Qt.AlignHCenter
116 scale: 0.75
117 topPadding: -1
118 bottomPadding: -1
119
120 onToggled: control.activeStateChanged(_index, checked)
121 }
122
123 Slider {
124 id: stateFreqSld
125 enabled: stateCkb.checked
126
127 Layout.alignment: Qt.AlignHCenter
128 orientation: Qt.Vertical
129
130 value: _freq
131 from: _freqMin
132 to: _freqMax
133 stepSize: 1
134
135 onPressedChanged: pressed => {
136 if (!pressed)
137 control.someStateChanged(_index, value, _volt)
138 }
139 }
140
141 CIntInput {
142 value: stateFreqSld.value
143 minValue: stateFreqSld.from
144 maxValue: stateFreqSld.to
145
146 enabled: stateCkb.checked
147 Layout.preferredWidth: tFMetrics.width + padding * 2
148 Layout.alignment: Qt.AlignHCenter
149
150 onValueChanged: control.someStateChanged(_index, value, _volt)
151 }
152
153 CIntInput {
154 value: _volt
155 minValue: _voltMin
156 maxValue: _voltMax
157
158 enabled: stateCkb.checked
159 visible: manualVolt.checked
160 Layout.preferredWidth: tFMetrics.width + padding * 2
161 Layout.alignment: Qt.AlignHCenter
162
163 onValueChanged: control.someStateChanged(_index, _freq, value)
164 }
165
166 TextField {
167 text: qsTr("Auto")
168
169 enabled: false
170 visible: !manualVolt.checked
171
172 padding: Style.TextField.padding
173 horizontalAlignment: TextInput.AlignHCenter
174
175 Layout.preferredWidth: tFMetrics.width + padding * 2
176 Layout.alignment: Qt.AlignHCenter
177 }
178 }
179 }
180
181 ColumnLayout {
182 anchors.fill: parent
183
184 GridLayout {
185 columns: 2
186
187 ColumnLayout {
188 Layout.fillHeight: true
189
190 Label {
191 id: title
192 font.pointSize: 11
193 font.bold: true
194 }
195
196 Item { Layout.fillHeight: true }
197
198 Label {
199 id: freqLbl
200 text: qsTr("Frequency") + " (MHz)"
201 Layout.alignment: Qt.AlignRight
202 }
203
204 Item { Layout.preferredHeight: 7 }
205
206 ColumnLayout {
207
208 RowLayout {
209 Item { Layout.fillWidth: true }
210
211 Item {
212 implicitWidth: manualVolt.width / (1 + Style.g_tweakScale)
213
214 Switch {
215 id: manualVolt
216
217 scale: Style.g_tweakScale
218 anchors.centerIn: parent
219 }
220 }
221
222 Label { text: qsTr("Voltage") + " (mV)" }
223 }
224
225 Item { Layout.preferredHeight: 3 }
226 }
227 }
228
229 RowLayout {
230 id: freqStates
231
232 spacing: 15
233 Layout.fillWidth: true
234
235 Repeater {
236 model: stateModel
237 delegate: stateCtl
238 }
239 }
240 }
241 }
242 }