VehicleSummary.qml 6.36 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
import QtQuick                  2.3
import QtQuick.Controls         1.2
13
import QtQuick.Controls.Styles  1.4
14

15
import QGroundControl                       1.0
16 17 18 19
import QGroundControl.FactSystem            1.0
import QGroundControl.Controls              1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
20
import QGroundControl.Palette               1.0
21 22

Rectangle {
dogmaphobic's avatar
dogmaphobic committed
23 24
    id:             _summaryRoot
    anchors.fill:   parent
25 26
    anchors.rightMargin: ScreenTools.defaultFontPixelWidth
    anchors.leftMargin:  ScreenTools.defaultFontPixelWidth
dogmaphobic's avatar
dogmaphobic committed
27 28
    color:          qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
29
    property real _minSummaryW:     ScreenTools.isTinyScreen ? ScreenTools.defaultFontPixelWidth * 28 : ScreenTools.defaultFontPixelWidth * 36
30
    property real _summaryBoxWidth: _minSummaryW
31
    property real _summaryBoxSpace: ScreenTools.defaultFontPixelWidth * 2
32 33 34 35 36 37 38 39 40 41 42

    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) {
43
                _summaryBoxSpace = ScreenTools.defaultFontPixelWidth * 2
44 45 46 47 48 49
                sw = _summaryBoxSpace * (idx - 1)
            }
            rw = _summaryRoot.width - sw
            _summaryBoxWidth = rw / idx
        }
    }
dogmaphobic's avatar
dogmaphobic committed
50 51 52 53

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

55 56 57 58 59 60 61 62 63 64 65 66
    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

    Component.onCompleted: {
        computeSummaryBoxSize()
    }

    onWidthChanged: {
        computeSummaryBoxSize()
    }
67

Don Gagne's avatar
Don Gagne committed
68
    QGCFlickable {
dogmaphobic's avatar
dogmaphobic committed
69 70
        clip:               true
        anchors.fill:       parent
71 72
        contentHeight:      summaryColumn.height
        contentWidth:       _summaryRoot.width
dogmaphobic's avatar
dogmaphobic committed
73
        flickableDirection: Flickable.VerticalFlick
74 75 76 77 78 79 80 81 82 83

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

            QGCLabel {
                width:			parent.width
                wrapMode:		Text.WordWrap
                color:			setupComplete ? qgcPal.text : qgcPal.warningText
84
                font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
85
                horizontalAlignment: Text.AlignHCenter
86
                text:           setupComplete ?
87 88
                    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.")
89

90
                property bool setupComplete: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.setupComplete : false
91
            }
92

93 94 95 96
            Flow {
                id:         _flowCtl
                width:      _summaryRoot.width
                spacing:    _summaryBoxSpace
Don Gagne's avatar
Don Gagne committed
97

98
                Repeater {
99
                    model: QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : undefined
100

101
                    // Outer summary item rectangle
Don Gagne's avatar
Don Gagne committed
102
                    Rectangle {
103
                        width:      _summaryBoxWidth
104
                        height:     ScreenTools.defaultFontPixelHeight * 13
105
                        color:      qgcPal.windowShade
dogmaphobic's avatar
dogmaphobic committed
106
                        visible:    modelData.summaryQmlSource.toString() !== ""
107 108 109 110 111
                        border.width: 1
                        border.color: qgcPal.text
                        Component.onCompleted: {
                            border.color = Qt.rgba(border.color.r, border.color.g, border.color.b, 0.1)
                        }
112

113
                        readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 2
114 115

                        // Title bar
116
                        QGCButton {
117 118 119
                            id:     titleBar
                            width:  parent.width
                            height: titleHeight
dogmaphobic's avatar
dogmaphobic committed
120
                            text:   capitalizeWords(modelData.name)
121 122 123

                            // Setup indicator
                            Rectangle {
124
                                anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
125 126
                                anchors.right:          parent.right
                                anchors.verticalCenter: parent.verticalCenter
127
                                width:                  ScreenTools.defaultFontPixelWidth * 1.75
128 129 130
                                height:                 width
                                radius:                 width / 2
                                color:                  modelData.setupComplete ? "#00d932" : "red"
131
                                visible:                modelData.requiresSetup && modelData.setupSource !== ""
132
                            }
133

134
                            onClicked : {
135
                                console.log(modelData.setupSource)
136
                                if (modelData.setupSource !== "") {
137 138
                                    setupView.showVehicleComponentPanel(modelData)
                                }
139
                            }
140 141 142 143 144 145
                        }
                        // Summary Qml
                        Rectangle {
                            anchors.top:    titleBar.bottom
                            width:          parent.width
                            Loader {
146 147 148
                                anchors.fill:       parent
                                anchors.margins:    ScreenTools.defaultFontPixelWidth
                                source:             modelData.summaryQmlSource
149
                            }
150 151 152 153 154 155 156
                        }
                    }
                }
            }
        }
    }
}