MissionItemEditor.qml 9.61 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
Don Gagne's avatar
Don Gagne committed
24

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

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

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

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

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

            onClicked: _root.clicked()
        }

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

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

            MouseArea {
                anchors.fill:   parent
85 86 87 88 89 90 91 92 93 94 95 96 97
                onClicked:      hamburgerMenu.popup()

                Menu {
                    id: hamburgerMenu

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

                    MenuItem {
                        text:           "Delete all"

98
                        onTriggered: qgcView.showDialog(deleteAllPromptDialog, "Delete all", qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                    }

                    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
                        }
                    }
                }
122
            }
Don Gagne's avatar
Don Gagne committed
123
        }
Don Gagne's avatar
Don Gagne committed
124

Don Gagne's avatar
Don Gagne committed
125 126 127 128 129
        QGCButton {
            id:                     commandPicker
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.left:           label.right
130
            anchors.right:          hamburger.left
Don Gagne's avatar
Don Gagne committed
131 132 133 134 135 136 137 138 139 140
            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
141

142
            onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", qgcView.showDialogDefaultWidth, StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
143
        }
Don Gagne's avatar
Don Gagne committed
144

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

Don Gagne's avatar
Don Gagne committed
153
        Rectangle {
154
            id:                 valuesRect
155
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
156 157 158
            anchors.top:        commandPicker.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
159
            height:             valuesItem.height
Don Gagne's avatar
Don Gagne committed
160
            color:              qgcPal.windowShadeDark
161
            visible:            missionItem.sequenceNumber != 0 && missionItem.isCurrentItem
162
            radius:             _radius
Don Gagne's avatar
Don Gagne committed
163

Don Gagne's avatar
Don Gagne committed
164
            Item {
165
                id:                 valuesItem
Don Gagne's avatar
Don Gagne committed
166
                anchors.margins:    _margin
167 168 169 170
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
                height:             valuesColumn.height + _margin
Don Gagne's avatar
Don Gagne committed
171

Don Gagne's avatar
Don Gagne committed
172
                Column {
173 174 175 176 177
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed
178

179 180 181
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
182 183 184 185 186 187 188 189
                        text:       missionItem.rawEdit ?
                                        "Provides advanced access to all commands/parameters. Be very careful!" :
                                        missionItem.commandDescription
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
                        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
                            }
209
                        }
210 211
                    }

Don Gagne's avatar
Don Gagne committed
212
                    Repeater {
213
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
214 215

                        Item {
216
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
217 218 219
                            height: textField.height

                            QGCLabel {
220
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
221 222 223 224 225 226 227 228 229 230
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
231 232 233 234 235 236 237 238
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
239 240 241
                            }
                        }
                    }
242

243 244
                    Repeater {
                        model: missionItem.checkboxFacts
245

246 247 248 249 250 251
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
                } // Column
Don Gagne's avatar
Don Gagne committed
252 253 254
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
255
} // Rectangle