MissionItemEditor.qml 8.16 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
Don Gagne's avatar
Don Gagne committed
18
    height: editorLoader.visible ? (editorLoader.y + editorLoader.height + (_margin * 2)) : (commandPicker.y + commandPicker.height + _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
Don Gagne's avatar
Don Gagne committed
93
        color:                  qgcPal.text
94
    }
95

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

        Menu {
105
            id: hamburgerMenu
106 107

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

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

                Instantiator {
118
                    model: _missionController.complexMissionItemNames
119

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

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

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

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

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

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

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

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

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

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

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

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

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

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

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