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

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

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0
18
import QGroundControl.Vehicle               1.0
19 20 21 22

Item {
    anchors.top:    parent.top
    anchors.bottom: parent.bottom
23
    width:          primaryLinkSelector.width
24

25
    property bool showIndicator: false
26

27 28 29 30
    property var _activeVehicle:    QGroundControl.multiVehicleManager.activeVehicle
    property var _rgLinkNames:      _activeVehicle ? _activeVehicle.vehicleLinkManager.linkNames : [ ]
    property var _rgLinkStatus:     _activeVehicle ? _activeVehicle.vehicleLinkManager.linkStatuses : [ ]
    property var _rgMenuItems:      [ ]
31

32 33 34 35 36
    function updateLinkSelectionMenu() {
        // Remove old menu items
        var i
        for (i = 0; i < _rgMenuItems.length; i++) {
            linkSelectionMenu.removeItem(_rgMenuItems[i])
37
        }
38
        _rgMenuItems.length = 0
39

40 41 42 43 44
        // Add new items
        for (i = 0; i < _rgLinkNames.length; i++) {
            var menuItem = linkSelectionMenuItemComponent.createObject(null, { "text": _rgLinkNames[i] + " " + _rgLinkStatus[i] })
            _rgMenuItems.push(menuItem)
            linkSelectionMenu.insertItem(i, menuItem)
45
        }
acfloria's avatar
acfloria committed
46

47 48
        showIndicator = _rgLinkNames.length > 1
    }
49

50 51 52 53 54 55 56 57 58 59
    Component.onCompleted:  updateLinkSelectionMenu()
    on_RgLinkNamesChanged:  updateLinkSelectionMenu()
    on_RgLinkStatusChanged: updateLinkSelectionMenu()

    QGCLabel {
        id:                     primaryLinkSelector
        anchors.verticalCenter: parent.verticalCenter
        text:                   _activeVehicle ? _activeVehicle.vehicleLinkManager.primaryLinkName : ""
        font.pointSize:         ScreenTools.mediumFontPointSize
        color:                  qgcPal.buttonText
60

61 62 63 64 65
        MouseArea {
            anchors.fill:   parent
            onClicked:      linkSelectionMenu.popup()
        }
    }
66 67 68 69 70 71 72 73 74

    QGCMenu { id: linkSelectionMenu }

    Component {
        id: linkSelectionMenuItemComponent
        QGCMenuItem {
            onTriggered: _activeVehicle.vehicleLinkManager.primaryLinkName = text
        }
    }
75
}