LinkIndicator.qml 3.45 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/


11 12
import QtQuick                              2.11
import QtQuick.Controls                     2.4
13 14 15 16 17 18

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0
19
import QGroundControl.Vehicle               1.0
20 21 22 23 24 25

//-------------------------------------------------------------------------
//-- Link Indicator
Item {
    anchors.top:    parent.top
    anchors.bottom: parent.bottom
26
    width:          priorityLinkSelector.width
27

28
    property bool showIndicator: false
29

30 31
    property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

32 33
    QGCLabel {
        id:                     priorityLinkSelector
34
        text:                   _activeVehicle ? _activeVehicle.priorityLinkName : qsTr("N/A", "No data to display")
35 36 37
        font.pointSize:         ScreenTools.mediumFontPointSize
        color:                  qgcPal.buttonText
        anchors.verticalCenter: parent.verticalCenter
38
        QGCMenu {
39 40 41 42
            id: linkSelectionMenu
        }
        Component {
            id: linkSelectionMenuItemComponent
43
            QGCMenuItem {
44
                onTriggered: _activeVehicle.priorityLinkName = text
45 46 47 48
            }
        }
        property var linkSelectionMenuItems: []
        function updatelinkSelectionMenu() {
49
            if (_activeVehicle) {
50
                // Remove old menu items
Gus Grubba's avatar
Gus Grubba committed
51 52
                var i
                for (i = 0; i < linkSelectionMenuItems.length; i++) {
53 54 55
                    linkSelectionMenu.removeItem(linkSelectionMenuItems[i])
                }
                linkSelectionMenuItems.length = 0
56

57
                // Add new items
58
                var has_hl = false;
59
                var links = _activeVehicle.links
Gus Grubba's avatar
Gus Grubba committed
60
                for (i = 0; i < links.length; i++) {
61
                    var menuItem = linkSelectionMenuItemComponent.createObject(null, { "text": links[i].getName(), "enabled": links[i].link_active(_activeVehicle.id)})
62 63
                    linkSelectionMenuItems.push(menuItem)
                    linkSelectionMenu.insertItem(i, menuItem)
64 65 66 67

                    if (links[i].getHighLatency()) {
                        has_hl = true
                    }
68
                }
69

70
                showIndicator = links.length > 1 && has_hl
71 72
            }
        }
73

74
        Component.onCompleted: priorityLinkSelector.updatelinkSelectionMenu()
acfloria's avatar
acfloria committed
75

76 77 78 79
        Connections {
            target:                 QGroundControl.multiVehicleManager
            onActiveVehicleChanged: priorityLinkSelector.updatelinkSelectionMenu()
        }
acfloria's avatar
acfloria committed
80

81
        Connections {
82 83
            target:         _activeVehicle
            onLinksChanged: priorityLinkSelector.updatelinkSelectionMenu()
84
        }
85 86

        Connections {
87
            target:                     _activeVehicle
88 89 90
            onLinksPropertiesChanged:   priorityLinkSelector.updatelinkSelectionMenu()
        }

91
        MouseArea {
92
            visible:        _activeVehicle
93 94 95 96 97
            anchors.fill:   parent
            onClicked:      linkSelectionMenu.popup()
        }
    }
}