MissionItemEditor.qml 7.88 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
    property var    map             ///< Map control
23 24
    property var    missionItem     ///< MissionItem associated with this editor
    property bool   readOnly        ///< true: read only view, false: full editing view
25
    property var    rootQgcView
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 34 35
    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
36

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

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

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

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

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
66
        text:                   missionItem.abbreviation.charAt(0)
67 68 69
        color:                  _outerTextColor
    }

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

82
    }
83

84
    QGCMouseArea {
85 86
        fillItem:   hamburger
        visible:    hamburger.visible
87 88 89 90 91 92 93 94
        onClicked: {
            currentItemScope.focus = true
            if (_waypointsOnlyMode) {
                waypointsOnlyMenu.popup()
            } else {
                normalMenu.popup()
            }
        }
95 96

        Menu {
97
            id: normalMenu
98 99

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

104 105 106 107
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
            Menu {
                id:     normalPatternMenu
                title:  qsTr("Insert pattern")

                Instantiator {
                    model: missionController.complexMissionItemNames

                    onObjectAdded:      normalPatternMenu.insertItem(index, object)
                    onObjectRemoved:    normalPatternMenu.removeItem(object)

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

126
            MenuItem {
127
                text:           qsTr("Change command...")
128 129
                onTriggered:    commandPicker.clicked()
            }
130

131 132 133
            MenuSeparator {
                visible: missionItem.isSimpleItem
            }
134

135 136 137 138 139
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem
140

141 142 143 144
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
145
                        } else {
146
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
147
                        }
148 149
                    } else {
                        missionItem.rawEdit = true
150
                    }
151
                    checked = missionItem.rawEdit
152 153 154
                }
            }
        }
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

        Menu {
            id: waypointsOnlyMenu

            MenuItem {
                text:           qsTr("Insert waypoint")
                onTriggered:    insertWaypoint()
            }

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

            Menu {
                id:     waypointsOnlyPatternMenu
                title:  qsTr("Insert pattern")

                Instantiator {
                    model: missionController.complexMissionItemNames

                    onObjectAdded:      waypointsOnlyPatternMenu.insertItem(index, object)
                    onObjectRemoved:    waypointsOnlyPatternMenu.removeItem(object)

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

        }
187 188 189 190
    }

    QGCButton {
        id:                     commandPicker
191
        anchors.topMargin:      _margin / 2
192 193 194
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
195
        anchors.top:            parent.top
196
        visible:                !commandLabel.visible
197 198 199 200 201 202 203 204 205 206
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

207
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
208 209 210
    }

    QGCLabel {
211
        id:                 commandLabel
212
        anchors.fill:       commandPicker
213
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
214
        verticalAlignment:  Text.AlignVCenter
215
        text:               missionItem.commandName
216 217 218 219 220 221 222 223 224
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
225
        height:             item ? item.height : 0
226
        source:             missionItem.editorQml
227 228 229 230 231

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

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