MissionItemEditor.qml 7.57 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 50 51 52 53 54 55 56 57
    MouseArea {
        anchors.fill:   parent
        onClicked:      _root.clicked()
    }

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
58
        text:                   missionItem.abbreviation.charAt(0)
59 60 61
        color:                  _outerTextColor
    }

Gus Grubba's avatar
Gus Grubba committed
62
    QGCColoredImage {
63 64 65 66
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
67 68 69
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
70 71
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0
Gus Grubba's avatar
Gus Grubba committed
72
        color:                  qgcPal.windowShade
73

74
    }
75

76
    QGCMouseArea {
77 78
        fillItem:   hamburger
        visible:    hamburger.visible
79
        onClicked:  _waypointsOnlyMode ? waypointsOnlyMenu.popup() : normalMenu.popup()
80 81

        Menu {
82
            id: normalMenu
83 84

            MenuItem {
85
                text:           qsTr("Insert waypoint")
86 87
                onTriggered:    insert()
            }
88

89 90 91 92
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
93

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
            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)
                    }
                }
            }

111
            MenuItem {
112
                text:           qsTr("Change command...")
113 114
                onTriggered:    commandPicker.clicked()
            }
115

116 117 118
            MenuSeparator {
                visible: missionItem.isSimpleItem
            }
119

120 121 122 123 124
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem
125

126 127 128 129
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
130
                        } else {
131
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
132
                        }
133 134
                    } else {
                        missionItem.rawEdit = true
135
                    }
136
                    checked = missionItem.rawEdit
137 138 139
                }
            }
        }
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

        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)
                    }
                }
            }

        }
172 173 174 175
    }

    QGCButton {
        id:                     commandPicker
176
        anchors.topMargin:      _margin / 2
177 178 179
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
180
        anchors.top:            parent.top
181
        visible:                !commandLabel.visible
182 183 184 185 186 187 188 189 190 191
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

192
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
193 194 195
    }

    QGCLabel {
196
        id:                 commandLabel
197
        anchors.fill:       commandPicker
198
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
199
        verticalAlignment:  Text.AlignVCenter
200
        text:               missionItem.commandName
201 202 203 204 205 206 207 208 209
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
210
        height:             item ? item.height : 0
211
        source:             missionItem.editorQml
212 213 214 215 216

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

217 218
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
219
    }
Don Gagne's avatar
Don Gagne committed
220
} // Rectangle