MissionItemEditor.qml 8.66 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 21
    radius: _radius

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

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

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

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

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

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

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

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

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

Don Gagne's avatar
Don Gagne committed
73 74
    /*
      Trying no sequence numbers in ui
75 76 77 78 79
    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
80
        text:                   missionItem.homePosition ? "P" : missionItem.sequenceNumber
81
        color:                  _outerTextColor
Don Gagne's avatar
Don Gagne committed
82
    }*/
83

Gus Grubba's avatar
Gus Grubba committed
84
    QGCColoredImage {
85 86 87 88
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
89 90 91
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
92
        source:                 "qrc:/qmlimages/Hamburger.svg"
93
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
Don Gagne's avatar
Don Gagne committed
94
        color:                  qgcPal.text
95
    }
96

97
    QGCMouseArea {
98 99
        fillItem:   hamburger
        visible:    hamburger.visible
100 101
        onClicked: {
            currentItemScope.focus = true
102
            hamburgerMenu.popup()
103
        }
104

105
        QGCMenu {
106
            id: hamburgerMenu
107

108
            QGCMenuItem {
109
                text:           qsTr("Insert waypoint")
110
                onTriggered:    insertWaypoint()
111
            }
112

113
            QGCMenu {
114 115 116
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
117 118

                Instantiator {
119
                    model: _missionController.complexMissionItemNames
120

121 122
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
123

124
                    QGCMenuItem {
125 126 127 128 129 130
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

131
            QGCMenuItem {
132
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
133
                visible:        _singleComplexItem
134
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
135 136
            }

137
            QGCMenuItem {
138 139 140 141
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

142
            QGCMenuItem {
143
                text:           qsTr("Change command...")
144
                onTriggered:    commandPicker.clicked()
145
                visible:        missionItem.isSimpleItem && !_waypointsOnlyMode
146
            }
147

148
            QGCMenuItem {
149 150
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
151
                onTriggered:    mainWindow.showComponentDialog(editPositionDialog, qsTr("Edit Position"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
152 153
            }

154
            QGCMenuSeparator {
155
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
156
            }
157

158
            QGCMenuItem {
159 160 161
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
162
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
163

164 165 166 167
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
168
                        } else {
169
                            mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"))
170
                        }
171 172
                    } else {
                        missionItem.rawEdit = true
173
                    }
174
                    checked = missionItem.rawEdit
175 176
                }
            }
Don Gagne's avatar
Don Gagne committed
177 178 179 180 181

            QGCMenuItem {
                text:       qsTr("Item #%1").arg(missionItem.sequenceNumber)
                enabled:    false
            }
182 183 184 185 186
        }
    }

    QGCButton {
        id:                     commandPicker
187
        anchors.topMargin:      _margin / 2
188
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
189 190 191 192 193 194 195

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

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

199
        anchors.top:            parent.top
200
        visible:                !commandLabel.visible
201 202 203 204 205 206
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
207 208
                missionItem:    _root.missionItem
                map:            _root.map
209 210 211
            }
        }

212
        onClicked: mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
213 214 215
    }

    QGCLabel {
Don Gagne's avatar
Don Gagne committed
216 217 218 219 220 221 222
        id:                     commandLabel
        anchors.fill:           commandPicker
        visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
        verticalAlignment:      Text.AlignVCenter
        horizontalAlignment:    Text.AlignHCenter
        text:                   missionItem.commandName
        color:                  _outerTextColor
223 224 225 226 227 228 229 230
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
231
        source:             missionItem.editorQml
232
        visible:            _currentItem
233

234 235 236
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
237
    }
Don Gagne's avatar
Don Gagne committed
238
} // Rectangle