MissionItemEditor.qml 7.4 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
    property bool   _singleComplexItem:         missionController.complexMissionItemNames.length === 1
37

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

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

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

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

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

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

83
    }
84

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

        Menu {
94
            id: hamburgerMenu
95 96

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

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

                Instantiator {
                    model: missionController.complexMissionItemNames

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

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

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

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

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

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

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

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

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

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

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

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

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

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

205 206
        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