MissionItemStatus.qml 6.29 KB
Newer Older
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
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

import QtQuick          2.5
import QtQuick.Controls 1.3

import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
30
import QGroundControl               1.0
31 32 33 34 35 36 37

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
38 39
    height:     valueGrid.height + (_margins * 2)
    radius:     ScreenTools.defaultFontPixelWidth * 0.5
40 41 42 43 44 45
    color:      qgcPal.window
    opacity:    0.80
    clip:       true

    readonly property real margins: ScreenTools.defaultFontPixelWidth

Don Gagne's avatar
Don Gagne committed
46
    property real   _collapsedWidth:    valueGrid.width + (margins * 2)
47
    property bool   _expanded:          true
Don Gagne's avatar
Don Gagne committed
48 49 50 51 52 53
    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
54 55
    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
56
    property string _gradientText:      _statusValid ? _gradientPercent.toFixed(0) + "%" : ""
57 58 59 60 61 62 63 64 65
    property string _azimuthText:       _statusValid ? Math.round(_azimuth) : ""

    readonly property real _margins:    ScreenTools.defaultFontPixelWidth

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

66 67
    Row {
        anchors.fill:       parent
68
        anchors.margins:    _margins
69
        spacing:            _margins
70

71 72 73 74 75
        Grid {
            id:                 valueGrid
            columns:            2
            columnSpacing:      _margins
            anchors.verticalCenter: parent.verticalCenter
76

77 78
            QGCLabel { text: qsTr("Distance:") }
            QGCLabel { text: _distanceText }
Don Gagne's avatar
Don Gagne committed
79

80 81
            QGCLabel { text: qsTr("Alt diff:") }
            QGCLabel { text: _altText }
82

83 84
            QGCLabel { text: qsTr("Gradient:") }
            QGCLabel { text: _gradientText }
85

86 87 88
            QGCLabel { text: qsTr("Azimuth:") }
            QGCLabel { text: _azimuthText }
        }
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
        QGCFlickable {
            anchors.leftMargin:     _margins
            anchors.rightMargin:    _margins
            anchors.top:            parent.top
            anchors.bottom:         parent.bottom
            width:                  parent.width - valueGrid.width - (_margins * 2)
            contentWidth:           graphRow.width
            visible:                _expanded
            clip:                   true

            Row {
                id:                 graphRow
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                //anchors.margins:    ScreenTools.defaultFontPixelWidth * ScreenTools.smallFontPointRatio
                spacing:            ScreenTools.defaultFontPixelWidth * ScreenTools.smallFontPointRatio

                Repeater {
                    model: missionItems

                    Item {
                        height:     graphRow.height
                        width:      indicator.width
                        visible:    object.specifiesCoordinate && !object.isStandaloneCoordinate

                        property real availableHeight:  height - indicator.height
                        property bool graphAbsolute:    true

                        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)
                        }

                        /*
                          Taking these off for now since there really isn't room for the numbers
                        QGCLabel {
                            anchors.bottom:             parent.bottom
                            anchors.horizontalCenter:   parent.horizontalCenter
                            font.pointSize:             ScreenTools.smallFontPointSize
                            text:                       (object.relativeAltitude ? "" : "=") + object.coordinate.altitude.toFixed(0)
                        }
                        */
137 138 139 140 141 142
                    }
                }
            }
        }
    }
}