SimpleItemEditor.qml 14.9 KB
Newer Older
1 2 3 4
import QtQuick                      2.11
import QtQuick.Controls             2.4
import QtQuick.Controls.Styles      1.4
import QtQuick.Layouts              1.11
5

6
import QGroundControl               1.0
7 8 9 10 11 12 13 14
import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0

// Editor for Simple mission items
Rectangle {
15
    width:  availableWidth
16
    height: editorColumn.height + (_margin * 2)
17 18 19
    color:  qgcPal.windowShadeDark
    radius: _radius

20 21
    property bool _specifiesAltitude:       missionItem.specifiesAltitude
    property real _margin:                  ScreenTools.defaultFontPixelHeight / 2
22 23
    property bool _supportsTerrainFrame:    missionItem.masterController.supportsTerrain
    property var  _controllerVehicle:       missionItem.masterController.controllerVehicle
24 25
    property int  _globalAltMode:           missionItem.masterController.missionController.globalAltitudeMode
    property bool _globalAltModeIsMixed:    _globalAltMode == QGroundControl.AltitudeModeNone
26

27
    property string _altModeRelativeHelpText:       qsTr("Altitude relative to launch altitude")
28 29
    property string _altModeAbsoluteHelpText:       qsTr("Altitude above mean sea level")
    property string _altModeAboveTerrainHelpText:   qsTr("Altitude above terrain\nActual AMSL altitude: %1 %2").arg(missionItem.amslAltAboveTerrain.valueString).arg(missionItem.amslAltAboveTerrain.units)
30 31 32
    property string _altModeTerrainFrameHelpText:   qsTr("Using terrain reference frame")

    function updateAltitudeModeText() {
33
        if (missionItem.altitudeMode === QGroundControl.AltitudeModeRelative) {
34
            altModeLabel.text = QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeRelative)
35
            altModeHelp.text = _altModeRelativeHelpText
36
        } else if (missionItem.altitudeMode === QGroundControl.AltitudeModeAbsolute) {
37
            altModeLabel.text = QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAbsolute)
38
            altModeHelp.text = _altModeAbsoluteHelpText
39
        } else if (missionItem.altitudeMode === QGroundControl.AltitudeModeAboveTerrain) {
40
            altModeLabel.text = QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAboveTerrain)
41
            altModeHelp.text = Qt.binding(function() { return _altModeAboveTerrainHelpText })
42
        } else if (missionItem.altitudeMode === QGroundControl.AltitudeModeTerrainFrame) {
43
            altModeLabel.text = QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeTerrainFrame)
44 45 46 47
            altModeHelp.text = _altModeTerrainFrameHelpText
        } else {
            altModeLabel.text = qsTr("Internal Error")
            altModeHelp.text = ""
DonLakeFlyer's avatar
DonLakeFlyer committed
48
        }
49
    }
50

51 52 53 54 55 56 57
    Component.onCompleted: updateAltitudeModeText()

    Connections {
        target:                 missionItem
        onAltitudeModeChanged:  updateAltitudeModeText()
    }

58
    Column {
59
        id:                 editorColumn
60 61 62 63
        anchors.margins:    _margin
        anchors.left:       parent.left
        anchors.right:      parent.right
        anchors.top:        parent.top
64 65 66 67 68 69 70 71 72 73
        spacing:            _margin

        QGCLabel {
            width:          parent.width
            wrapMode:       Text.WordWrap
            font.pointSize: ScreenTools.smallFontPointSize
            text:           missionItem.rawEdit ?
                                qsTr("Provides advanced access to all commands/parameters. Be very careful!") :
                                missionItem.commandDescription
        }
74

75 76 77 78
        ColumnLayout {
            anchors.left:       parent.left
            anchors.right:      parent.right
            spacing:            _margin
79
            visible:            missionItem.isTakeoffItem && missionItem.wizardMode // Hack special case for takeoff item
80

81
            QGCLabel {
82
                text:               qsTr("Move '%1' Takeoff to the %2 location.").arg(_controllerVehicle.vtol ? qsTr("V") : qsTr("T")).arg(_controllerVehicle.vtol ? qsTr("desired") : qsTr("climbout"))
83 84
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
85
                visible:            !initialClickLabel.visible
86 87
            }

88
            QGCLabel {
89
                text:               qsTr("Ensure clear of obstacles and into the wind.")
90 91
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
92
                visible:            !initialClickLabel.visible
93
            }
94

95
            QGCButton {
DoinLakeFlyer's avatar
DoinLakeFlyer committed
96
                text:               qsTr("Done")
97
                Layout.fillWidth:   true
98
                visible:            !initialClickLabel.visible
99 100
                onClicked: {
                    missionItem.wizardMode = false
DoinLakeFlyer's avatar
DoinLakeFlyer committed
101 102
                    // Trial of no auto select next item
                    //editorRoot.selectNextNotReadyItem()
103 104
                }
            }
105 106 107 108 109 110 111 112 113 114

            QGCLabel {
                id:                 initialClickLabel
                text:               missionItem.launchTakeoffAtSameLocation ?
                                        qsTr("Click in map to set planned Takeoff location.") :
                                        qsTr("Click in map to set planned Launch location.")
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
                visible:            missionItem.isTakeoffItem && !missionItem.launchCoordinate.isValid
            }
115 116
        }

117 118 119 120 121 122 123 124 125 126
        Column {
            anchors.left:       parent.left
            anchors.right:      parent.right
            spacing:            _margin
            visible:            !missionItem.wizardMode

            GridLayout {
                anchors.left:   parent.left
                anchors.right:  parent.right
                columns:        2
127

128 129
                Repeater {
                    model: missionItem.comboboxFacts
130

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
                    QGCLabel {
                        text:           object.name
                        visible:        object.name !== ""
                        Layout.column:  0
                        Layout.row:     index
                    }
                }

                Repeater {
                    model: missionItem.comboboxFacts

                    FactComboBox {
                        indexModel:         false
                        model:              object.enumStrings
                        fact:               object
                        font.pointSize:     ScreenTools.smallFontPointSize
                        Layout.column:      1
                        Layout.row:         index
                        Layout.fillWidth:   true
                    }
                }
            }
153

154
            // This control needs to morph between a simple altitude entry field to a more complex alt mode picker based on the global plan alt mode
155 156 157 158
            Rectangle {
                anchors.left:   parent.left
                anchors.right:  parent.right
                height:         altColumn.y + altColumn.height + _margin
159
                color:          _globalAltModeIsMixed ? qgcPal.windowShade: qgcPal.window
160 161
                visible:        _specifiesAltitude

162
                ColumnLayout {
163
                    id:                 altColumn
164
                    anchors.margins:    _globalAltModeIsMixed ? _margin : 0
165 166 167
                    anchors.top:        parent.top
                    anchors.left:       parent.left
                    anchors.right:      parent.right
168
                    spacing:            _globalAltModeIsMixed ? _margin : 0
169

170
                    QGCLabel {
171 172 173 174 175
                        Layout.fillWidth:   true
                        wrapMode:           Text.WordWrap
                        font.pointSize:     ScreenTools.smallFontPointSize
                        text:               qsTr("Altitude below specifies the approximate altitude of the ground. Normally 0 for landing back at original launch location.")
                        visible:            missionItem.isLandCommand
176 177
                    }

178
                    Item {
179 180 181
                        width:      altModeDropArrow.x + altModeDropArrow.width
                        height:     altModeLabel.height
                        visible:    _globalAltModeIsMixed
182 183 184 185

                        QGCLabel { id: altModeLabel }

                        QGCColoredImage {
186
                            id:                     altModeDropArrow
187 188 189 190 191 192 193 194
                            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 4
                            anchors.left:           altModeLabel.right
                            anchors.verticalCenter: altModeLabel.verticalCenter
                            width:                  ScreenTools.defaultFontPixelHeight / 2
                            height:                 width
                            sourceSize.height:      height
                            source:                 "/res/DropArrow.svg"
                            color:                  qgcPal.text
195 196
                        }

197 198
                        QGCMouseArea {
                            anchors.fill:   parent
199
                            onClicked:      altModeMenu.popup()
200 201
                        }

202
                        QGCMenu {
203
                            id: altModeMenu
204 205

                            QGCMenuItem {
206
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeRelative)
207 208 209 210 211 212
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeRelative
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeRelative
                            }

                            QGCMenuItem {
213
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAbsolute)
214 215 216 217 218 219 220
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeAbsolute
                                visible:        QGroundControl.corePlugin.options.showMissionAbsoluteAltitude
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeAbsolute
                            }

                            QGCMenuItem {
221
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAboveTerrain)
222 223 224 225 226 227 228
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeAboveTerrain
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeAboveTerrain
                                visible:        missionItem.specifiesCoordinate
                            }

                            QGCMenuItem {
229
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeTerrainFrame)
230 231
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeTerrainFrame
232
                                visible:        _supportsTerrainFrame && (missionItem.specifiesCoordinate || missionItem.specifiesAltitudeOnly)
233 234
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeTerrainFrame
                            }
235
                        }
DonLakeFlyer's avatar
DonLakeFlyer committed
236
                    }
237

238 239 240 241 242 243
                    QGCLabel {
                        text:           qsTr("Altitude")
                        font.pointSize: ScreenTools.smallFontPointSize
                        visible:        !_globalAltModeIsMixed
                    }

244 245
                    AltitudeFactTextField {
                        id:                 altField
246
                        Layout.fillWidth:   true
247 248 249
                        fact:               missionItem.altitude
                        altitudeMode:       missionItem.altitudeMode
                    }
250

251 252
                    QGCLabel {
                        id:                 altModeHelp
253
                        Layout.fillWidth:   true
254 255
                        wrapMode:           Text.WordWrap
                        font.pointSize:     ScreenTools.smallFontPointSize
256
                        visible:            _globalAltModeIsMixed
257
                    }
258
                }
259 260
            }

261 262 263 264 265 266 267 268
            GridLayout {
                anchors.left:   parent.left
                anchors.right:  parent.right
                flow:           GridLayout.TopToBottom
                rows:           missionItem.textFieldFacts.count +
                                missionItem.nanFacts.count +
                                (missionItem.speedSection.available ? 1 : 0)
                columns:        2
269

270 271
                Repeater {
                    model: missionItem.textFieldFacts
272

273 274
                    QGCLabel { text: object.name }
                }
275

276 277
                Repeater {
                    model: missionItem.nanFacts
278

279 280 281 282 283
                    QGCCheckBox {
                        text:           object.name
                        checked:        !isNaN(object.rawValue)
                        onClicked:      object.rawValue = checked ? 0 : NaN
                    }
284 285
                }

286 287 288 289 290 291 292
                QGCCheckBox {
                    id:         flightSpeedCheckbox
                    text:       qsTr("Flight Speed")
                    checked:    missionItem.speedSection.specifyFlightSpeed
                    onClicked:  missionItem.speedSection.specifyFlightSpeed = checked
                    visible:    missionItem.speedSection.available
                }
293

294

295 296
                Repeater {
                    model: missionItem.textFieldFacts
297

298 299 300 301 302 303
                    FactTextField {
                        showUnits:          true
                        fact:               object
                        Layout.fillWidth:   true
                        enabled:            !object.readOnly
                    }
304 305
                }

306 307 308 309 310 311 312 313 314 315
                Repeater {
                    model: missionItem.nanFacts

                    FactTextField {
                        showUnits:          true
                        fact:               object
                        Layout.fillWidth:   true
                        enabled:            !isNaN(object.rawValue)
                    }
                }
316 317

                FactTextField {
318
                    fact:               missionItem.speedSection.flightSpeed
319
                    Layout.fillWidth:   true
320 321
                    enabled:            flightSpeedCheckbox.checked
                    visible:            missionItem.speedSection.available
322 323 324
                }
            }

325 326 327
            CameraSection {
                checked:    missionItem.cameraSection.settingsSpecified
                visible:    missionItem.cameraSection.available
328 329
            }
        }
330 331
    }
}