MissionItemEditor.qml 6.96 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
        onClicked: {
            currentItemScope.focus = true
89
            hamburgerMenu.popup()
90
        }
91 92

        Menu {
93
            id: hamburgerMenu
94 95

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

100 101 102 103
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
            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)
                    }
                }
            }

122
            MenuItem {
123
                text:           qsTr("Change command...")
124
                onTriggered:    commandPicker.clicked()
125
                visible:        !_waypointsOnlyMode
126
            }
127

128
            MenuSeparator {
129
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
130
            }
131

132 133 134 135
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
136
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
137

138 139 140 141
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
142
                        } else {
143
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
144
                        }
145 146
                    } else {
                        missionItem.rawEdit = true
147
                    }
148
                    checked = missionItem.rawEdit
149 150 151 152 153 154 155
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
156
        anchors.topMargin:      _margin / 2
157 158 159
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
160
        anchors.top:            parent.top
161
        visible:                !commandLabel.visible
162 163 164 165 166 167 168 169 170 171
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

172
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
173 174 175
    }

    QGCLabel {
176
        id:                 commandLabel
177
        anchors.fill:       commandPicker
178
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
179
        verticalAlignment:  Text.AlignVCenter
180
        text:               missionItem.commandName
181 182 183 184 185 186 187 188 189
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
190
        height:             item ? item.height : 0
191
        source:             missionItem.editorQml
192 193 194 195 196

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

197 198
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
199
    }
Don Gagne's avatar
Don Gagne committed
200
} // Rectangle