APMAirframeComponent.qml 5.47 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


Don Gagne's avatar
Don Gagne committed
11
import QtQuick          2.5
12
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:  _useOldFrameParam ?  oldFramePageComponent: newFramePageComponent
26

27 28 29 30 31
    property real _margins:             ScreenTools.defaultFontPixelWidth
    property bool _useOldFrameParam:    controller.parameterExists(-1, "FRAME")
    property Fact _oldFrameParam:       controller.getParameterFact(-1, "FRAME", false)
    property Fact _newFrameParam:       controller.getParameterFact(-1, "FRAME_CLASS", false)
    property Fact _frameTypeParam:      controller.getParameterFact(-1, "FRAME_TYPE", false)
32 33 34

    APMAirframeComponentController {
        id:         controller
35
        factPanel:  airframePage.viewPanel
36 37
    }

Don Gagne's avatar
Don Gagne committed
38 39 40 41
    ExclusiveGroup {
        id: airframeTypeExclusive
    }

42 43 44 45 46 47 48 49 50 51 52 53 54 55
    Component {
        id: applyRestartDialogComponent

        QGCViewDialog {
            id: applyRestartDialog

            Connections {
                target: controller
                onCurrentAirframeTypeChanged: {
                    airframePicker.model = controller.currentAirframeType.airframes;
                }
            }

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
56 57 58 59 60 61
                id:                 applyParamsText
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.margins:    _margins
                wrapMode:           Text.WordWrap
Don Gagne's avatar
Don Gagne committed
62
                text:               qsTr("Select your drone to load the default parameters for it. ")
63 64 65
            }

            Flow {
Don Gagne's avatar
Don Gagne committed
66 67 68 69 70 71 72 73
                anchors.margins:    _margins
                anchors.top:        applyParamsText.bottom
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.bottom:     parent.bottom
                spacing :           _margins
                layoutDirection:    Qt.Vertical;

74
                Repeater {
Don Gagne's avatar
Don Gagne committed
75 76
                    id:     airframePicker
                    model:  controller.currentAirframeType.airframes;
77 78

                    delegate: QGCButton {
Don Gagne's avatar
Don Gagne committed
79
                        id:     btnParams
80 81
                        width:  parent.width / 2.1
                        height: (ScreenTools.defaultFontPixelHeight * 14) / 5
Don Gagne's avatar
Don Gagne committed
82
                        text:   controller.currentAirframeType.airframes[index].name;
83

Don Gagne's avatar
Don Gagne committed
84 85 86 87
                        onClicked : {
                            controller.loadParameters(controller.currentAirframeType.airframes[index].params)
                            hideDialog()
                        }
88 89 90 91 92 93
                    }
                }
            }
        }
    }

94
    Component {
95
        id: oldFramePageComponent
96

97 98 99 100
        Column {
            width:      availableWidth
            height:     1000
            spacing:    _margins
101

102 103
            RowLayout {
                anchors.left:   parent.left
104
                anchors.right:  parent.right
105
                spacing:        _margins
106

107 108 109 110 111 112
                QGCLabel {
                    font.pointSize:     ScreenTools.mediumFontPointSize
                    wrapMode:           Text.WordWrap
                    text:               qsTr("Please select your airframe type")
                    Layout.fillWidth:   true
                }
Don Gagne's avatar
Don Gagne committed
113

114 115 116 117 118
                QGCButton {
                    text:       qsTr("Load common parameters")
                    onClicked:  showDialog(applyRestartDialogComponent, qsTr("Load common parameters"), qgcView.showDialogDefaultWidth, StandardButton.Close)
                }
            }
119

120 121
            Repeater {
                model: controller.airframeTypesModel
122

123 124 125 126
                QGCRadioButton {
                    text: object.name
                    checked: controller.currentAirframeType == object
                    exclusiveGroup: airframeTypeExclusive
127

128 129 130
                    onCheckedChanged: {
                        if (checked) {
                            controller.currentAirframeType = object
131 132 133 134
                        }
                    }
                }
            }
135
        } // Column
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    } // Component - oldFramePageComponent

    Component {
        id: newFramePageComponent

        Grid {
            anchors.left:   parent.left
            anchors.right:  parent.right
            spacing:        _margins
            columns:        2

            QGCLabel {
                text:               qsTr("Frame Class:")
            }

            FactComboBox {
                fact:       _newFrameParam
                indexModel: false
                width:      ScreenTools.defaultFontPixelWidth * 15
            }

            QGCLabel {
                text:               qsTr("Frame Type:")
            }

            FactComboBox {
                fact:       _frameTypeParam
                indexModel: false
                width:      ScreenTools.defaultFontPixelWidth * 15
            }
        }
    }
168
} // SetupPage