MissionItemEditor.qml 7.45 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.height + (_margin * 2)
19
    color:  _currentItem ? qgcPal.primaryButton : qgcPal.windowShade
20 21
    radius: _radius

22 23 24 25
    property var    map                 ///< Map control
    property var    missionController
    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 35 36
    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
37
    property bool   _singleComplexItem:         missionController.complexMissionItemNames.length === 1
38

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

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

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

        MouseArea {
            anchors.fill:   parent
            onClicked: {
                currentItemScope.focus = true
                _root.clicked()
            }
        }
61 62 63 64 65 66 67
    }

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

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

84
    }
85

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

        Menu {
95
            id: hamburgerMenu
96 97

            MenuItem {
98
                text:           qsTr("Insert waypoint")
99
                onTriggered:    insertWaypoint()
100
            }
101

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

                Instantiator {
                    model: missionController.complexMissionItemNames

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

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

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

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

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

137
            MenuSeparator {
138
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
139
            }
140

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

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

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

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

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

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

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
199
        height:             item ? item.height : 0
200
        source:             missionItem.editorQml
201 202 203 204 205

        onLoaded: {
            item.visible = Qt.binding(function() { return _currentItem; })
        }

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