MissionItemEditor.qml 9.96 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 insert(int i)
24
    signal moveHomeToMapCenter
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

34 35
    property bool _showValues: missionItem.isCurrentItem

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
    Component {
42
        id: valuesComponent
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        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
                height:             valuesColumn.height + _margin

                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 ?
                                            "Provides advanced access to all commands/parameters. Be very careful!" :
                                            missionItem.commandDescription)
                    }

                    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
150 151 152

    }

Don Gagne's avatar
Don Gagne committed
153
    Item {
154
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
155
        anchors.margins:    _margin
156 157 158
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
159
        height:             _showValues ? valuesLoader.y + valuesLoader.height : valuesLoader.y
Don Gagne's avatar
Don Gagne committed
160

161 162 163 164 165 166 167
        MouseArea {
            anchors.fill:   parent
            visible:        !missionItem.isCurrentItem

            onClicked: _root.clicked()
        }

168
        QGCLabel {
169 170
            id:                     label
            anchors.verticalCenter: commandPicker.verticalCenter
171 172
            color:                  missionItem.isCurrentItem ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:                   missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
173 174
        }

175
        Image {
176
            id:                     hamburger
Don Gagne's avatar
Don Gagne committed
177 178
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          parent.right
179 180 181
            anchors.verticalCenter: commandPicker.verticalCenter
            width:                  commandPicker.height
            height:                 commandPicker.height
182 183
            source:                 "qrc:/qmlimages/Hamburger.svg"
            visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0
184 185 186

            MouseArea {
                anchors.fill:   parent
187 188 189 190 191
                onClicked:      hamburgerMenu.popup()

                Menu {
                    id: hamburgerMenu

192 193 194 195 196
                    MenuItem {
                        text:           "Insert"
                        onTriggered:    insert(missionItem.sequenceNumber)
                    }

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
                    MenuItem {
                        text:           "Delete"
                        onTriggered:    remove()
                    }

                    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
                        }
                    }
                }
223
            }
Don Gagne's avatar
Don Gagne committed
224
        }
Don Gagne's avatar
Don Gagne committed
225

Don Gagne's avatar
Don Gagne committed
226 227 228 229 230
        QGCButton {
            id:                     commandPicker
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.left:           label.right
231
            anchors.right:          hamburger.left
Don Gagne's avatar
Don Gagne committed
232 233 234 235 236 237 238 239 240 241
            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
242

243
            onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", qgcView.showDialogDefaultWidth, StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
244
        }
Don Gagne's avatar
Don Gagne committed
245

246 247 248 249
        QGCLabel {
            anchors.fill:       commandPicker
            visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem
            verticalAlignment:  Text.AlignVCenter
250
            text:               missionItem.sequenceNumber == 0 ? "Home Position" : missionItem.commandName
251
            color:              qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
252 253
        }

254 255
        Loader {
            id:                 valuesLoader
256
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
257 258 259
            anchors.top:        commandPicker.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
260 261
            sourceComponent:    _showValues ? valuesComponent : undefined
        }
Don Gagne's avatar
Don Gagne committed
262
    } // Item
Don Gagne's avatar
Don Gagne committed
263
} // Rectangle