SimpleItemEditor.qml 11 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
4
import QtQuick.Dialogs          1.2
5
import QtQuick.Layouts          1.2
6

7
import QGroundControl               1.0
8 9 10 11 12 13 14 15
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 {
16
    width:  availableWidth
Don Gagne's avatar
Don Gagne committed
17
    height: valuesColumn.height + (_margin * 2)
18 19 20
    color:  qgcPal.windowShadeDark
    radius: _radius

21 22 23 24
    readonly property int _altModeRelative:     0
    readonly property int _altModeAbsolute:     1
    readonly property int _altModeAboveTerrain: 2
    readonly property int _altModeTerrainFrame: 3
25

26 27 28 29
    property bool _specifiesAltitude:       missionItem.specifiesAltitude
    property real _margin:                  ScreenTools.defaultFontPixelHeight / 2
    property bool _supportsTerrainFrame:    missionItem

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

Don Gagne's avatar
Don Gagne committed
35 36 37 38 39
    readonly property string _altModeRelativeExtraUnits:        qsTr(" (Rel)")
    readonly property string _altModeAbsoluteExtraUnits:        qsTr(" (AMSL)")
    readonly property string _altModeAboveTerrainExtraUnits:    qsTr(" (Abv Terr)")
    readonly property string _altModeTerrainFrameExtraUnits:    qsTr(" (TerrF)")

40 41 42 43
    function updateAltitudeModeText() {
        if (missionItem.altitudeMode === _altModeRelative) {
            altModeLabel.text = qsTr("Altitude")
            altModeHelp.text = _altModeRelativeHelpText
Don Gagne's avatar
Don Gagne committed
44
            altField.extraUnits = _altModeRelativeExtraUnits
45 46 47
        } else if (missionItem.altitudeMode === _altModeAbsolute) {
            altModeLabel.text = qsTr("Above Mean Sea Level")
            altModeHelp.text = _altModeAbsoluteHelpText
Don Gagne's avatar
Don Gagne committed
48
            altField.extraUnits = _altModeAbsoluteExtraUnits
49 50 51
        } else if (missionItem.altitudeMode === _altModeAboveTerrain) {
            altModeLabel.text = qsTr("Above Terrain")
            altModeHelp.text = Qt.binding(function() { return _altModeAboveTerrainHelpText })
Don Gagne's avatar
Don Gagne committed
52
            altField.extraUnits = _altModeAboveTerrainExtraUnits
53 54 55
        } else if (missionItem.altitudeMode === _altModeTerrainFrame) {
            altModeLabel.text = qsTr("Terrain Frame")
            altModeHelp.text = _altModeTerrainFrameHelpText
Don Gagne's avatar
Don Gagne committed
56
            altField.extraUnits = _altModeTerrainFrameExtraUnits
57 58 59
        } else {
            altModeLabel.text = qsTr("Internal Error")
            altModeHelp.text = ""
Don Gagne's avatar
Don Gagne committed
60
            altField.extraUnits = ""
DonLakeFlyer's avatar
DonLakeFlyer committed
61
        }
62
    }
63

64 65 66 67 68 69 70
    Component.onCompleted: updateAltitudeModeText()

    Connections {
        target:                 missionItem
        onAltitudeModeChanged:  updateAltitudeModeText()
    }

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    Column {
        id:                 valuesColumn
        anchors.margins:    _margin
        anchors.left:       parent.left
        anchors.right:      parent.right
        anchors.top:        parent.top
        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
        }

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

            Repeater {
                model: missionItem.comboboxFacts

                QGCLabel {
                    text:           object.name
98
                    visible:        object.name !== ""
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                    Layout.column:  0
                    Layout.row:     index
                }
            }

            Repeater {
                model: missionItem.comboboxFacts

                FactComboBox {
                    indexModel:         false
                    model:              object.enumStrings
                    fact:               object
                    Layout.column:      1
                    Layout.row:         index
                    Layout.fillWidth:   true
                }
            }
        }

118
        Rectangle {
DonLakeFlyer's avatar
DonLakeFlyer committed
119 120 121 122 123
            anchors.left:   parent.left
            anchors.right:  parent.right
            height:         altColumn.y + altColumn.height + _margin
            color:          qgcPal.windowShade
            visible:        _specifiesAltitude
124 125 126 127 128 129 130 131 132

            Column {
                id:                 altColumn
                anchors.margins:    _margin
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.right:      parent.right
                spacing:            _margin

133 134 135 136 137 138 139 140 141 142
                Item {
                    width:  altHamburger.x + altHamburger.width
                    height: altModeLabel.height

                    QGCLabel { id: altModeLabel }

                    QGCColoredImage {
                        id:                     altHamburger
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 4
                        anchors.left:           altModeLabel.right
Don Gagne's avatar
Don Gagne committed
143 144 145
                        anchors.verticalCenter: altModeLabel.verticalCenter
                        width:                  ScreenTools.defaultFontPixelHeight / 2
                        height:                 width
146
                        sourceSize.height:      height
Don Gagne's avatar
Don Gagne committed
147
                        source:                 "/res/DropArrow.svg"
148
                        color:                  qgcPal.text
149
                    }
DonLakeFlyer's avatar
DonLakeFlyer committed
150

151 152 153
                    QGCMouseArea {
                        anchors.fill:   parent
                        onClicked:      altHamburgerMenu.popup()
154
                    }
155 156 157 158 159 160

                    Menu {
                        id: altHamburgerMenu

                        MenuItem {
                            text:           qsTr("Altitude Relative To Home")
161 162
                            checkable:      true
                            checked:        missionItem.altitudeMode === _altModeRelative
163 164 165 166
                            onTriggered:    missionItem.altitudeMode = _altModeRelative
                        }

                        MenuItem {
167 168 169 170
                            text:           qsTr("Altitude Above Mean Sea Level")
                            checkable:      true
                            checked:        missionItem.altitudeMode === _altModeAbsolute
                            visible:        QGroundControl.corePlugin.options.showMissionAbsoluteAltitude
171 172 173 174
                            onTriggered:    missionItem.altitudeMode = _altModeAbsolute
                        }

                        MenuItem {
175 176 177
                            text:           qsTr("Altitude Above Terrain")
                            checkable:      true
                            checked:        missionItem.altitudeMode === _altModeAboveTerrain
178
                            onTriggered:    missionItem.altitudeMode = _altModeAboveTerrain
Don Gagne's avatar
Don Gagne committed
179
                            visible:        missionItem.specifiesCoordinate
180 181 182 183
                        }

                        MenuItem {
                            text:           qsTr("Terrain Frame")
184 185 186
                            checkable:      true
                            checked:        missionItem.altitudeMode === _altModeTerrainFrame
                            visible:        missionItem.altitudeMode === _altModeTerrainFrame
187 188
                            onTriggered:    missionItem.altitudeMode = _altModeTerrainFrame
                        }
DonLakeFlyer's avatar
DonLakeFlyer committed
189
                    }
190 191
                }

192
                FactTextField {
Don Gagne's avatar
Don Gagne committed
193 194 195 196 197 198 199
                    id:                 altField
                    fact:               missionItem.altitude
                    unitsLabel:         fact.units + extraUnits
                    anchors.left:       parent.left
                    anchors.right:      parent.right

                    property string extraUnits
200 201
                }

202
                QGCLabel {
Don Gagne's avatar
Don Gagne committed
203 204 205 206 207
                    id:                 altModeHelp
                    wrapMode:           Text.WordWrap
                    font.pointSize:     ScreenTools.smallFontPointSize
                    anchors.left:       parent.left
                    anchors.right:      parent.right
208
                }
209 210 211
            }
        }

212 213 214 215
        GridLayout {
            anchors.left:   parent.left
            anchors.right:  parent.right
            flow:           GridLayout.TopToBottom
216 217
            rows:           missionItem.textFieldFacts.count +
                            missionItem.nanFacts.count +
218
                            (missionItem.speedSection.available ? 1 : 0)
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
            columns:        2

            Repeater {
                model: missionItem.textFieldFacts

                QGCLabel { text: object.name }
            }

            Repeater {
                model: missionItem.nanFacts

                QGCCheckBox {
                    text:           object.name
                    checked:        !isNaN(object.rawValue)
                    onClicked:      object.rawValue = checked ? 0 : NaN
                }
            }

            QGCCheckBox {
                id:         flightSpeedCheckbox
                text:       qsTr("Flight Speed")
                checked:    missionItem.speedSection.specifyFlightSpeed
                onClicked:  missionItem.speedSection.specifyFlightSpeed = checked
                visible:    missionItem.speedSection.available
            }

245

246 247 248 249 250 251 252
            Repeater {
                model: missionItem.textFieldFacts

                FactTextField {
                    showUnits:          true
                    fact:               object
                    Layout.fillWidth:   true
253
                    enabled:            !object.readOnly
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
                }
            }

            Repeater {
                model: missionItem.nanFacts

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

            FactTextField {
                fact:               missionItem.speedSection.flightSpeed
                Layout.fillWidth:   true
                enabled:            flightSpeedCheckbox.checked
                visible:            missionItem.speedSection.available
            }
        }

        CameraSection {
            checked:    missionItem.cameraSection.settingsSpecified
            visible:    missionItem.cameraSection.available
        }
    } // Column
281
} // Rectangle