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

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

Don Gagne's avatar
Don Gagne committed
14 15 16

/// Mission item edit control
Rectangle {
17
    id:     _root
18
    height: editorLoader.y + (editorLoader.visible ? editorLoader.height : 0) + (_margin * 2)
19
    color:  _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
20 21
    radius: _radius

22
    property var    map                 ///< Map control
23
    property var    masterController
24 25
    property var    missionItem         ///< MissionItem associated with this editor
    property bool   readOnly            ///< true: read only view, false: full editing view
26
    property var    rootQgcView
Don Gagne's avatar
Don Gagne committed
27

28 29
    signal clicked
    signal remove
30 31
    signal insertWaypoint
    signal insertComplexItem(string complexItemName)
Don Gagne's avatar
Don Gagne committed
32

33 34
    property var    _masterController:          masterController
    property var    _missionController:         _masterController.missionController
35 36 37 38
    property bool   _currentItem:               missionItem.isCurrentItem
    property color  _outerTextColor:            _currentItem ? qgcPal.primaryButtonText : qgcPal.text
    property bool   _noMissionItemsAdded:       ListView.view.model.count === 1
    property real   _sectionSpacer:             ScreenTools.defaultFontPixelWidth / 2  // spacing between section headings
39
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
40

41
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 12)
42 43
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
44
    readonly property real  _hamburgerSize:     commandPicker.height * 0.75
45
    readonly property bool  _waypointsOnlyMode: QGroundControl.corePlugin.options.missionWaypointsOnly
46

Don Gagne's avatar
Don Gagne committed
47 48 49
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
50 51
    }

52 53
    FocusScope {
        id:             currentItemScope
54
        anchors.fill:   parent
55 56 57 58 59 60 61 62

        MouseArea {
            anchors.fill:   parent
            onClicked: {
                currentItemScope.focus = true
                _root.clicked()
            }
        }
63 64
    }

65 66 67 68 69 70 71 72 73
    Component {
        id: editPositionDialog

        EditPositionDialog {
            coordinate: missionItem.coordinate
            onCoordinateChanged: missionItem.coordinate = coordinate
        }
    }

74 75 76 77 78
    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
79
        text:                   missionItem.homePosition ? "P" : missionItem.sequenceNumber
80 81 82
        color:                  _outerTextColor
    }

Gus Grubba's avatar
Gus Grubba committed
83
    QGCColoredImage {
84 85 86 87
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
88 89 90
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
91
        source:                 "qrc:/qmlimages/Hamburger.svg"
92
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
Gus Grubba's avatar
Gus Grubba committed
93
        color:                  qgcPal.windowShade
94

95
    }
96

97
    QGCMouseArea {
98 99
        fillItem:   hamburger
        visible:    hamburger.visible
100 101
        onClicked: {
            currentItemScope.focus = true
102
            hamburgerMenu.popup()
103
        }
104 105

        Menu {
106
            id: hamburgerMenu
107 108

            MenuItem {
109
                text:           qsTr("Insert waypoint")
110
                onTriggered:    insertWaypoint()
111
            }
112

113
            Menu {
114 115 116
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
117 118

                Instantiator {
119
                    model: _missionController.complexMissionItemNames
120

121 122
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
123 124 125 126 127 128 129 130

                    MenuItem {
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

131
            MenuItem {
132
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
133
                visible:        _singleComplexItem
134
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
135 136 137 138 139 140 141
            }

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

142
            MenuItem {
143
                text:           qsTr("Change command...")
144
                onTriggered:    commandPicker.clicked()
145
                visible:        !_waypointsOnlyMode
146
            }
147

148 149 150 151 152 153
            MenuItem {
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
                onTriggered:    qgcView.showDialog(editPositionDialog, qsTr("Edit Position"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
            }

154
            MenuSeparator {
155
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
156
            }
157

158 159 160 161
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
162
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
163

164 165 166 167
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
168
                        } else {
169
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
170
                        }
171 172
                    } else {
                        missionItem.rawEdit = true
173
                    }
174
                    checked = missionItem.rawEdit
175 176 177 178 179 180 181
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
182
        anchors.topMargin:      _margin / 2
183 184 185
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
186
        anchors.top:            parent.top
187
        visible:                !commandLabel.visible
188 189 190 191 192 193 194 195 196 197
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

198
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
199 200 201
    }

    QGCLabel {
202
        id:                 commandLabel
203
        anchors.fill:       commandPicker
204
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
205
        verticalAlignment:  Text.AlignVCenter
206
        text:               missionItem.commandName
207 208 209 210 211 212 213 214 215
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
216
        source:             missionItem.editorQml
217
        visible:            _currentItem
218

219 220 221
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
222
    }
Don Gagne's avatar
Don Gagne committed
223
} // Rectangle