ModeIndicator.qml 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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.3
import QtQuick.Controls 1.2
13 14 15 16 17 18 19 20 21

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0

//-------------------------------------------------------------------------
//-- Mode Indicator
22 23 24 25
Item {
    anchors.top:    parent.top
    anchors.bottom: parent.bottom
    width:          flightModeSelector.width
26

27
    property var _flightModes:      activeVehicle ? activeVehicle.flightModes : [ ]
28 29

    on_FlightModesChanged: flightModeSelector.updateFlightModesMenu()
30

31 32
    QGCLabel {
        id:                     flightModeSelector
33
        text:                   activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
34 35 36 37 38
        font.pointSize:         ScreenTools.mediumFontPointSize
        color:                  qgcPal.buttonText
        anchors.verticalCenter: parent.verticalCenter
        Menu {
            id: flightModesMenu
39
        }
40 41 42
        Component {
            id: flightModeMenuItemComponent
            MenuItem {
43
                onTriggered: activeVehicle.flightMode = text
44
            }
45 46 47
        }
        property var flightModesMenuItems: []
        function updateFlightModesMenu() {
48
            if (activeVehicle && activeVehicle.flightModeSetAvailable) {
49
                // Remove old menu items
Gus Grubba's avatar
Gus Grubba committed
50 51
                var i
                for (i = 0; i < flightModesMenuItems.length; i++) {
52 53 54 55
                    flightModesMenu.removeItem(flightModesMenuItems[i])
                }
                flightModesMenuItems.length = 0
                // Add new items
Gus Grubba's avatar
Gus Grubba committed
56
                for (i = 0; i < _flightModes.length; i++) {
57
                    var menuItem = flightModeMenuItemComponent.createObject(null, { "text": _flightModes[i] })
58 59 60
                    flightModesMenuItems.push(menuItem)
                    flightModesMenu.insertItem(i, menuItem)
                }
61 62
            }
        }
63 64
        Component.onCompleted: flightModeSelector.updateFlightModesMenu()
        MouseArea {
65
            visible:        activeVehicle && activeVehicle.flightModeSetAvailable
66 67 68
            anchors.fill:   parent
            onClicked:      flightModesMenu.popup()
        }
69 70
    }
}