SimpleItemEditor.qml 15.2 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
    property var  _controllerVehicle:       missionItem.masterController.controllerVehicle
23
    property bool _supportsTerrainFrame:    _controllerVehicle.supportsTerrainFrame
24 25
    property int  _globalAltMode:           missionItem.masterController.missionController.globalAltitudeMode
    property bool _globalAltModeIsMixed:    _globalAltMode == QGroundControl.AltitudeModeNone
DonLakeFlyer's avatar
DonLakeFlyer committed
26
    property real _radius:                  ScreenTools.defaultFontPixelWidth / 2
27

28
    property string _altModeRelativeHelpText:       qsTr("Altitude relative to launch altitude")
29 30
    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)
31 32 33
    property string _altModeTerrainFrameHelpText:   qsTr("Using terrain reference frame")

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

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

    Connections {
        target:                 missionItem
        onAltitudeModeChanged:  updateAltitudeModeText()
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
59 60
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }

61
    Column {
62
        id:                 editorColumn
63 64 65 66
        anchors.margins:    _margin
        anchors.left:       parent.left
        anchors.right:      parent.right
        anchors.top:        parent.top
67 68 69 70 71 72 73 74 75 76
        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
        }
77

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

84
            QGCLabel {
85 86 87 88 89
                text:               qsTr("Move '%1' %2 to the %3 location. %4")
                                        .arg(_controllerVehicle.vtol ? qsTr("T") : qsTr("T"))
                                        .arg(_controllerVehicle.vtol ? qsTr("Transition Direction") : qsTr("Takeoff"))
                                        .arg(_controllerVehicle.vtol ? qsTr("desired") : qsTr("climbout"))
                                        .arg(_controllerVehicle.vtol ? (qsTr("Ensure distance from launch to transition direction is far enough to complete transition.")) : "")
90 91
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
92
                visible:            !initialClickLabel.visible
93 94
            }

95
            QGCLabel {
96
                text:               qsTr("Ensure clear of obstacles and into the wind.")
97 98
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
99
                visible:            !initialClickLabel.visible
100
            }
101

102
            QGCButton {
DoinLakeFlyer's avatar
DoinLakeFlyer committed
103
                text:               qsTr("Done")
104
                Layout.fillWidth:   true
105
                visible:            !initialClickLabel.visible
106 107
                onClicked: {
                    missionItem.wizardMode = false
108 109
                }
            }
110 111 112 113 114 115 116 117 118 119

            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
            }
120 121
        }

122 123 124 125 126 127
        Column {
            anchors.left:       parent.left
            anchors.right:      parent.right
            spacing:            _margin
            visible:            !missionItem.wizardMode

128
            // 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
129 130 131 132
            Rectangle {
                anchors.left:   parent.left
                anchors.right:  parent.right
                height:         altColumn.y + altColumn.height + _margin
133
                color:          _globalAltModeIsMixed ? qgcPal.windowShadeLight : qgcPal.windowShadeDark
134 135
                visible:        _specifiesAltitude

136
                ColumnLayout {
137
                    id:                 altColumn
138
                    anchors.margins:    _globalAltModeIsMixed ? _margin : 0
139 140 141
                    anchors.top:        parent.top
                    anchors.left:       parent.left
                    anchors.right:      parent.right
142
                    spacing:            _globalAltModeIsMixed ? _margin : 0
143

144
                    QGCLabel {
145 146 147 148 149
                        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
150 151
                    }

152
                    Item {
153 154 155
                        width:      altModeDropArrow.x + altModeDropArrow.width
                        height:     altModeLabel.height
                        visible:    _globalAltModeIsMixed
156 157 158 159

                        QGCLabel { id: altModeLabel }

                        QGCColoredImage {
160
                            id:                     altModeDropArrow
161 162 163 164 165 166 167 168
                            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
169 170
                        }

171 172
                        QGCMouseArea {
                            anchors.fill:   parent
173
                            onClicked:      altModeMenu.popup()
174 175
                        }

176
                        QGCMenu {
177
                            id: altModeMenu
178 179

                            QGCMenuItem {
180
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeRelative)
181 182 183 184 185 186
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeRelative
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeRelative
                            }

                            QGCMenuItem {
187
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAbsolute)
188 189 190 191 192 193 194
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeAbsolute
                                visible:        QGroundControl.corePlugin.options.showMissionAbsoluteAltitude
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeAbsolute
                            }

                            QGCMenuItem {
195
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeAboveTerrain)
196 197 198 199 200 201 202
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeAboveTerrain
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeAboveTerrain
                                visible:        missionItem.specifiesCoordinate
                            }

                            QGCMenuItem {
203
                                text:           QGroundControl.altitudeModeShortDescription(QGroundControl.AltitudeModeTerrainFrame)
204 205
                                checkable:      true
                                checked:        missionItem.altitudeMode === QGroundControl.AltitudeModeTerrainFrame
206
                                visible:        _supportsTerrainFrame && (missionItem.specifiesCoordinate || missionItem.specifiesAltitudeOnly)
207 208
                                onTriggered:    missionItem.altitudeMode = QGroundControl.AltitudeModeTerrainFrame
                            }
209
                        }
DonLakeFlyer's avatar
DonLakeFlyer committed
210
                    }
211

212 213 214 215 216 217
                    QGCLabel {
                        text:           qsTr("Altitude")
                        font.pointSize: ScreenTools.smallFontPointSize
                        visible:        !_globalAltModeIsMixed
                    }

218 219
                    AltitudeFactTextField {
                        id:                 altField
220
                        Layout.fillWidth:   true
221 222 223
                        fact:               missionItem.altitude
                        altitudeMode:       missionItem.altitudeMode
                    }
224

225 226
                    QGCLabel {
                        id:                 altModeHelp
227
                        Layout.fillWidth:   true
228 229
                        wrapMode:           Text.WordWrap
                        font.pointSize:     ScreenTools.smallFontPointSize
230
                        visible:            _globalAltModeIsMixed
231
                    }
232
                }
233 234
            }

DonLakeFlyer's avatar
DonLakeFlyer committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
            ColumnLayout {
                anchors.left:   parent.left
                anchors.right:  parent.right
                spacing:        _margin

                Repeater {
                    model: missionItem.comboboxFacts

                    ColumnLayout {
                        Layout.fillWidth:   true
                        spacing:            0

                        QGCLabel {
                            font.pointSize: ScreenTools.smallFontPointSize
                            text:           object.name
                            visible:        object.name !== ""
                        }

                        FactComboBox {
                            Layout.fillWidth:   true
                            indexModel:         false
                            model:              object.enumStrings
                            fact:               object
                        }
                    }
                }
            }

263 264 265 266 267 268 269 270
            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
271

272 273
                Repeater {
                    model: missionItem.textFieldFacts
274

275 276
                    QGCLabel { text: object.name }
                }
277

278 279
                Repeater {
                    model: missionItem.nanFacts
280

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

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

296

297 298
                Repeater {
                    model: missionItem.textFieldFacts
299

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

308 309 310 311 312 313 314 315 316 317
                Repeater {
                    model: missionItem.nanFacts

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

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

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