-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValveQML.qml
317 lines (276 loc) · 8.82 KB
/
ValveQML.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import QtQuick
import QtQuick.Controls
Item {
id: root
width: 40
height: width
property int valveState: 0 // use Qt.toString(1) to convert a number to string for state
property color enableOff: "red"
property color enableOn: "green"
property color enableStale: "yellow"
property int fontSize: 9
property string valveName: "VALVE"
property int valveID: 0
property int valveCommandOff: 0 // Convert to hex, then from hex convert to string.
property int valveCommandOn: 0 // The extra step could be cut if the conversion to hex results in a string
property alias valveRectItem: valveRect
property alias valveLabelItem: valveLabel
property alias valveImageItem: valveImage //source is set from main qml
property alias valveMouseAreaForMain: valveMouseArea
property alias valveScaleUpItem: valveScaleUp
property alias valveScaleDownItem: valveScaleDown
signal someSignal
// All these items below will pull value from the properties above, which are set my main.qml
Rectangle {
id: valveRect
z: 0
color: "red"
radius: width
anchors.fill: parent
border.color: "white"
border.width: 1.2
//anchors.fill: parent
gradient: Gradient {
GradientStop {id: gradientStop1; position: 0.0; color: "yellow"}
GradientStop {id: gradientStop2; position: 0.05; color: "orange"}
GradientStop {id: gradientStop3; position: 0.5; color: "red"}
GradientStop {id: gradientStop4; position: 0.95; color: "red"}
}
Popup { // shows more info about the valve. Connect this to a button to show the popup up
id: valvePopup
x: 65
y: -10
width: 75
height: 100
modal: false
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
Column {
}
}
Label {
id: valveLabel
width: 30
height: 25
z: 10
text: root.valveName
anchors.verticalCenter: parent.verticalCenter
anchors.bottom: parent.bottom
horizontalAlignment: Text.AlignHCenter
font.pointSize: fontSize
anchors.bottomMargin: 15
anchors.horizontalCenter: parent.horizontalCenter
}
MouseArea
{
id: valveMouseArea // use an alias to expose this to main to handle the doubleClicked signal there. Send on/off commands during offNominal
width: parent.width
height: parent.height
anchors.fill: parent
hoverEnabled: true
enabled: true
onDoubleClicked: // Only Clickable (ie sending valve commands) when vehicle state is in offNominaloffNominaloffNominaloffNominal
{
// if (VehicleState === a number that represents nominal (which is 6))
//{
console.log(valveName);
console.log(valveID);
console.log(valveCommandOff);
console.log(valveCommandOn);
console.log(valveCommandOff.toString(16));
console.log(valveCommandOn.toString(16));
console.log("State before click" + root.state)
if (root.state === "0") // Closed //TESTING ONLY. this directly sets the state in the frontend using QML, which
// interferes with the backend and makes it stop working
{
frameHandler.sendFrame(window.commandFrameID, valveCommandOn.toString(16)) // nominal
}
else
{
frameHandler.sendFrame(window.commandFrameID, valveCommandOff.toString(16)) // nominal
}
/*
else if (root.state === "1") // Open
{
// frameHandler.sendFrame(valveID, valveCommandOff.toString(16)) // nominal
}
else if (root.state === "2") // FireCommanded
{
root.state = "3" // delete this later on
}
else if (root.state === "3") // OpenCommanded
{
root.state = "4" // delete this later on
}
else if (root.state === "4") // CloseCommanded
{
//root.state = "0" // delete this later on
}
*/
console.log("State after click" + root.state)
//}
// if (VehicleState === a number that represents nominal)
// {
// }
}
onEntered:
{
valveScaleUp.start()
}
onExited:
{
valveScaleDown.start()
}
}
/*
RotationAnimation {
id: animation
target: valveRect
loops: Animation.Infinite
from: valveRect.rotation
to: 360
direction: RotationAnimation.Clockwise
duration: 1000
running: true
}
*/
ScaleAnimator{
id: valveScaleUp // when hover over the valve
target: valveRect
from: 1
to: 1.15
duration: 35 // Set this low
running: false
}
ScaleAnimator{
id: valveScaleDown // when cursor exits the valve
target: valveRect
from: 1.15
to: 1
duration: 35 // Set this low
running: false
}
}
Image {
id: valveImage
//source:
}
Label{
}
Button { // Kinda dangerous since its close to the valve, possible to misclick.
// consider putting these in another window?
id: button
y: 45
width: 41
height: 15
text: qsTr("info")
//font: 10
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: -20
onClicked:
{
valvePopup.open()
}
}
states: [
State {
name: "0" // Closed
PropertyChanges {
target: gradientStop1;
color: "red"
}
PropertyChanges {
target: gradientStop2;
color: "red"
}
PropertyChanges {
target: gradientStop3;
color: "red"
}
PropertyChanges {
target: gradientStop4;
color: "red"
}
},
State {
name: "1" // Open
PropertyChanges {
target: gradientStop1;
color: "lawngreen"
}
PropertyChanges {
target: gradientStop2;
color: "lawngreen"
}
PropertyChanges {
target: gradientStop3;
color: "lawngreen"
}
PropertyChanges {
target: gradientStop4;
color: "lawngreen"
}
},
State {
name: "2" // FireCommanded
PropertyChanges {
target: gradientStop1;
color: "darkorange"
}
PropertyChanges {
target: gradientStop2;
color: "darkorange"
}
PropertyChanges {
target: gradientStop3;
color: "darkorange"
}
PropertyChanges {
target: gradientStop4;
color: "darkorange"
}
},
State {
name: "3" // OpenCommanded
PropertyChanges {
target: gradientStop1;
color: "darkorange"
}
PropertyChanges {
target: gradientStop2;
color: "darkorange"
}
PropertyChanges {
target: gradientStop3;
color: "lawngreen"
}
PropertyChanges {
target: gradientStop4;
color: "lawngreen"
}
},
State {
name: "4" // CloseCommanded
PropertyChanges {
target: gradientStop1;
color: "gold"
}
PropertyChanges {
target: gradientStop2;
color: "gold"
}
PropertyChanges {
target: gradientStop3;
color: "red"
}
PropertyChanges {
target: gradientStop4;
color: "red"
}
}
]
Component.onCompleted:
{
}
}