MissionItemEditor.qml 10.3 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
    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
19
    property var    qgcView     ///< QGCView control used for showing dialogs
Don Gagne's avatar
Don Gagne committed
20

21 22
    signal clicked
    signal remove
23
    signal removeAll
24
    signal insert(int i)
25
    signal moveHomeToMapCenter
Don Gagne's avatar
Don Gagne committed
26

27
    height: innerItem.height + (_margin * 3)
28
    color:  missionItem.isCurrentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
29
    radius: _radius
Don Gagne's avatar
Don Gagne committed
30

31
    readonly property real _editFieldWidth:     ScreenTools.defaultFontPixelWidth * 16
32 33
    readonly property real _margin:             ScreenTools.defaultFontPixelWidth / 2
    readonly property real _radius:             ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
34

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

40 41 42 43 44 45 46 47 48 49 50 51 52
    Component {
        id: deleteAllPromptDialog

        QGCViewMessage {
            message: "Are you sure you want to delete all mission items?"

            function accept() {
                removeAll()
                hideDialog()
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
53
    Item {
54
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
55
        anchors.margins:    _margin
56 57 58 59
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
        height:             valuesRect.visible ? valuesRect.y + valuesRect.height : valuesRect.y
Don Gagne's avatar
Don Gagne committed
60

61 62 63 64 65 66 67
        MouseArea {
            anchors.fill:   parent
            visible:        !missionItem.isCurrentItem

            onClicked: _root.clicked()
        }

68
        QGCLabel {
69 70
            id:                     label
            anchors.verticalCenter: commandPicker.verticalCenter
71 72
            color:                  missionItem.isCurrentItem ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:                   missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
73 74
        }

75
        Image {
76
            id:                     hamburger
Don Gagne's avatar
Don Gagne committed
77 78
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          parent.right
79 80 81
            anchors.verticalCenter: commandPicker.verticalCenter
            width:                  commandPicker.height
            height:                 commandPicker.height
82 83
            source:                 "qrc:/qmlimages/Hamburger.svg"
            visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0
84 85 86

            MouseArea {
                anchors.fill:   parent
87 88 89 90 91
                onClicked:      hamburgerMenu.popup()

                Menu {
                    id: hamburgerMenu

92 93 94 95 96
                    MenuItem {
                        text:           "Insert"
                        onTriggered:    insert(missionItem.sequenceNumber)
                    }

97 98 99 100 101 102 103 104
                    MenuItem {
                        text:           "Delete"
                        onTriggered:    remove()
                    }

                    MenuItem {
                        text:           "Delete all"

105
                        onTriggered: qgcView.showDialog(deleteAllPromptDialog, "Delete all", qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
                    }

                    MenuSeparator { }

                    MenuItem {
                        text:       "Show all values"
                        checkable:  true
                        checked:    missionItem.rawEdit

                        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
                        }
                    }
                }
129
            }
Don Gagne's avatar
Don Gagne committed
130
        }
Don Gagne's avatar
Don Gagne committed
131

Don Gagne's avatar
Don Gagne committed
132 133 134 135 136
        QGCButton {
            id:                     commandPicker
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.left:           label.right
137
            anchors.right:          hamburger.left
Don Gagne's avatar
Don Gagne committed
138 139 140 141 142 143 144 145 146 147
            visible:                missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit
            text:                   missionItem.commandName

            Component {
                id: commandDialog

                MissionCommandDialog {
                    missionItem: _root.missionItem
                }
            }
Don Gagne's avatar
Don Gagne committed
148

149
            onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", qgcView.showDialogDefaultWidth, StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
150
        }
Don Gagne's avatar
Don Gagne committed
151

152 153 154 155
        QGCLabel {
            anchors.fill:       commandPicker
            visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem
            verticalAlignment:  Text.AlignVCenter
156
            text:               missionItem.sequenceNumber == 0 ? "Home Position" : missionItem.commandName
157
            color:              qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
158 159
        }

Don Gagne's avatar
Don Gagne committed
160
        Rectangle {
161
            id:                 valuesRect
162
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
163 164 165
            anchors.top:        commandPicker.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
166
            height:             valuesItem.height
Don Gagne's avatar
Don Gagne committed
167
            color:              qgcPal.windowShadeDark
168
            visible:            missionItem.isCurrentItem
169
            radius:             _radius
Don Gagne's avatar
Don Gagne committed
170

Don Gagne's avatar
Don Gagne committed
171
            Item {
172
                id:                 valuesItem
Don Gagne's avatar
Don Gagne committed
173
                anchors.margins:    _margin
174 175 176 177
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
                height:             valuesColumn.height + _margin
Don Gagne's avatar
Don Gagne committed
178

Don Gagne's avatar
Don Gagne committed
179
                Column {
180 181 182 183 184
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed
185

186 187 188
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
189 190 191 192 193
                        text:       missionItem.sequenceNumber == 0 ?
                                        "Planned home position." :
                                        (missionItem.rawEdit ?
                                            "Provides advanced access to all commands/parameters. Be very careful!" :
                                            missionItem.commandDescription)
194 195 196 197 198
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
                        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
                            }
218
                        }
219 220
                    }

Don Gagne's avatar
Don Gagne committed
221
                    Repeater {
222
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
223 224

                        Item {
225
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
226 227 228
                            height: textField.height

                            QGCLabel {
229
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
230 231 232 233 234 235 236 237 238 239
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
240 241 242 243 244 245 246 247
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
248 249 250
                            }
                        }
                    }
251

252 253
                    Repeater {
                        model: missionItem.checkboxFacts
254

255 256 257 258 259
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
260 261 262 263 264 265 266

                    QGCButton {
                        text:       "Move Home to map center"
                        visible:    missionItem.homePosition
                        onClicked:  moveHomeToMapCenter()
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
267
                } // Column
Don Gagne's avatar
Don Gagne committed
268 269 270
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
271
} // Rectangle