MissionItemEditor.qml 7.08 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
                onTriggered:    insertWaypoint()
102
            }
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
                onTriggered:    commandPicker.clicked()
129
                visible:        !_waypointsOnlyMode
130
            }
131

132
            MenuSeparator {
133
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
134
            }
135

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

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

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

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

176
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
177 178 179
    }

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

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
194
        height:             item ? item.height : 0
195
        source:             missionItem.editorQml
196 197 198 199 200

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

201 202
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
203
    }
Don Gagne's avatar
Don Gagne committed
204
} // Rectangle