MissionItemEditor.qml 8.2 KB
Newer Older
1 2 3 4 5
import QtQuick                      2.11
import QtQuick.Controls             2.4
import QtQuick.Controls.Styles      1.4
import QtQuick.Dialogs              1.2
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
Don Gagne's avatar
Don Gagne committed
26

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

32 33
    property var    _masterController:          masterController
    property var    _missionController:         _masterController.missionController
34 35 36 37
    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
38
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
39

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

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

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

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

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

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

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

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

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

103
        QGCMenu {
104
            id: hamburgerMenu
105

106
            QGCMenuItem {
107
                text:           qsTr("Insert waypoint")
108
                onTriggered:    insertWaypoint()
109
            }
110

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

                Instantiator {
117
                    model: _missionController.complexMissionItemNames
118

119 120
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
121

122
                    QGCMenuItem {
123 124 125 126 127 128
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

129
            QGCMenuItem {
130
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
131
                visible:        _singleComplexItem
132
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
133 134
            }

135
            QGCMenuItem {
136 137 138 139
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

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

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

152
            QGCMenuSeparator {
153
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
154
            }
155

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

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

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

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

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

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

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

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