VehicleSummary.qml 6.18 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
/*=====================================================================

 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/>.

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

24 25 26
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
27

28
import QGroundControl                       1.0
29 30 31 32
import QGroundControl.FactSystem            1.0
import QGroundControl.Controls              1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
33
import QGroundControl.Palette               1.0
34 35

Rectangle {
dogmaphobic's avatar
dogmaphobic committed
36 37 38 39
    id:             _summaryRoot
    anchors.fill:   parent
    color:          qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
40
    property real _minSummaryW:     ScreenTools.defaultFontPixelWidth * 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    property real _summaryBoxWidth: _minSummaryW
    property real _summaryBoxSpace: ScreenTools.defaultFontPixelWidth

    function computeSummaryBoxSize() {
        var sw  = 0
        var rw  = 0
        var idx = Math.floor(_summaryRoot.width / (_minSummaryW + ScreenTools.defaultFontPixelWidth))
        if(idx < 1) {
            _summaryBoxWidth = _summaryRoot.width
            _summaryBoxSpace = 0
        } else {
            _summaryBoxSpace = 0
            if(idx > 1) {
                _summaryBoxSpace = ScreenTools.defaultFontPixelWidth
                sw = _summaryBoxSpace * (idx - 1)
            }
            rw = _summaryRoot.width - sw
            _summaryBoxWidth = rw / idx
        }
    }
dogmaphobic's avatar
dogmaphobic committed
61 62 63 64

    function capitalizeWords(sentence) {
        return sentence.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
    }
65

66 67 68 69 70 71 72 73 74 75 76 77
    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

    Component.onCompleted: {
        computeSummaryBoxSize()
    }

    onWidthChanged: {
        computeSummaryBoxSize()
    }
78

Don Gagne's avatar
Don Gagne committed
79
    QGCFlickable {
dogmaphobic's avatar
dogmaphobic committed
80 81
        clip:               true
        anchors.fill:       parent
82 83
        contentHeight:      summaryColumn.height
        contentWidth:       _summaryRoot.width
dogmaphobic's avatar
dogmaphobic committed
84
        flickableDirection: Flickable.VerticalFlick
85 86 87 88 89 90 91 92 93 94 95

        Column {
            id:             summaryColumn
            width:          _summaryRoot.width
            spacing:        ScreenTools.defaultFontPixelHeight

            QGCLabel {
                width:			parent.width
                wrapMode:		Text.WordWrap
                color:			setupComplete ? qgcPal.text : qgcPal.warningText
                font.weight:    Font.DemiBold
dogmaphobic's avatar
dogmaphobic committed
96
                horizontalAlignment: Text.AlignHCenter
97
                text:           setupComplete ?
98 99
                    qsTr("Below you will find a summary of the settings for your vehicle. To the left are the setup menus for each component.") :
                    qsTr("WARNING: Your vehicle requires setup prior to flight. Please resolve the items marked in red using the menu on the left.")
100
                property bool setupComplete: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.setupComplete : false
101
            }
102

103 104 105 106
            Flow {
                id:         _flowCtl
                width:      _summaryRoot.width
                spacing:    _summaryBoxSpace
Don Gagne's avatar
Don Gagne committed
107

108
                Repeater {
109
                    model: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : undefined
110

111
                    // Outer summary item rectangle
Don Gagne's avatar
Don Gagne committed
112
                    Rectangle {
113 114 115
                        width:      _summaryBoxWidth
                        height:     ScreenTools.defaultFontPixelHeight * 13
                        color:      qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
116
                        visible:    modelData.summaryQmlSource.toString() !== ""
117 118 119 120

                        readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 2

                        // Title bar
121
                        QGCButton {
122 123 124
                            id:     titleBar
                            width:  parent.width
                            height: titleHeight
dogmaphobic's avatar
dogmaphobic committed
125
                            text:   capitalizeWords(modelData.name)
126 127 128

                            // Setup indicator
                            Rectangle {
dogmaphobic's avatar
dogmaphobic committed
129
                                anchors.rightMargin:    ScreenTools.defaultFontPixelWidth * 0.5
130 131
                                anchors.right:          parent.right
                                anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
132
                                width:                  ScreenTools.defaultFontPixelWidth * 1.5
133 134 135 136 137
                                height:                 width
                                radius:                 width / 2
                                color:                  modelData.setupComplete ? "#00d932" : "red"
                                visible:                modelData.requiresSetup
                            }
138 139 140 141

                            onClicked : {
                                setupView.showVehicleComponentPanel(modelData)
                            }
142 143 144 145 146 147 148 149 150 151
                        }

                        // Summary Qml
                        Rectangle {
                            anchors.top:    titleBar.bottom
                            width:          parent.width
                            Loader {
                                anchors.fill:   parent
                                source:         modelData.summaryQmlSource
                            }
152 153 154 155 156 157 158
                        }
                    }
                }
            }
        }
    }
}