MissionItemEditor.qml 11.6 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
    id:             _root
19
    height:         editorLoader.visible ? (editorLoader.y + editorLoader.height + _innerMargin) : (topRowLayout.y + topRowLayout.height + _margin)
20 21 22
    color:          _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
    radius:         _radius
    opacity:        _currentItem ? 1.0 : 0.7
DoinLakeFlyer's avatar
DoinLakeFlyer committed
23
    border.width:   _readyForSave ? 0 : 2
24
    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
    signal selectNextNotReadyItem
Don Gagne's avatar
Don Gagne committed
34

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

44
    readonly property real  _editFieldWidth:    Math.min(width - _innerMargin * 2, ScreenTools.defaultFontPixelWidth * 12)
45
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
46
    readonly property real  _innerMargin:       2
47
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
48
    readonly property real  _hamburgerSize:     commandPicker.height * 0.75
49
    readonly property real  _trashSize:         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
        }
    }

79 80 81 82 83 84
    Row {
        id:                 topRowLayout
        anchors.margins:    _margin
        anchors.left:       parent.left
        anchors.top:        parent.top
        spacing:            _margin
85

86 87 88
        Rectangle {
            id:                     notReadyForSaveIndicator
            anchors.verticalCenter: parent.verticalCenter
DoinLakeFlyer's avatar
DoinLakeFlyer committed
89
            width:                  _hamburgerSize
90 91 92 93 94 95 96 97 98 99 100 101 102 103
            height:                 width
            border.width:           1
            border.color:           qgcPal.warningText
            color:                  "white"
            radius:                 width / 2
            visible:                !_readyForSave

            QGCLabel {
                id:                 readyForSaveLabel
                anchors.centerIn:   parent
                //: Indicator in Plan view to show mission item is not ready for save/send
                text:               qsTr("?")
                color:              qgcPal.warningText
                font.pointSize:     ScreenTools.smallFontPointSize
104
            }
105
        }
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        QGCColoredImage {
            id:                     deleteButton
            anchors.verticalCenter: parent.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()
123
            }
124
        }
125

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
        Item {
            id:                     commandPicker
            anchors.verticalCenter: parent.verticalCenter
            height:                 ScreenTools.implicitComboBoxHeight
            width:                  innerLayout.width
            visible:                !commandLabel.visible

            RowLayout {
                id:                     innerLayout
                anchors.verticalCenter: parent.verticalCenter
                spacing:                _padding

                property real _padding: ScreenTools.comboBoxPadding

                QGCLabel { text: missionItem.commandName }

                QGCColoredImage {
                    height:             ScreenTools.defaultFontPixelWidth
                    width:              height
                    fillMode:           Image.PreserveAspectFit
                    smooth:             true
                    antialiasing:       true
                    color:              qgcPal.text
                    source:             "/qmlimages/arrow-down.png"
                }
151 152
            }

153 154 155
            QGCMouseArea {
                fillItem:   parent
                onClicked:  mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
156
            }
157

158 159
            Component {
                id: commandDialog
160

161
                MissionCommandDialog {
162
                    vehicle:                    masterController.controllerVehicle
163 164 165 166
                    missionItem:                _root.missionItem
                    map:                        _root.map
                    // FIXME: Disabling fly through commands doesn't work since you may need to change from an RTL to something else
                    flyThroughCommandsAllowed:  true //_missionController.flyThroughCommandsAllowed
167 168
                }
            }
169
        }
Don Gagne's avatar
Don Gagne committed
170

171 172 173 174 175 176 177 178 179
        QGCLabel {
            id:                     commandLabel
            anchors.verticalCenter: parent.verticalCenter
            width:                  commandPicker.width
            height:                 commandPicker.height
            visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode || missionItem.isTakeoffItem
            verticalAlignment:      Text.AlignVCenter
            text:                   missionItem.commandName
            color:                  _outerTextColor
180 181 182
        }
    }

183 184
   QGCColoredImage {
        id:                     hamburger
185
        anchors.margins:        _margin
186
        anchors.right:          parent.right
187
        anchors.verticalCenter: topRowLayout.verticalCenter
188
        width:                  _hamburgerSize
189
        height:                 _hamburgerSize
190 191 192
        sourceSize.height:      _hamburgerSize
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
193 194 195
        color:                  qgcPal.text

        QGCMouseArea {
196 197 198 199 200
            fillItem:   hamburger
            onClicked: {
                currentItemScope.focus = true
                hamburgerMenu.popup()
            }
201

202 203
            QGCMenu {
                id: hamburgerMenu
204

205 206 207 208 209
                QGCMenuItem {
                    text:           qsTr("Move to vehicle position")
                    visible:        missionItem.specifiesCoordinate
                    enabled:        _activeVehicle
                    onTriggered:    missionItem.coordinate = _activeVehicle.coordinate
210 211

                    property var    _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle
212
                }
213

214 215 216 217 218
                QGCMenuItem {
                    text:           qsTr("Move to previous item position")
                    visible:        _missionController.previousCoordinate.isValid
                    onTriggered:    missionItem.coordinate = _missionController.previousCoordinate
                }
219

220 221 222 223 224
                QGCMenuItem {
                    text:           qsTr("Edit position...")
                    visible:        missionItem.specifiesCoordinate
                    onTriggered:    mainWindow.showComponentDialog(editPositionDialog, qsTr("Edit Position"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
                }
225

226 227 228
                QGCMenuSeparator {
                    visible: missionItem.isSimpleItem && !_waypointsOnlyMode
                }
229

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
                QGCMenuItem {
                    text:       qsTr("Show all values")
                    checkable:  true
                    checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                    visible:    missionItem.isSimpleItem && !_waypointsOnlyMode

                    onTriggered:    {
                        if (missionItem.rawEdit) {
                            if (missionItem.friendlyEditAllowed) {
                                missionItem.rawEdit = false
                            } else {
                                mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"))
                            }
                        } else {
                            missionItem.rawEdit = true
                        }
                        checked = missionItem.rawEdit
                    }
                }
249

250 251 252 253
                QGCMenuItem {
                    text:       qsTr("Item #%1").arg(missionItem.sequenceNumber)
                    enabled:    false
                }
254 255 256 257
            }
        }
    }

258
    /*
259
    QGCLabel {
260 261 262 263 264 265 266 267 268 269 270 271
        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
272 273
    }

274 275
*/

276 277
    Loader {
        id:                 editorLoader
278
        anchors.margins:    _innerMargin
279
        anchors.left:       parent.left
280
        anchors.top:        topRowLayout.bottom
281
        source:             missionItem.editorQml
282
        visible:            _currentItem
283

284
        property var    masterController:   _masterController
285
        property real   availableWidth:     _root.width - (anchors.margins * 2) ///< How wide the editor should be
286
        property var    editorRoot:         _root
287
    }
Don Gagne's avatar
Don Gagne committed
288
} // Rectangle