MissionItemEditor.qml 9.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
    radius: _radius
DonLakeFlyer's avatar
DonLakeFlyer committed
21
    opacity: _currentItem ? 1.0 : 0.7
22

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

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

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

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

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

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

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

66 67 68 69 70 71 72 73 74
    Component {
        id: editPositionDialog

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

DonLakeFlyer's avatar
DonLakeFlyer committed
75
    Rectangle {
76 77 78
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
DonLakeFlyer's avatar
DonLakeFlyer committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        width:                  readyForSaveLabel.contentHeight
        height:                 width
        border.width:           1
        border.color:           "red"
        color:                  "white"
        radius:                 width / 2
        visible:                missionItem.readyForSaveState !== VisualMissionItem.ReadyForSave

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

Gus Grubba's avatar
Gus Grubba committed
97
    QGCColoredImage {
98 99 100 101
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
102 103 104
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
105
        source:                 "qrc:/qmlimages/Hamburger.svg"
106
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
Don Gagne's avatar
Don Gagne committed
107
        color:                  qgcPal.text
108
    }
109

110
    QGCMouseArea {
111 112
        fillItem:   hamburger
        visible:    hamburger.visible
113 114
        onClicked: {
            currentItemScope.focus = true
115
            hamburgerMenu.popup()
116
        }
117

118
        QGCMenu {
119
            id: hamburgerMenu
120

121
            QGCMenuItem {
122
                text:           qsTr("Insert waypoint")
123
                onTriggered:    insertWaypoint()
124
            }
125

126
            QGCMenu {
127 128 129
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
130 131

                Instantiator {
132
                    model: _missionController.complexMissionItemNames
133

134 135
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
136

137
                    QGCMenuItem {
138 139 140 141 142 143
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

144
            QGCMenuItem {
145
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
146
                visible:        _singleComplexItem
147
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
148 149
            }

150
            QGCMenuItem {
151 152 153 154
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

155
            QGCMenuItem {
156
                text:           qsTr("Change command...")
157
                onTriggered:    commandPicker.clicked()
158
                visible:        missionItem.isSimpleItem && !_waypointsOnlyMode
159
            }
160

161
            QGCMenuItem {
162 163
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
164
                onTriggered:    mainWindow.showComponentDialog(editPositionDialog, qsTr("Edit Position"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
165 166
            }

167
            QGCMenuSeparator {
168
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
169
            }
170

171
            QGCMenuItem {
172 173 174
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
175
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
176

177 178 179 180
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
181
                        } else {
182
                            mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"))
183
                        }
184 185
                    } else {
                        missionItem.rawEdit = true
186
                    }
187
                    checked = missionItem.rawEdit
188 189
                }
            }
Don Gagne's avatar
Don Gagne committed
190 191 192 193 194

            QGCMenuItem {
                text:       qsTr("Item #%1").arg(missionItem.sequenceNumber)
                enabled:    false
            }
195 196 197 198 199
        }
    }

    QGCButton {
        id:                     commandPicker
200
        anchors.topMargin:      _margin / 2
201
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
202 203 204 205 206 207 208

        anchors.leftMargin:     _margin
        anchors.left:           parent.left

        /*
            Trying no sequence numbers in ui
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
209
        anchors.left:           label.right
Don Gagne's avatar
Don Gagne committed
210 211
        */

212
        anchors.top:            parent.top
213
        visible:                !commandLabel.visible
214 215 216 217 218 219
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
220 221
                missionItem:    _root.missionItem
                map:            _root.map
222 223 224
            }
        }

225
        onClicked: mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
226 227 228
    }

    QGCLabel {
Don Gagne's avatar
Don Gagne committed
229 230 231 232 233 234 235
        id:                     commandLabel
        anchors.fill:           commandPicker
        visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
        verticalAlignment:      Text.AlignVCenter
        horizontalAlignment:    Text.AlignHCenter
        text:                   missionItem.commandName
        color:                  _outerTextColor
236 237 238 239 240 241 242 243
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
244
        source:             missionItem.editorQml
245
        visible:            _currentItem
246

247 248 249
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
250
    }
Don Gagne's avatar
Don Gagne committed
251
} // Rectangle