-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathcustomgears.qml
More file actions
287 lines (250 loc) · 9.08 KB
/
Copy pathcustomgears.qml
File metadata and controls
287 lines (250 loc) · 9.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.0
import Qt.labs.settings 1.0
ScrollView {
contentWidth: -1
focus: true
anchors.horizontalCenter: parent.horizontalCenter
anchors.fill: parent
id: customGearSettingsWindow
visible: true
clip: true
Settings {
id: settings
property bool gears_custom_table_enabled: false
property string gears_custom_table: "1|1\n2|2\n3|3\n4|4\n5|5\n6|6\n7|7\n8|8\n9|9\n10|10\n11|11\n12|12\n13|13\n14|14\n15|15\n16|16\n17|17\n18|18\n19|19\n20|20\n21|21\n22|22\n23|23\n24|24"
}
ListModel {
id: gearListModel
}
property var gearRows: []
property int rowHeight: 55
property int offsetControlHeight: 43
Component.onCompleted: {
loadGearRows()
}
function clampOffset(value) {
if (isNaN(value)) {
return 0
}
return Math.max(-100, Math.min(100, value))
}
function parseOffset(value) {
return parseFloat(String(value).replace(",", "."))
}
function defaultGearRows() {
var rows = []
for (var i = 1; i <= 24; i++) {
rows.push({ gear: i, offset: i })
}
return rows
}
function loadGearRows() {
var parsed = stringToGearRows(settings.gears_custom_table)
gearRows = parsed.length === 24 ? parsed : defaultGearRows()
updateGearListModel()
saveGearRows()
}
function stringToGearRows(gearString) {
if (!gearString) {
return []
}
var rows = []
var lines = gearString.split("\n")
for (var i = 0; i < lines.length; i++) {
var parts = lines[i].split("|")
if (parts.length < 2) {
continue
}
var gear = parseInt(parts[0])
var offset = clampOffset(parseOffset(parts[1]))
if (gear >= 1 && gear <= 24) {
rows[gear - 1] = { gear: gear, offset: offset }
}
}
var compactRows = []
for (var j = 1; j <= 24; j++) {
compactRows.push(rows[j - 1] ? rows[j - 1] : { gear: j, offset: j })
}
return compactRows
}
function gearRowsToString(rows) {
return rows.map(function(row) {
return row.gear + "|" + clampOffset(parseOffset(row.offset))
}).join("\n")
}
function saveGearRows() {
settings.gears_custom_table = gearRowsToString(gearRows)
}
function updateGearListModel() {
if (!gearListModel) {
return
}
gearListModel.clear()
for (var i = 0; i < gearRows.length; i++) {
gearListModel.append(gearRows[i])
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
IndicatorOnlySwitch {
text: qsTr("Enable Custom Gear Table")
spacing: 0
bottomPadding: 0
topPadding: 0
rightPadding: 0
leftPadding: 0
clip: false
checked: settings.gears_custom_table_enabled
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
onClicked: settings.gears_custom_table_enabled = checked
}
Label {
text: qsTr("Each gear uses the offset below instead of the raw gear value. QZ applies it automatically to resistance, inclination, or slope depending on the trainer path. Default is linear.")
wrapMode: Text.WordWrap
Layout.fillWidth: true
font.pixelSize: Qt.application.font.pixelSize - 2
color: Material.accent
}
Button {
text: qsTr("Reset to Linear Defaults")
Layout.fillWidth: true
Layout.preferredHeight: 40
onClicked: {
gearRows = defaultGearRows()
updateGearListModel()
saveGearRows()
}
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 40
color: "#f0f0f0"
border.width: 1
border.color: "#cccccc"
Row {
anchors.fill: parent
Rectangle {
width: parent.width / 2
height: parent.height
border.width: 1
border.color: "#cccccc"
color: "transparent"
Text {
anchors.centerIn: parent
text: qsTr("Gear")
font.bold: true
color: "black"
}
}
Rectangle {
width: parent.width / 2
height: parent.height
border.width: 1
border.color: "#cccccc"
color: "transparent"
Text {
anchors.centerIn: parent
text: qsTr("Offset")
font.bold: true
color: "black"
}
}
}
}
ListView {
id: gearTable
Layout.fillWidth: true
Layout.preferredHeight: 24 * rowHeight
clip: true
model: gearListModel
Component.onCompleted: {
updateGearListModel()
}
ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AsNeeded
}
delegate: Rectangle {
width: gearTable.width
height: rowHeight
color: index % 2 === 0 ? "white" : "#fafafa"
Row {
anchors.fill: parent
Rectangle {
width: parent.width / 2
height: parent.height
border.width: 1
border.color: "#cccccc"
color: "transparent"
Text {
anchors.centerIn: parent
text: gear
color: "black"
}
}
Rectangle {
width: parent.width / 2
height: parent.height
border.width: 1
border.color: "#cccccc"
color: "transparent"
RowLayout {
anchors.centerIn: parent
width: parent.width * 0.92
height: offsetControlHeight
spacing: 4
Button {
text: "-"
Layout.preferredWidth: 34
Layout.fillHeight: true
onClicked: {
gearRows[index].offset = clampOffset(parseOffset(gearRows[index].offset) - 0.5)
offsetTextField.text = gearRows[index].offset
saveGearRows()
}
}
TextField {
id: offsetTextField
Layout.fillWidth: true
Layout.fillHeight: true
text: offset
color: "black"
selectedTextColor: "white"
selectionColor: Material.accent
horizontalAlignment: Text.AlignHCenter
background: Rectangle {
color: "white"
border.color: "#cccccc"
radius: 2
}
function applyOffset() {
var newOffset = clampOffset(parseOffset(text))
gearRows[index].offset = newOffset
text = newOffset
saveGearRows()
}
onAccepted: applyOffset()
onEditingFinished: applyOffset()
}
Button {
text: "+"
Layout.preferredWidth: 34
Layout.fillHeight: true
onClicked: {
gearRows[index].offset = clampOffset(parseOffset(gearRows[index].offset) + 0.5)
offsetTextField.text = gearRows[index].offset
saveGearRows()
}
}
}
}
}
}
}
}
}