MissionItemEditor.qml 10.1 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 18 19 20 21 22 23
    id:             _root
    height:         editorLoader.visible ? (editorLoader.y + editorLoader.height + (_margin * 2)) : (commandPicker.y + commandPicker.height + _margin / 2)
    color:          _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
    radius:         _radius
    opacity:        _currentItem ? 1.0 : 0.7
    border.width:   _readyForSave ? 0 : 1
    border.color:   qgcPal.warningText
24

25
    property var    map                 ///< Map control
26
    property var    masterController
27 28
    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
29

30 31
    signal clicked
    signal remove
32 33
    signal insertWaypoint
    signal insertComplexItem(string complexItemName)
34
    signal selectNextNotReadyItem
Don Gagne's avatar
Don Gagne committed
35

36 37
    property var    _masterController:          masterController
    property var    _missionController:         _masterController.missionController
38 39 40 41
    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
42
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
43
    property bool   _readyForSave:              missionItem.readyForSaveState === VisualMissionItem.ReadyForSave
44

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

Don Gagne's avatar
Don Gagne committed
51 52 53
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
54 55
    }

56 57
    FocusScope {
        id:             currentItemScope
58
        anchors.fill:   parent
59 60 61 62 63 64 65 66

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

69 70 71 72 73 74 75 76 77
    Component {
        id: editPositionDialog

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

DonLakeFlyer's avatar
DonLakeFlyer committed
78
    Rectangle {
79 80
        id:                     notReadyForSaveIndicator
        anchors.verticalCenter: notReadyForSaveLabel.visible ? notReadyForSaveLabel.verticalCenter : commandPicker.verticalCenter
81 82
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
DonLakeFlyer's avatar
DonLakeFlyer committed
83 84 85
        width:                  readyForSaveLabel.contentHeight
        height:                 width
        border.width:           1
86
        border.color:           qgcPal.warningText
DonLakeFlyer's avatar
DonLakeFlyer committed
87 88
        color:                  "white"
        radius:                 width / 2
89
        visible:                !_readyForSave
DonLakeFlyer's avatar
DonLakeFlyer committed
90 91 92 93 94 95

        QGCLabel {
            id:                 readyForSaveLabel
            anchors.centerIn:   parent
            //: Indicator in Plan view to show mission item is not ready for save/send
            text:               qsTr("?")
96
            color:              qgcPal.warningText
DonLakeFlyer's avatar
DonLakeFlyer committed
97 98 99
            font.pointSize:     ScreenTools.smallFontPointSize
        }
    }
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    QGCLabel {
        id:                     notReadyForSaveLabel
        anchors.margins:        _margin
        anchors.left:           notReadyForSaveIndicator.right
        anchors.right:          parent.right
        anchors.top:            commandPicker.bottom
        visible:                _currentItem && !_readyForSave
        text:                   missionItem.readyForSaveState === VisualMissionItem.NotReadyForSaveTerrain ?
                                    qsTr("Incomplete: Waiting on terrain data.") :
                                    qsTr("Incomplete: Item not fully specified.")
        wrapMode:               Text.WordWrap
        horizontalAlignment:    Text.AlignHCenter
        color:                  qgcPal.warningText
    }

Gus Grubba's avatar
Gus Grubba committed
116
    QGCColoredImage {
117 118 119 120
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
121 122 123
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
124
        source:                 "qrc:/qmlimages/Hamburger.svg"
125
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
Don Gagne's avatar
Don Gagne committed
126
        color:                  qgcPal.text
127
    }
128

129
    QGCMouseArea {
130 131
        fillItem:   hamburger
        visible:    hamburger.visible
132 133
        onClicked: {
            currentItemScope.focus = true
134
            hamburgerMenu.popup()
135
        }
136

137
        QGCMenu {
138
            id: hamburgerMenu
139

140
            QGCMenuItem {
141
                text:           qsTr("Insert waypoint")
142
                onTriggered:    insertWaypoint()
143
            }
144

145
            QGCMenu {
146 147 148
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
149 150

                Instantiator {
151
                    model: _missionController.complexMissionItemNames
152

153 154
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
155

156
                    QGCMenuItem {
157 158 159 160 161 162
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

163
            QGCMenuItem {
164
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
165
                visible:        _singleComplexItem
166
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
167 168
            }

169
            QGCMenuItem {
170 171 172 173
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

174
            QGCMenuItem {
175
                text:           qsTr("Change command...")
176
                onTriggered:    commandPicker.clicked()
177
                visible:        missionItem.isSimpleItem && !_waypointsOnlyMode
178
            }
179

180
            QGCMenuItem {
181 182
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
183
                onTriggered:    mainWindow.showComponentDialog(editPositionDialog, qsTr("Edit Position"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
184 185
            }

186
            QGCMenuSeparator {
187
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
188
            }
189

190
            QGCMenuItem {
191 192 193
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
194
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
195

196 197 198 199
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
200
                        } else {
201
                            mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"))
202
                        }
203 204
                    } else {
                        missionItem.rawEdit = true
205
                    }
206
                    checked = missionItem.rawEdit
207 208
                }
            }
Don Gagne's avatar
Don Gagne committed
209 210 211 212 213

            QGCMenuItem {
                text:       qsTr("Item #%1").arg(missionItem.sequenceNumber)
                enabled:    false
            }
214 215 216 217 218
        }
    }

    QGCButton {
        id:                     commandPicker
219
        anchors.topMargin:      _margin
220
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
221 222
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
223
        anchors.top:            parent.top
224
        visible:                !commandLabel.visible
225 226 227 228 229 230
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
231 232
                missionItem:    _root.missionItem
                map:            _root.map
233 234 235
            }
        }

236
        onClicked: mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
237 238 239
    }

    QGCLabel {
Don Gagne's avatar
Don Gagne committed
240 241 242 243 244 245 246
        id:                     commandLabel
        anchors.fill:           commandPicker
        visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
        verticalAlignment:      Text.AlignVCenter
        horizontalAlignment:    Text.AlignHCenter
        text:                   missionItem.commandName
        color:                  _outerTextColor
247 248 249 250
    }

    Loader {
        id:                 editorLoader
251
        anchors.margins:    _margin
252
        anchors.left:       parent.left
253
        anchors.top:        _readyForSave ? commandPicker.bottom : notReadyForSaveLabel.bottom
254
        source:             missionItem.editorQml
255
        visible:            _currentItem
256

257 258 259
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
260
    }
Don Gagne's avatar
Don Gagne committed
261
} // Rectangle