MissionItemEditor.qml 9.81 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)
Don Gagne's avatar
Don Gagne committed
25

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

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

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

39 40 41 42 43 44 45 46 47 48 49 50 51
    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
52
    Item {
53
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
54
        anchors.margins:    _margin
55 56 57 58
        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
59

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

            onClicked: _root.clicked()
        }

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

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

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

                Menu {
                    id: hamburgerMenu

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

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

                    MenuItem {
                        text:           "Delete all"

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

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

Don Gagne's avatar
Don Gagne committed
131 132 133 134 135
        QGCButton {
            id:                     commandPicker
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.left:           label.right
136
            anchors.right:          hamburger.left
Don Gagne's avatar
Don Gagne committed
137 138 139 140 141 142 143 144 145 146
            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
147

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

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

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

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

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

185 186 187
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
188 189 190 191 192 193 194 195
                        text:       missionItem.rawEdit ?
                                        "Provides advanced access to all commands/parameters. Be very careful!" :
                                        missionItem.commandDescription
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

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

Don Gagne's avatar
Don Gagne committed
218
                    Repeater {
219
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
220 221

                        Item {
222
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
223 224 225
                            height: textField.height

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

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

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
245 246 247
                            }
                        }
                    }
248

249 250
                    Repeater {
                        model: missionItem.checkboxFacts
251

252 253 254 255 256 257
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
                } // Column
Don Gagne's avatar
Don Gagne committed
258 259 260
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
261
} // Rectangle