MissionItemEditor.qml 7.58 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed
4
import QtQuick.Dialogs          1.2
5
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
18
    height: editorLoader.y + (editorLoader.visible ? editorLoader.height : 0) + (_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
26
    property var    rootQgcView
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
    }

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
70
        text:                   missionItem.homePosition ? "H" : missionItem.sequenceNumber
71 72 73
        color:                  _outerTextColor
    }

Gus Grubba's avatar
Gus Grubba committed
74
    QGCColoredImage {
75 76 77 78
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
79 80 81
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
82 83
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0
Gus Grubba's avatar
Gus Grubba committed
84
        color:                  qgcPal.windowShade
85

86
    }
87

88
    QGCMouseArea {
89 90
        fillItem:   hamburger
        visible:    hamburger.visible
91 92
        onClicked: {
            currentItemScope.focus = true
93
            hamburgerMenu.popup()
94
        }
95 96

        Menu {
97
            id: hamburgerMenu
98 99

            MenuItem {
100
                text:           qsTr("Insert waypoint")
101
                onTriggered:    insertWaypoint()
102
            }
103

104
            Menu {
105 106 107
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
108 109

                Instantiator {
110
                    model: _missionController.complexMissionItemNames
111

112 113
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
114 115 116 117 118 119 120 121

                    MenuItem {
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

122
            MenuItem {
123
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
124
                visible:        _singleComplexItem
125
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
126 127 128 129 130 131 132
            }

            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

133
            MenuItem {
134
                text:           qsTr("Change command...")
135
                onTriggered:    commandPicker.clicked()
136
                visible:        !_waypointsOnlyMode
137
            }
138

139
            MenuSeparator {
140
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
141
            }
142

143 144 145 146
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
147
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
148

149 150 151 152
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
153
                        } else {
154
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
155
                        }
156 157
                    } else {
                        missionItem.rawEdit = true
158
                    }
159
                    checked = missionItem.rawEdit
160 161 162 163 164 165 166
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
167
        anchors.topMargin:      _margin / 2
168 169 170
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
171
        anchors.top:            parent.top
172
        visible:                !commandLabel.visible
173 174 175 176 177 178 179 180 181 182
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

183
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
184 185 186
    }

    QGCLabel {
187
        id:                 commandLabel
188
        anchors.fill:       commandPicker
189
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
190
        verticalAlignment:  Text.AlignVCenter
191
        text:               missionItem.commandName
192 193 194 195 196 197 198 199 200
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
201
        source:             missionItem.editorQml
202
        visible:            _currentItem
203

204 205 206
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
207
    }
Don Gagne's avatar
Don Gagne committed
208
} // Rectangle