MissionItemEditor.qml 9.17 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)
Don Gagne's avatar
Don Gagne committed
32

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

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

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

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

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

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

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

DonLakeFlyer's avatar
DonLakeFlyer committed
74
    Rectangle {
75 76 77
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
DonLakeFlyer's avatar
DonLakeFlyer committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        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
        }
    }
95

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

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

117
        QGCMenu {
118
            id: hamburgerMenu
119

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

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

                Instantiator {
131
                    model: _missionController.complexMissionItemNames
132

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Component {
            id: commandDialog

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

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

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

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

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