MissionItemStatus.qml 5.21 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
9 10 11 12 13 14 15 16


import QtQuick          2.5
import QtQuick.Controls 1.3

import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
17
import QGroundControl               1.0
18 19 20 21 22 23 24

Rectangle {
    property var    currentMissionItem          ///< Mission item to display status for
    property var    missionItems                ///< List of all available mission items
    property real   expandedWidth               ///< Width of control when expanded

    width:      _expanded ? expandedWidth : _collapsedWidth
25 26
    height:     valueGrid.height + (_margins * 2)
    radius:     ScreenTools.defaultFontPixelWidth * 0.5
27 28 29 30 31 32
    color:      qgcPal.window
    opacity:    0.80
    clip:       true

    readonly property real margins: ScreenTools.defaultFontPixelWidth

Don Gagne's avatar
Don Gagne committed
33
    property real   _collapsedWidth:    valueGrid.width + (margins * 2)
34
    property bool   _expanded:          true
Don Gagne's avatar
Don Gagne committed
35 36 37 38 39 40
    property real   _distance:          _statusValid ? _currentMissionItem.distance : 0
    property real   _altDifference:     _statusValid ? _currentMissionItem.altDifference : 0
    property real   _gradient:          _statusValid ? Math.atan(_currentMissionItem.altDifference / _currentMissionItem.distance) : 0
    property real   _gradientPercent:   isNaN(_gradient) ? 0 : _gradient * 100
    property real   _azimuth:           _statusValid ? _currentMissionItem.azimuth : -1
    property bool   _statusValid:       currentMissionItem != undefined
41 42
    property string _distanceText:      _statusValid ? QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(2) + " " + QGroundControl.appSettingsDistanceUnitsString : ""
    property string _altText:           _statusValid ? QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(2) + " " + QGroundControl.appSettingsDistanceUnitsString : ""
Don Gagne's avatar
Don Gagne committed
43
    property string _gradientText:      _statusValid ? _gradientPercent.toFixed(0) + "%" : ""
44 45 46 47 48 49 50 51 52
    property string _azimuthText:       _statusValid ? Math.round(_azimuth) : ""

    readonly property real _margins:    ScreenTools.defaultFontPixelWidth

    MouseArea {
        anchors.fill:   parent
        onClicked:      _expanded = !_expanded
    }

53 54
    Row {
        anchors.fill:       parent
55
        anchors.margins:    _margins
56
        spacing:            _margins
57

58 59 60 61 62
        Grid {
            id:                 valueGrid
            columns:            2
            columnSpacing:      _margins
            anchors.verticalCenter: parent.verticalCenter
63

64 65
            QGCLabel { text: qsTr("Distance:") }
            QGCLabel { text: _distanceText }
Don Gagne's avatar
Don Gagne committed
66

67 68
            QGCLabel { text: qsTr("Alt diff:") }
            QGCLabel { text: _altText }
69

70 71
            QGCLabel { text: qsTr("Gradient:") }
            QGCLabel { text: _gradientText }
72

73 74 75
            QGCLabel { text: qsTr("Azimuth:") }
            QGCLabel { text: _azimuthText }
        }
76

77
        ListView {
78 79
            id:                     statusListView
            model:                  missionItems
80
            highlightMoveDuration:  250
81 82 83 84
            anchors.leftMargin:     _margins
            anchors.rightMargin:    _margins
            anchors.top:            parent.top
            anchors.bottom:         parent.bottom
85
            orientation:            ListView.Horizontal
86
            spacing:                0
87
            visible:                _expanded
88
            width:                  parent.width - valueGrid.width - (_margins * 2)
89
            clip:                   true
90

91 92
            delegate: Item {
                height:     statusListView.height
93 94
                width:      display ? (indicator.width + spacing)  : 0
                visible:    display
95 96 97

                property real availableHeight:  height - indicator.height
                property bool graphAbsolute:    true
98 99
                readonly property bool display: object.specifiesCoordinate && !object.isStandaloneCoordinate
                readonly property real spacing: ScreenTools.defaultFontPixelWidth * ScreenTools.smallFontPointRatio
100 101 102 103 104 105 106 107 108 109

                MissionItemIndexLabel {
                    id:                         indicator
                    anchors.horizontalCenter:   parent.horizontalCenter
                    y:                          availableHeight - (availableHeight * object.altPercent)
                    small:                      true
                    isCurrentItem:              object.isCurrentItem
                    label:                      object.abbreviation
                    visible:                    object.relativeAltitude ? true : (object.homePosition || graphAbsolute)
                }
110

111 112
                Connections {
                    target: object
113

114 115 116
                    onIsCurrentItemChanged: {
                        if (object.isCurrentItem) {
                            statusListView.currentIndex = index
117
                        }
118 119 120 121 122 123
                    }
                }
            }
        }
    }
}