-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDroneTrackingPanel.qml
More file actions
607 lines (521 loc) · 27.2 KB
/
DroneTrackingPanel.qml
File metadata and controls
607 lines (521 loc) · 27.2 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import "qrc:/gcsStyle" as GcsStyle
import "./components"
import "./components" as Components
/*
Welcome to the wild west....
We say GcsStyle.PanelStyle because that is how it is defined as a singleton
Our singleton definition is in /gcsStyle/qmldir
This might be some of the nastiest code ever written... CSS/QSS is hell
*/
Rectangle {
id: mainPanel
width: 350
color: GcsStyle.PanelStyle.surfaceBackground
border.color: GcsStyle.panelStyle.defaultBorderColor
border.width: 0 // remove the border
signal selectionChanged(var selectedDrones) // Broadcast the current selection so other components (telemetry, commands, etc.) stay in sync
signal activeDroneChanged(var anchor) // Broadcast the current anchor which will be used as the active drone
signal followRequested(var drone) // Dedicated signal for the "follow" shortcut so main.qml can toggle map following
property var selectedIndexes: [] // Stores which rows are selected
property int lastSelectedIndex: -1 // Remembers last drone the user clicked (so Shift-click knows where to start)
property int selectionAnchorIndex: -1 // Anchor index used for Shift-range selections
property bool multiSelectActive: selectedIndexes.length > 1
property string activePanel: "drones" // "drones", "discovery"
RowLayout {
anchors.fill: parent
spacing: 0
anchors.margins: parent.border.width
// Left vertical bar
Rectangle {
// TODO: Turn each of these buttons that select the view into a component.
// This should just be a list
Layout.fillHeight: true
width: 65
color: GcsStyle.PanelStyle.baseBackground
clip: true
border.color: GcsStyle.panelStyle.defaultBorderColor
border.width: GcsStyle.panelStyle.defaultBorderWidth
ColumnLayout {
anchors.fill: parent
anchors.topMargin: GcsStyle.PanelStyle.sidebarTopMargin
spacing: GcsStyle.PanelStyle.buttonSpacing // Small space between buttons
// Toggle button 1
Rectangle {
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: GcsStyle.PanelStyle.buttonSize
Layout.preferredHeight: GcsStyle.PanelStyle.buttonSize
property bool hovered: false
color: mainPanel.activePanel === "drones" ? GcsStyle.PanelStyle.buttonActiveColor
: (hovered ? GcsStyle.PanelStyle.hoverBackground : GcsStyle.PanelStyle.buttonColor)
border.color: mainPanel.activePanel === "drones" ? GcsStyle.PanelStyle.listItemSelectedBorderColor : "transparent"
border.width: mainPanel.activePanel === "drones" ? GcsStyle.PanelStyle.defaultBorderWidth : 0
radius: 8
Image {
anchors.right: parent.right
anchors.rightMargin: GcsStyle.PanelStyle.iconRightMargin
anchors.verticalCenter: parent.verticalCenter
source: GcsStyle.PanelStyle.isLightTheme ? "qrc:/resources/droneSVG.svg" : "qrc:/resources/droneStatusDarkMode.svg"
sourceSize.width: GcsStyle.PanelStyle.iconSize
sourceSize.height: GcsStyle.PanelStyle.iconSize
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: parent.hovered = true
onExited: parent.hovered = false
onClicked: {
mainPanel.activePanel = "drones"
droneController.rebuildVariant()
}
}
}
// Toggle button 2 - Mission Planning
Rectangle {
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: GcsStyle.PanelStyle.buttonSize
Layout.preferredHeight: GcsStyle.PanelStyle.buttonSize
property bool hovered: false
color: mainPanel.activePanel === "mission" ? GcsStyle.PanelStyle.buttonActiveColor
: (hovered ? GcsStyle.PanelStyle.hoverBackground : GcsStyle.PanelStyle.buttonColor)
border.color: mainPanel.activePanel === "mission" ? GcsStyle.PanelStyle.listItemSelectedBorderColor : "transparent"
border.width: mainPanel.activePanel === "mission" ? GcsStyle.PanelStyle.defaultBorderWidth : 0
radius: 8
Image {
anchors.right: parent.right
anchors.rightMargin: GcsStyle.PanelStyle.iconRightMargin
anchors.verticalCenter: parent.verticalCenter
source: GcsStyle.PanelStyle.isLightTheme ? "qrc:/resources/missionPlanningIcon.svg" : "qrc:/resources/missionPlanningIcon.svg"
sourceSize.width: GcsStyle.PanelStyle.iconSize
sourceSize.height: GcsStyle.PanelStyle.iconSize
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: parent.hovered = true
onExited: parent.hovered = false
onClicked: {mainPanel.activePanel = "mission"}
}
}
// Toggle button 3
Rectangle {
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: GcsStyle.PanelStyle.buttonSize
Layout.preferredHeight: GcsStyle.PanelStyle.buttonSize
property bool hovered: false
color: mainPanel.activePanel === "discovery" ? GcsStyle.PanelStyle.buttonActiveColor
: (hovered ? GcsStyle.PanelStyle.hoverBackground : GcsStyle.PanelStyle.buttonColor)
border.color: mainPanel.activePanel === "discovery" ? GcsStyle.PanelStyle.listItemSelectedBorderColor : "transparent"
border.width: mainPanel.activePanel === "discovery" ? GcsStyle.PanelStyle.defaultBorderWidth : 0
radius: 8
Image {
anchors.right: parent.right
anchors.rightMargin: GcsStyle.PanelStyle.iconRightMargin
anchors.verticalCenter: parent.verticalCenter
source: GcsStyle.PanelStyle.isLightTheme ? "qrc:/resources/discoveryPanelIcon.svg" : "qrc:/resources/discoveryPanelIconDarkMode.svg"
sourceSize.width: GcsStyle.PanelStyle.iconSize
sourceSize.height: GcsStyle.PanelStyle.iconSize
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: parent.hovered = true
onExited: parent.hovered = false
onClicked: {
mainPanel.activePanel = "discovery"
droneController.loadUnknownDrones()
}
}
}
Item { Layout.fillHeight: true } // Bottom spacer to push buttons up
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 0
// Header
Rectangle {
Layout.fillWidth: true
height: 80
color: GcsStyle.PanelStyle.primaryColor
radius: GcsStyle.PanelStyle.cornerRadius
clip: true
ColumnLayout {
anchors.fill: parent
anchors.margins: GcsStyle.PanelStyle.defaultMargin
spacing: 0
Text {
text: {
switch (mainPanel.activePanel) {
case "drones": return "Drone List"
case "mission": return "Mission Planning"
case "discovery": return "UAV Discovery"
}
}
font.pixelSize: GcsStyle.PanelStyle.headerFontSize
font.family: GcsStyle.PanelStyle.fontFamily
color: GcsStyle.PanelStyle.textOnPrimaryColor
font.underline: true
}
Text {
text: {
switch (mainPanel.activePanel) {
case "drones":
return droneController ? "Drones in fleet: " + droneController.drones.length : "0 drones in fleet"
case "mission":
return droneController ? "Drones in fleet: " + droneController.drones.length : "0 drones in fleet"
case "discovery":
return droneController ? droneController.unknownDrones.filter(u => !u.ignored).length + " discovered UAVs" : "0 discovered UAVs"
}
}
font.pixelSize: GcsStyle.PanelStyle.subHeaderFontSize
font.family: GcsStyle.PanelStyle.fontFamily
color: GcsStyle.PanelStyle.textOnPrimaryColor
}
}
}
// ==========================================
// Drone list view
UAVListPanel {
id: trackDroneListPanel
panel: mainPanel
listModel: droneController.drones
inactiveCount: 0
visible: mainPanel.activePanel === "drones"
}
// ==========================================
// Mission Planning View
UAVMissionListPanel {
id: trackUAVMissionPanel
panel: mainPanel
listModel: droneController.drones
visible: mainPanel.activePanel === "mission"
}
// ==========================================
// Discovery panel view
// TODO: Turn this panel into a component
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: mainPanel.activePanel === "discovery"
spacing: 0
// Search bar
Rectangle {
Layout.fillWidth: true
Layout.leftMargin: 8
Layout.rightMargin: 8
Layout.bottomMargin: 8
height: 36
color: GcsStyle.PanelStyle.baseBackground
border.color: GcsStyle.panelStyle.defaultBorderColor
border.width: GcsStyle.panelStyle.defaultBorderWidth
radius: 8
RowLayout {
anchors.fill: parent
anchors.leftMargin: GcsStyle.PanelStyle.defaultMargin
anchors.rightMargin: GcsStyle.PanelStyle.defaultMargin
spacing: 6
TextInput {
id: discoverySearchInput
Layout.fillWidth: true
color: GcsStyle.PanelStyle.textPrimaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeMedium
font.family: GcsStyle.PanelStyle.fontFamily
clip: true
Text {
anchors.fill: parent
text: "Search..."
color: GcsStyle.PanelStyle.textSecondaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeMedium
font.family: GcsStyle.PanelStyle.fontFamily
visible: !discoverySearchInput.text
}
}
}
}
ListView {
id: discoveryListView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
property int selectedIndex: -1
model: droneController.unknownDrones.filter(u => !u.ignored)
delegate: Rectangle {
id: discoveredItem
width: ListView.view.width
clip: true
// Hides ignored drones
height: visible ? (expanded ? 110 : GcsStyle.PanelStyle.itemHeight) : 0
visible: !modelData.ignored // only shows the discovered drone if it isn't ignored
// local UI state
property bool expanded: false
property bool hovered: false
property bool selected: discoveryListView.selectedIndex === index
// when selected changes colors
color: selected
? GcsStyle.PanelStyle.listItemSelectedColor
: (hovered
? GcsStyle.PanelStyle.hoverBackground
: GcsStyle.PanelStyle.cardBackground)
border.color: selected
? GcsStyle.PanelStyle.listItemSelectedBorderColor
: GcsStyle.panelStyle.defaultBorderColor
border.width: GcsStyle.panelStyle.defaultBorderWidth
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: discoveredItem.hovered = true
onExited: discoveredItem.hovered = false
onClicked: {
discoveredItem.expanded = !discoveredItem.expanded
discoveryListView.selectedIndex =
(discoveryListView.selectedIndex === index )
? -1 : index
}
}
ColumnLayout {
anchors.left: parent.left
anchors.right: parent.right
RowLayout {
id: collapsedView
Layout.fillWidth: true
Layout.margins: GcsStyle.PanelStyle.defaultMargin
spacing: 15
//drone icon
Item {
width: 23
height: 23
Layout.alignment: Qt.AlignVCenter
Layout.leftMargin: 8
Image {
anchors.centerIn: parent
source: GcsStyle.PanelStyle.isLightTheme
? "qrc:/resources/droneStatusLightMode.svg"
: "qrc:/resources/droneStatusDarkMode.svg"
sourceSize.width: GcsStyle.PanelStyle.iconSize + 8
sourceSize.height: GcsStyle.PanelStyle.iconSize + 8
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.leftMargin: 8
spacing: 2
Text {
text: modelData.uavType
color: GcsStyle.PanelStyle.textPrimaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeMedium
font.family: GcsStyle.PanelStyle.fontFamily
Layout.fillWidth: true
elide: Text.ElideRight
font.bold: true
}
Text {
text: "UID: " + modelData.uid;
color: GcsStyle.PanelStyle.textPrimaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeXXS
font.family: GcsStyle.PanelStyle.fontFamily
}
Text {
text: "FC: " + modelData.fc;
color: GcsStyle.PanelStyle.textPrimaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeXXS
font.family: GcsStyle.PanelStyle.fontFamily
}
}
RowLayout {
Layout.alignment: Qt.AlignRight
spacing: 4
//spacer all buttons are pushed towards the right
Item { Layout.fillWidth: true }
// Add drone button
Button {
Layout.preferredHeight: 27
Layout.preferredWidth: 27
padding: 0
contentItem: Item {
anchors.fill: parent
Image {
anchors.centerIn: parent
source: "qrc:/resources/plusIcon.png"
height: GcsStyle.PanelStyle.statusIconSize
width: GcsStyle.PanelStyle.statusIconSize
fillMode: Image.PreserveAspectFit
}
}
background: Rectangle {
radius: GcsStyle.PanelStyle.buttonRadius
color: "#b0ffa8"
}
MouseArea {
// This mouse area gives us the ability to add a pointer hand when the button is hovered
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
console.log("added!")
droneController.acceptUnknownDrone(modelData.uid);
discoveryListView.selectedIndex = -1
}
}
}
// Ignore drone button
Button {
Layout.preferredHeight: 27
Layout.preferredWidth: 27
padding: 0
contentItem: Item {
anchors.fill: parent
Image {
anchors.centerIn: parent
source: "qrc:/resources/xIcon.png"
height: GcsStyle.PanelStyle.statusIconSize
width: GcsStyle.PanelStyle.statusIconSize
fillMode: Image.PreserveAspectFit
}
}
background: Rectangle {
radius: GcsStyle.PanelStyle.buttonRadius
color: "#ffa8a8"
}
MouseArea {
// This mouse area gives us the ability to add a pointer hand when the button is hovered
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
console.log("ignore")
droneController.setUnknownDroneIgnored(modelData.uid, true)
discoveryListView.selectedIndex = -1
}
}
}
}
}
Item {
id: expandedView
visible: discoveredItem.expanded
Layout.fillWidth: true
ColumnLayout {
anchors.fill: parent
Text {
Layout.fillWidth: true
Layout.margins: GcsStyle.PanelStyle.defaultMargin
text: "more drone info..."
color: GcsStyle.PanelStyle.textPrimaryColor
font.pixelSize: GcsStyle.PanelStyle.fontSizeXXS
font.family: GcsStyle.PanelStyle.fontFamily
horizontalAlignment: Text.AlignHCenter
}
}
}
}
}
Connections {
target: droneController
function onUnknownDronesChanged() {
discoveryListView.model = droneController ? droneController.unknownDrones : []
}
}
}
}
}
}
//Helper Functions for drone selection
// Function to clear current selection highlight
function clearSelection() {
updateSelection([], -1)
selectionAnchorIndex = -1
emitSelectionChanged()
}
// Select exactly one row (used for normal clicks and follow shortcut)
function setSingleSelection(idx) {
updateSelection([idx], idx)
selectionAnchorIndex = idx
}
// Add/remove a row from the current selection while preserving order
function toggleSelection(idx) {
var newSelection = selectedIndexes.slice()
var existing = newSelection.indexOf(idx)
if (existing === -1) {
newSelection.push(idx)
updateSelection(newSelection, idx)
selectionAnchorIndex = idx
} else {
newSelection.splice(existing, 1)
var nextLast = newSelection.length > 0 ? newSelection[newSelection.length - 1] : -1
updateSelection(newSelection, nextLast)
if (selectionAnchorIndex === idx) {
selectionAnchorIndex = nextLast
}
}
}
// Build a contiguous selection between two indexes (shift-click behavior)
function selectRange(startIdx, endIdx) {
if (startIdx === -1) {
setSingleSelection(endIdx)
return
}
var from = Math.min(startIdx, endIdx)
var to = Math.max(startIdx, endIdx)
var rangeSelection = []
for (var i = from; i <= to; ++i) {
rangeSelection.push(i)
}
updateSelection(rangeSelection, endIdx)
}
// Normalize, de-duplicate, and store the new selection state
function updateSelection(selectionArray, lastIndex) {
var sorted = selectionArray.slice().sort(function(a, b) { return a - b })
var deduped = []
for (var i = 0; i < sorted.length; ++i) {
if (deduped.length === 0 || deduped[deduped.length - 1] !== sorted[i]) {
deduped.push(sorted[i])
}
}
selectedIndexes = deduped
lastSelectedIndex = lastIndex
syncCurrentIndex()
}
// Keep ListView's built-in currentIndex aligned with our selection rules
function syncCurrentIndex() {
if (selectedIndexes.length === 1) {
trackDroneListPanel.uavListPanel.currentIndex = selectedIndexes[0]
} else {
trackDroneListPanel.uavListPanel.currentIndex = -1
}
}
function isIndexSelected(idx) {
return selectedIndexes.indexOf(idx) !== -1
}
// Turn selected indexes into real drone objects and emit the public signal
function emitSelectionChanged() {
var selected = []
var model = trackDroneListPanel.uavListPanel.model
for (var i = 0; i < selectedIndexes.length; ++i) {
var idx = selectedIndexes[i]
if (idx >= 0 && idx < trackDroneListPanel.uavListPanel.count) {
var droneData = model && model[idx] !== undefined ? model[idx] : null
if (droneData) {
selected.push(droneData)
}
}
}
selectionChanged(selected)
}
// Whenever the selection changes, the active drone has a chance of also changing
// This will let main.qml know the active drone is updated
onSelectionChanged: function(selected) {
var idx = selectionAnchorIndex
if (idx < 0 || idx >= trackDroneListPanel.uavListPanel.count) {
activeDroneChanged(null)
return
}
var model = trackDroneListPanel.uavListPanel.model
var drone = model ? model[idx] : null
activeDroneChanged(drone)
}
}