| 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 |
|
| 21 |
signal activeStateChanged(int index, bool active) |
| 22 |
signal someStateChanged(int index, int freq) |
| 23 |
|
| 24 |
function setFStates(states, freqMin, freqMax) { |
| 25 |
stateModel.clear() |
| 26 |
|
| 27 |
for (var i = 0; i < states.length; i += 2) { |
| 28 |
|
| 29 |
stateModel.append({"_index": states[i], |
| 30 |
"_freq": states[i + 1], |
| 31 |
"_freqMin": freqMin, |
| 32 |
"_freqMax": freqMax}) |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
function updateFState(index, freq) { |
| 37 |
for (var i = 0; i < stateModel.count; ++i) { |
| 38 |
if (stateModel.get(i)._index === index) { |
| 39 |
stateModel.set(i, {"_freq": freq}) |
| 40 |
break |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
function setFreqRange(min, max) { |
| 46 |
for (var i = 0; i < stateModel.count; ++i) |
| 47 |
stateModel.set(i, {"_freqMin": min, "_freqMax": max}) |
| 48 |
} |
| 49 |
|
| 50 |
TextMetrics { |
| 51 |
id: tFMetrics |
| 52 |
text: "9999" |
| 53 |
} |
| 54 |
|
| 55 |
ListModel { |
| 56 |
id: stateModel |
| 57 |
|
| 58 |
function getStateLabel(stateIndex) { |
| 59 |
if (stateIndex === 0) |
| 60 |
return qsTr("MINIMUM") |
| 61 |
else if (stateModel.count === 1 || stateIndex === stateModel.count - 1) |
| 62 |
return qsTr("MAXIMUM") |
| 63 |
else |
| 64 |
return qsTr("STATE") + " " + stateIndex |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
Component { |
| 69 |
id: stateCtl |
| 70 |
|
| 71 |
ColumnLayout { |
| 72 |
Label { |
| 73 |
text: stateModel.getStateLabel(_index) |
| 74 |
Layout.alignment: Qt.AlignHCenter |
| 75 |
} |
| 76 |
|
| 77 |
Label { |
| 78 |
text: "MHz" |
| 79 |
font.pointSize: 8 |
| 80 |
Layout.alignment: Qt.AlignHCenter |
| 81 |
} |
| 82 |
|
| 83 |
Slider { |
| 84 |
id: stateFreqSld |
| 85 |
|
| 86 |
Layout.alignment: Qt.AlignHCenter |
| 87 |
orientation: Qt.Vertical |
| 88 |
|
| 89 |
value: _freq |
| 90 |
from: _freqMin |
| 91 |
to: _freqMax |
| 92 |
stepSize: 1 |
| 93 |
|
| 94 |
onPressedChanged: pressed => { |
| 95 |
if (!pressed) |
| 96 |
control.someStateChanged(_index, value) |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
CIntInput { |
| 101 |
value: stateFreqSld.value |
| 102 |
minValue: stateFreqSld.from |
| 103 |
maxValue: stateFreqSld.to |
| 104 |
Layout.preferredWidth: tFMetrics.width + padding * 2 |
| 105 |
Layout.alignment: Qt.AlignHCenter |
| 106 |
|
| 107 |
onValueChanged: control.someStateChanged(_index, value) |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
ColumnLayout { |
| 113 |
anchors.fill: parent |
| 114 |
|
| 115 |
GridLayout { |
| 116 |
columns: 2 |
| 117 |
|
| 118 |
Label { |
| 119 |
id: title |
| 120 |
font.pointSize: 11 |
| 121 |
font.bold: true |
| 122 |
Layout.columnSpan: 2 |
| 123 |
} |
| 124 |
|
| 125 |
CPane { |
| 126 |
padding: Style.FVControl.inner_padding |
| 127 |
bottomPadding: 0 |
| 128 |
Layout.columnSpan: 2 |
| 129 |
|
| 130 |
RowLayout { |
| 131 |
id: freqStates |
| 132 |
|
| 133 |
spacing: 15 |
| 134 |
Layout.fillWidth: true |
| 135 |
|
| 136 |
Repeater { |
| 137 |
model: stateModel |
| 138 |
delegate: stateCtl |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |