APMAirframeComponent.qml 9.94 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
Don Gagne's avatar
Don Gagne committed
13
import QtQuick.Dialogs  1.2
14
import QtQuick.Layouts  1.2
15

Don Gagne's avatar
Don Gagne committed
16
import QGroundControl.FactSystem    1.0
17
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
18 19 20 21
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0
22

23 24
SetupPage {
    id:             airframePage
25
    pageComponent:  pageComponent
Don Gagne's avatar
Don Gagne committed
26

27
    Component {
28 29 30 31 32 33
        id: pageComponent

        ColumnLayout {
            id:     mainColumn
            width:  availableWidth

34 35 36 37 38 39 40
            property real _minW:                ScreenTools.defaultFontPixelWidth * 20
            property real _boxWidth:            _minW
            property real _boxSpace:            ScreenTools.defaultFontPixelWidth
            property real _margins:             ScreenTools.defaultFontPixelWidth
            property Fact _frameClass:          controller.getParameterFact(-1, "FRAME_CLASS")
            property Fact _frameType:           controller.getParameterFact(-1, "FRAME_TYPE", false)    // FRAME_TYPE is not available on all Rover versions
            property bool _frameTypeAvailable:  controller.parameterExists(-1, "FRAME_TYPE")
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

            readonly property real spacerHeight: ScreenTools.defaultFontPixelHeight

            onWidthChanged:         computeDimensions()
            Component.onCompleted:  computeDimensions()

            function computeDimensions() {
                var sw  = 0
                var rw  = 0
                var idx = Math.floor(mainColumn.width / (_minW + ScreenTools.defaultFontPixelWidth))
                if(idx < 1) {
                    _boxWidth = mainColumn.width
                    _boxSpace = 0
                } else {
                    _boxSpace = 0
                    if(idx > 1) {
                        _boxSpace = ScreenTools.defaultFontPixelWidth
                        sw = _boxSpace * (idx - 1)
                    }
                    rw = mainColumn.width - sw
                    _boxWidth = rw / idx
62 63
                }
            }
64

65
            APMAirframeComponentController { id: controller; }
66

67 68 69 70 71
            QGCLabel {
                id:                 helpText
                Layout.fillWidth:   true
                text:               (_frameClass.rawValue === 0 ?
                                         qsTr("Airframe is currently not set.") :
72 73 74
                                         qsTr("Currently set to frame class '%1'").arg(_frameClass.enumStringValue) +
                                         (_frameTypeAvailable ?  qsTr(" and frame type '%2'").arg(_frameType.enumStringValue) : "") +
                                         qsTr(".", "period for end of sentence")) +
75 76 77 78
                                    qsTr(" To change this configuration, select the desired frame class below and frame type.")
                font.family:        ScreenTools.demiboldFontFamily
                wrapMode:           Text.WordWrap
            }
79

80 81 82 83
            Item {
                id:             lastSpacer
                height:         parent.spacerHeight
                width:          10
84
            }
85

86 87 88 89
            Flow {
                id:                 flowView
                Layout.fillWidth:   true
                spacing:            _boxSpace
90

91 92 93
                ExclusiveGroup {
                    id: airframeTypeExclusive
                }
94

95 96
                Repeater {
                    model: controller.frameClassModel
97

98 99 100 101 102 103
                    // Outer summary item rectangle
                    Rectangle {
                        id:     outerRect
                        width:  _boxWidth
                        height: ScreenTools.defaultFontPixelHeight * 14
                        color:  qgcPal.window
104

105 106
                        readonly property real titleHeight: ScreenTools.defaultFontPixelHeight * 1.75
                        readonly property real innerMargin: ScreenTools.defaultFontPixelWidth
107

108
                        MouseArea {
109 110 111 112 113 114 115 116 117
                            anchors.fill: parent
                            onClicked: {
                                if (!airframeCheckBox.checked || !combo.valid) {
                                    if (_frameTypeAvailable && object.defaultFrameType != -1) {
                                        _frameType.rawValue = object.defaultFrameType
                                    }
                                    airframeCheckBox.checked = true
                                }
                            }
118 119 120 121 122 123 124 125
                        }

                        QGCLabel {
                            id:     title
                            text:   object.name
                        }

                        Rectangle {
126
                            id:                 imageComboRect
127 128 129 130 131 132
                            anchors.topMargin:  ScreenTools.defaultFontPixelHeight / 2
                            anchors.top:        title.bottom
                            anchors.bottom:     parent.bottom
                            anchors.left:       parent.left
                            anchors.right:      parent.right
                            color:              airframeCheckBox.checked ? qgcPal.buttonHighlight : qgcPal.windowShade
133
                            opacity:            combo.valid ? 1.0 : 0.5
134 135 136 137 138 139 140 141 142 143 144 145

                            ColumnLayout {
                                anchors.margins:    innerMargin
                                anchors.fill:       parent
                                spacing:            innerMargin

                                Image {
                                    id:                 image
                                    Layout.fillWidth:   true
                                    Layout.fillHeight:  true
                                    fillMode:           Image.PreserveAspectFit
                                    smooth:             true
Gus Grubba's avatar
Gus Grubba committed
146 147
                                    antialiasing:       true
                                    sourceSize.width:   width
148
                                    source:             airframeCheckBox.checked ? object.imageResource : object.imageResourceDefault
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
                                }

                                QGCCheckBox {
                                    // Although this item is invisible we still use it to manage state
                                    id:             airframeCheckBox
                                    checked:        object.frameClass === _frameClass.rawValue
                                    exclusiveGroup: airframeTypeExclusive
                                    visible:        false

                                    onCheckedChanged: {
                                        if (checked) {
                                            _frameClass.rawValue = object.frameClass
                                        }
                                    }
                                }

                                QGCLabel {
                                    text:           qsTr("Frame Type")
                                    font.pointSize: ScreenTools.smallFontPointSize
                                    color:          qgcPal.buttonHighlightText
                                    visible:        airframeCheckBox.checked && object.frameTypeSupported
                                }

172
                                QGCComboBox {
173 174
                                    id:                 combo
                                    Layout.fillWidth:   true
175
                                    model:              object.frameTypeEnumStrings
176
                                    visible:            airframeCheckBox.checked && object.frameTypeSupported
177 178 179 180
                                    onActivated:        _frameType.rawValue = object.frameTypeEnumValues[index]

                                    property bool valid: true

181 182 183 184 185 186
                                    function checkFrameType(value) {
                                        return value == _frameType.rawValue
                                    }

                                    function selectFrameType() {
                                        var index = object.frameTypeEnumValues.findIndex(checkFrameType)
187 188 189 190 191 192 193 194 195
                                        if (index == -1 && combo.visible) {
                                            // Frame Class/Type is set to an invalid combination
                                            combo.valid = false
                                        } else {
                                            combo.currentIndex = index
                                            combo.valid = true
                                        }
                                    }

196
                                    Component.onCompleted: selectFrameType()
197 198 199 200

                                    Connections {
                                        target:                 _frameTypeAvailable ? _frameType : null
                                        ignoreUnknownSignals:   true
201
                                        onRawValueChanged:      combo.selectFrameType()
202
                                    }
203 204 205
                                }
                            }
                        }
206 207 208 209 210 211 212

                        QGCLabel {
                            anchors.fill:   imageComboRect
                            text:           qsTr("Invalid setting for FRAME_TYPE. Click to Reset.")
                            wrapMode:       Text.WordWrap
                            visible:        !combo.valid
                        }
213 214 215 216 217
                    }
                } // Repeater - summary boxes
            } // Flow - summary boxes
        } // Column
    } // Component
218
} // SetupPage