MissionItemEditor.qml 11.9 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
6
import QtQuick.Layouts              1.11
Don Gagne's avatar
Don Gagne committed
7

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

Don Gagne's avatar
Don Gagne committed
15 16 17

/// Mission item edit control
Rectangle {
18 19 20 21 22 23 24
    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
25

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

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

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

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

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

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

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

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

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

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

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

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    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
117
    QGCColoredImage {
118 119 120 121
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
122 123 124
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
125
        source:                 "qrc:/qmlimages/Hamburger.svg"
126
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
Don Gagne's avatar
Don Gagne committed
127
        color:                  qgcPal.text
128
    }
129

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

138
        QGCMenu {
139
            id: hamburgerMenu
140

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

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

                Instantiator {
152
                    model: _missionController.complexMissionItemNames
153

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

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

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

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

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

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

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

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

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

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

218 219 220
    QGCColoredImage {
        id:                     deleteButton
        anchors.margins:        _margin
Don Gagne's avatar
Don Gagne committed
221
        anchors.left:           parent.left
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
        anchors.verticalCenter: commandPicker.verticalCenter
        height:                 _hamburgerSize
        width:                  height
        sourceSize.height:      height
        fillMode:               Image.PreserveAspectFit
        mipmap:                 true
        smooth:                 true
        color:                  qgcPal.text
        visible:                _currentItem && missionItem.sequenceNumber !== 0
        source:                 "/res/TrashDelete.svg"

        QGCMouseArea {
            fillItem:   parent
            onClicked:  remove()
        }
    }

    Rectangle {
        id:                 commandPicker
        anchors.margins:    _margin
        anchors.left:       deleteButton.right
        anchors.top:        parent.top
        height:             ScreenTools.implicitComboBoxHeight
        width:              innerLayout.x + innerLayout.width + ScreenTools.comboBoxPadding
        visible:            !commandLabel.visible
        color:              qgcPal.window
        border.width:       1
        border.color:       qgcPal.text

        RowLayout {
            id:                 innerLayout
            anchors.margins:    _padding
            anchors.left:       parent.left
            anchors.top:        parent.top
            spacing:            _padding

            property real _padding: ScreenTools.comboBoxPadding

            QGCLabel { text: missionItem.commandName }

            QGCColoredImage {
                height:             ScreenTools.implicitComboBoxHeight - (ScreenTools.comboBoxPadding * 2)
                width:              height
                sourceSize.height:  height
                fillMode:           Image.PreserveAspectFit
                smooth:             true
                antialiasing:       true
                color:              qgcPal.text
                source:             "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/double-arrow.png"
            }
        }

        QGCMouseArea {
            fillItem:   parent
            onClicked:  mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
        }
278 279 280 281 282

        Component {
            id: commandDialog

            MissionCommandDialog {
283 284
                missionItem:    _root.missionItem
                map:            _root.map
285 286 287 288 289 290
            }
        }

    }

    QGCLabel {
Don Gagne's avatar
Don Gagne committed
291
        id:                     commandLabel
292
        anchors.leftMargin:     ScreenTools.comboBoxPadding
Don Gagne's avatar
Don Gagne committed
293 294 295 296 297
        anchors.fill:           commandPicker
        visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
        verticalAlignment:      Text.AlignVCenter
        text:                   missionItem.commandName
        color:                  _outerTextColor
298 299 300 301
    }

    Loader {
        id:                 editorLoader
302
        anchors.margins:    _margin
303
        anchors.left:       parent.left
304
        anchors.top:        _readyForSave ? commandPicker.bottom : notReadyForSaveLabel.bottom
305
        source:             missionItem.editorQml
306
        visible:            _currentItem
307

308 309 310
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
311
    }
Don Gagne's avatar
Don Gagne committed
312
} // Rectangle