MissionItemEditor.qml 11.9 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
Don Gagne's avatar
Don Gagne committed
4
import QtQuick.Dialogs          1.2
Don Gagne's avatar
Don Gagne committed
5 6 7

import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
Don Gagne's avatar
Don Gagne committed
8 9
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
10 11
import QGroundControl.Palette       1.0

Don Gagne's avatar
Don Gagne committed
12 13 14

/// Mission item edit control
Rectangle {
15 16
    id: _root

17 18 19 20
    height: editorLoader.y + editorLoader.height + (_margin * 2)
    color:  missionItem.isCurrentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
    radius: _radius

21 22
    property var    missionItem ///< MissionItem associated with this editor
    property bool   readOnly    ///< true: read only view, false: full editing view
Don Gagne's avatar
Don Gagne committed
23
    property var    qgcView     ///< QGCView control used for showing dialogs
Don Gagne's avatar
Don Gagne committed
24

25 26
    signal clicked
    signal remove
27
    signal insert(int i)
28
    signal moveHomeToMapCenter
Don Gagne's avatar
Don Gagne committed
29

30 31 32 33
    readonly property real  _editFieldWidth:    ScreenTools.defaultFontPixelWidth * 16
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
    property color          _outerTextColor:    missionItem.isCurrentItem ? "black" : qgcPal.text
Don Gagne's avatar
Don Gagne committed
34

35

Don Gagne's avatar
Don Gagne committed
36 37 38
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
39 40
    }

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    MouseArea {
        anchors.fill:   parent
        visible:        !missionItem.isCurrentItem
        onClicked:      _root.clicked()
    }

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
        text:                   missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
        color:                  _outerTextColor
    }

    Image {
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
        width:                  commandPicker.height
        height:                 commandPicker.height
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0

        MouseArea {
            anchors.fill:   parent
            onClicked:      hamburgerMenu.popup()

            Menu {
                id: hamburgerMenu

                MenuItem {
                    text:           "Insert"
                    onTriggered:    insert(missionItem.sequenceNumber)
                }

                MenuItem {
                    text:           "Delete"
                    onTriggered:    remove()
                }

                MenuSeparator {
85
                    visible: missionItem.isSimpleItem
86 87 88 89 90 91
                }

                MenuItem {
                    text:       "Show all values"
                    checkable:  true
                    checked:    missionItem.rawEdit
92
                    visible:    missionItem.isSimpleItem
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

                    onTriggered:    {
                        if (missionItem.rawEdit) {
                            if (missionItem.friendlyEditAllowed) {
                                missionItem.rawEdit = false
                            } else {
                                qgcView.showMessage("Mission Edit", "You have made changes to the mission item which cannot be shown in Simple Mode", StandardButton.Ok)
                            }
                        } else {
                            missionItem.rawEdit = true
                        }
                        checked = missionItem.rawEdit
                    }
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
        anchors.right:          hamburger.left
117
        visible:                missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit && missionItem.isSimpleItem
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

        onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", qgcView.showDialogDefaultWidth, StandardButton.Cancel)
    }

    QGCLabel {
        anchors.fill:       commandPicker
133
        visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem || !missionItem.isSimpleItem
134
        verticalAlignment:  Text.AlignVCenter
135
        text:               missionItem.sequenceNumber == 0 ? "Home Position" : (missionItem.isSimpleItem ? missionItem.commandName : "Survey")
136 137 138 139 140 141 142 143 144
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
145
        sourceComponent:    missionItem.isSimpleItem ? simpleMissionItemEditor : complexMissionItemEditor
146 147 148 149 150

        /// How wide the loaded component should be
        property real availableWidth: _root.width - (_margin * 2)
    }

151
    Component {
152
        id: valuesComponent
153

154 155 156 157 158 159 160 161 162 163 164 165 166
        Rectangle {
            id:                 valuesRect
            height:             valuesItem.height
            color:              qgcPal.windowShadeDark
            visible:            missionItem.isCurrentItem
            radius:             _radius

            Item {
                id:                 valuesItem
                anchors.margins:    _margin
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
167
                height:             valuesColumn.height + (_margin * 2)
168 169 170 171 172 173 174 175 176 177 178 179 180 181

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

                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        text:       missionItem.sequenceNumber == 0 ?
                                        "Planned home position." :
                                        (missionItem.rawEdit ?
182 183
                                             "Provides advanced access to all commands/parameters. Be very careful!" :
                                             missionItem.commandDescription)
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

                        Item {
                            width:  valuesColumn.width
                            height: comboBoxFact.height

                            QGCLabel {
                                id:                 comboBoxLabel
                                anchors.baseline:   comboBoxFact.baseline
                                text:               object.name
                                visible:            object.name != ""
                            }

                            FactComboBox {
                                id:             comboBoxFact
                                anchors.right:  parent.right
                                width:          comboBoxLabel.visible ? _editFieldWidth : parent.width
                                indexModel:     false
                                model:          object.enumStrings
                                fact:           object
                            }
                        }
                    }

                    Repeater {
                        model: missionItem.textFieldFacts

                        Item {
                            width:  valuesColumn.width
                            height: textField.height

                            QGCLabel {
                                id:                 textFieldLabel
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
                            }
                        }
                    }

                    Repeater {
                        model: missionItem.checkboxFacts

                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }

                    QGCButton {
                        text:       "Move Home to map center"
                        visible:    missionItem.homePosition
                        onClicked:  moveHomeToMapCenter()
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                } // Column
            } // Item
        } // Rectangle
260 261 262

    }

263 264
    Component {
        id: simpleMissionItemEditor
Don Gagne's avatar
Don Gagne committed
265

266 267 268 269
        Item {
            id:     innerItem
            width:  availableWidth
            height: _showValues ? valuesLoader.y + valuesLoader.height : valuesLoader.y
270

271
            property bool _showValues: missionItem.isCurrentItem
272

273 274 275 276 277 278 279 280
            Loader {
                id:                 valuesLoader
                anchors.left:       parent.left
                anchors.right:      parent.right
                sourceComponent:    _showValues ? valuesComponent : undefined
            }
        } // Item
    } // Component - simpleMissionItemEditor
281

282 283
    Component {
        id: complexMissionItemEditor
284

285 286 287 288 289 290
        Rectangle {
            id:         outerRect
            height:     editorColumn.height + (_margin * 2)
            width:      availableWidth
            color:      qgcPal.windowShadeDark
            radius:     _radius
291

292
            property bool addPointsMode: false
293

294 295 296 297 298 299 300
            Column {
                id:                 editorColumn
                anchors.margins:    _margin
                anchors.top:        parent.top
                anchors.left:       parent.left
                width:              availableWidth
                spacing:            _margin
301

302 303 304 305 306 307
                Connections {
                    target: editorMap

                    onMapClicked: {
                        if (addPointsMode) {
                            missionItem.addPolygonCoordinate(coordinate)
308 309 310
                        }
                    }
                }
Don Gagne's avatar
Don Gagne committed
311

312 313 314 315
                QGCLabel {
                    text:       "Fly a grid pattern over a defined area."
                    wrapMode:   Text.WordWrap
                }
Don Gagne's avatar
Don Gagne committed
316

317 318 319 320 321 322 323 324 325 326
                QGCButton {
                    text: addPointsMode ? "Finished" : "Draw Polygon"
                    onClicked: {
                        if (addPointsMode) {
                            addPointsMode = false
                        } else {
                            missionItem.clearPolygon()
                            addPointsMode = true
                        }
                    }
Don Gagne's avatar
Don Gagne committed
327 328
                }
            }
Don Gagne's avatar
Don Gagne committed
329
        }
330
    } // Component - complexMissionItemEditor
Don Gagne's avatar
Don Gagne committed
331

Don Gagne's avatar
Don Gagne committed
332
} // Rectangle