-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
264 lines (240 loc) · 7.74 KB
/
main.qml
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
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Controls.Material 2.1
import QtQuick.Window 2.0
import BackEnd 1.0
ApplicationWindow {
property int uiState: BackEnd.Connecting
property int hidState: BackEnd.HidData
// triggered when save is clicked; components optionally connected-to for before-save validation
signal beforeSave()
// trigger when a view is closed
signal beforeClose()
id: window
title: qsTr("Teensy Fan Controller")
visible: true
width: 575
height: 645
BackEnd {
id: backEnd
objectName: 'backEnd'
}
// log window is always active when application is running (shown using hdr button)
LogWindow {
id: logWindow
visible: false
onVisibleChanged: {
if (visible) {
x = window.width + window.x - 5
y = window.y
if (x + width + 5 > Screen.width)
x -= x + width + 5 - Screen.width;
}
logPageButton.highlighted = visible;
}
}
Connections {
target: backEnd
onHidConnectStatus: function(connecting, dataOnline, logOnline) {
if (connecting)
uiState = BackEnd.Connecting;
else if (dataOnline && logOnline)
uiState = BackEnd.Online;
else if (logOnline)
uiState = BackEnd.NoData;
else if (dataOnline)
uiState = BackEnd.NoLog;
else
uiState = BackEnd.Offline;
}
onHidState: function(state) {
if (state === hidState)
return;
hidState = state;
}
}
function doReconnect() {
uiState = BackEnd.Connecting;
console.log('Reset connection retry limits');
backEnd.reconnect();
}
header: ToolBar {
id: mainToolbar
contentHeight: toolButton.implicitHeight
ToolButton {
id: toolButton
text: stackView.depth > 1 ? "\u25C0" : "\u2630"
onClicked: {
if (stackView.depth > 1) {
if (stackView.depth == 2)
editToolbar.visible = false;
beforeClose() // make sure any changes are not list
stackView.pop()
} else {
drawer.open()
}
}
}
Label {
id: hdrLabel
text: stackView.currentItem.title
anchors.centerIn: parent
font.capitalization: Font.AllUppercase
}
ToolButton {
id: statusButton
visible: stackView.depth <= 1
icon.source: "images/worldwide.svg"
icon.height: 20
icon.width: 20
icon.color: {
return uiState === BackEnd.Offline
? 'red'
: (uiState === BackEnd.Online
? '#ededed'
: (uiState === BackEnd.Connecting ? 'gray' : 'yellow'))
}
display: AbstractButton.IconOnly
anchors.left: hdrLabel.right
ToolTip {
visible: parent.hovered
text: {
return qsTr(uiState === BackEnd.Offline
? "Log Not Connected\nData Not Connected"
: (uiState === BackEnd.Connecting
? 'Connecting'
: (uiState === BackEnd.NoLog
? 'Log Not Connected'
: (uiState === BackEnd.NoData ? 'Data Not Connected' : 'Connected')))) +
(uiState !== BackEnd.Online && uiState !== BackEnd.Connecting ? "\nClick to retry connection" : '')
}
}
onClicked: {
if (hidState !== BackEnd.HidData)
return;
if (uiState !== BackEnd.Online && uiState !== BackEnd.Connecting) {
doReconnect();
}
}
}
ToolButton {
id: logPageButton
icon.source: "images/log.svg"
icon.height: 20
icon.width: 20
display: AbstractButton.IconOnly
anchors.right: parent.right
onClicked: {
if (!highlighted)
logWindow.show()
else
logWindow.hide()
}
}
}
footer: ToolBar {
id: editToolbar
visible: false
contentHeight: saveButton.implicitHeight
ToolButton {
id: saveButton
anchors.right: parent.right
text: qsTr("Save")
onClicked: {
if (hidState !== BackEnd.HidData)
return;
window.beforeSave()
backEnd.save()
}
}
}
Drawer {
id: drawer
width: Math.max(115, Math.min(window.width * 0.65, 255))
height: window.height
Column {
anchors.fill: parent
ItemDelegate {
text: qsTr("Fan Setup")
width: parent.width
onClicked: {
editToolbar.visible = true
stackView.push("fans.qml")
drawer.close()
}
}
ItemDelegate {
text: qsTr("Hardware Setup")
width: parent.width
onClicked: {
editToolbar.visible = true
stackView.push("hardware.qml")
drawer.close()
}
}
ItemDelegate {
text: qsTr("Log")
width: parent.width
onClicked: {
if (logWindow.visible)
logWindow.requestActivate()
else
logWindow.show()
drawer.close()
}
}
// ItemDelegate {
// text: qsTr("Graph")
// width: parent.width
// onClicked: {
// stackView.push("history.qml")
// drawer.close()
// }
// }
}
}
StackView {
id: stackView
objectName: 'stackView'
initialItem: "pv.qml"
anchors.fill: parent
}
// Not Connected indicator
Rectangle {
id: uiIndicator
visible: uiState === BackEnd.Connecting || uiState === BackEnd.Offline || uiState === BackEnd.NoData
height: 25
width: 155
anchors.top: mainToolbar.bottom
anchors.right: parent.right
color: "transparent"
Label {
text: qsTr("\u26a0 Not Connected")
color: "#333333"
anchors.centerIn: parent
font.capitalization: Font.AllUppercase
}
}
// Config Download indicator
Rectangle {
visible: !uiIndicator.visible && hidState !== BackEnd.HidData
height: 25
width: 255
anchors.top: mainToolbar.bottom
anchors.right: parent.right
color: "transparent"
Label {
text: qsTr(hidState === BackEnd.HidConfig ? "\u26a0 Downloading Configuration" : "\u26a0 Saving Configuration")
color: "#333333"
anchors.centerIn: parent
font.capitalization: Font.AllUppercase
}
}
// Darken screen when Not Connected or config download/upload is active
Rectangle {
anchors.fill: parent
opacity: 0.35
color: 'gray'
visible: hidState !== BackEnd.HidData || uiState === BackEnd.Connecting
}
}