MissionItemEditor.qml 8.68 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
Gus Grubba's avatar
Gus Grubba committed
18
    height: header.height + (editorLoader.visible ? (editorLoader.height + (_margin * 3)) : 0)
19
    color:  _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
20 21
    radius: _radius

22
    property var    map                 ///< Map control
23
    property var    masterController
24 25
    property var    missionItem         ///< MissionItem associated with this editor
    property bool   readOnly            ///< true: read only view, false: full editing view
26
    property var    rootQgcView
Don Gagne's avatar
Don Gagne committed
27

28 29
    signal clicked
    signal remove
30 31
    signal insertWaypoint
    signal insertComplexItem(string complexItemName)
Don Gagne's avatar
Don Gagne committed
32

33 34
    property var    _masterController:          masterController
    property var    _missionController:         _masterController.missionController
35 36 37
    property bool   _currentItem:               missionItem.isCurrentItem
    property bool   _noMissionItemsAdded:       ListView.view.model.count === 1
    property real   _sectionSpacer:             ScreenTools.defaultFontPixelWidth / 2  // spacing between section headings
38
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
39

40
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 12)
Gus Grubba's avatar
Gus Grubba committed
41 42 43
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth * 0.5
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth * 0.5
    readonly property real  _hamburgerSize:     header.height * 0.75
44
    readonly property bool  _waypointsOnlyMode: QGroundControl.corePlugin.options.missionWaypointsOnly
45

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

51 52
    FocusScope {
        id:             currentItemScope
53
        anchors.fill:   parent
54 55 56 57 58 59 60
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                currentItemScope.focus = true
                _root.clicked()
            }
        }
61 62
    }

Gus Grubba's avatar
Gus Grubba committed
63
    //-- Dialog
64 65 66 67 68 69 70
    Component {
        id: editPositionDialog
        EditPositionDialog {
            coordinate: missionItem.coordinate
            onCoordinateChanged: missionItem.coordinate = coordinate
        }
    }
Gus Grubba's avatar
Gus Grubba committed
71 72 73 74 75 76
    //-- Header
    Row {
        id:                     header
        spacing:                ScreenTools.defaultFontPixelWidth
        height:                 ScreenTools.defaultFontPixelHeight * 3
        anchors.verticalCenter: editorLoader.visible ? undefined : parent.verticalCenter
77
        anchors.left:           parent.left
Gus Grubba's avatar
Gus Grubba committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
        Item {
            width:              ScreenTools.defaultFontPixelWidth * 3
            height:             parent.height
            QGCColoredImage {
                width:              ScreenTools.defaultFontPixelHeight
                height:             width
                sourceSize.height:  width
                source:             "qrc:/qmlimages/Home.svg"
                visible:            missionItem.homePosition
                color:              qgcPal.text
                anchors.centerIn:   parent
            }
            QGCLabel {
                text:               missionItem.sequenceNumber
                color:              qgcPal.text
                visible:            !missionItem.homePosition
                anchors.centerIn:   parent
            }
        }
        QGCLabel {
            id:                 label
            visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
            text:               missionItem.commandName
            color:              qgcPal.text
            anchors.verticalCenter: parent.verticalCenter
        }
        QGCButton {
            id:                  commandPicker
            visible:             !label.visible
            text:                missionItem.commandName
            anchors.verticalCenter: parent.verticalCenter
            Component {
                id: commandDialog
                MissionCommandDialog {
                    missionItem: _root.missionItem
                }
            }
            onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
        }
118
    }
Gus Grubba's avatar
Gus Grubba committed
119
    //-- Hamburger button at the right of header
Gus Grubba's avatar
Gus Grubba committed
120
    QGCColoredImage {
121 122 123
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
Gus Grubba's avatar
Gus Grubba committed
124
        anchors.verticalCenter: header.verticalCenter
125 126 127
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
128
        source:                 "qrc:/qmlimages/Hamburger.svg"
Gus Grubba's avatar
Gus Grubba committed
129 130
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber !== 0
        color:                  qgcPal.text
131
    }
Gus Grubba's avatar
Gus Grubba committed
132
    //-- Hamburger Menu
133
    QGCMouseArea {
134 135
        fillItem:   hamburger
        visible:    hamburger.visible
136 137
        onClicked: {
            currentItemScope.focus = true
138
            hamburgerMenu.popup()
139
        }
140
        Menu {
141
            id: hamburgerMenu
142
            MenuItem {
143
                text:           qsTr("Insert waypoint")
144
                onTriggered:    insertWaypoint()
145
            }
146
            Menu {
147 148 149
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
150
                Instantiator {
151
                    model: _missionController.complexMissionItemNames
152 153
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
154 155 156 157 158 159
                    MenuItem {
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }
160
            MenuItem {
161
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
162
                visible:        _singleComplexItem
163
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
164 165 166 167 168
            }
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
169
            MenuItem {
170
                text:           qsTr("Change command...")
171
                onTriggered:    commandPicker.clicked()
172
                visible:        !_waypointsOnlyMode
173
            }
174 175 176 177 178
            MenuItem {
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
                onTriggered:    qgcView.showDialog(editPositionDialog, qsTr("Edit Position"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
            }
179
            MenuSeparator {
180
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
181 182
            }
            MenuItem {
Gus Grubba's avatar
Gus Grubba committed
183 184 185 186 187
                text:           qsTr("Show all values")
                checkable:      true
                checked:        missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:        missionItem.isSimpleItem && !_waypointsOnlyMode
                onTriggered: {
188 189 190
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
191
                        } else {
192
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
193
                        }
194 195
                    } else {
                        missionItem.rawEdit = true
196
                    }
197
                    checked = missionItem.rawEdit
198 199 200 201
                }
            }
        }
    }
Gus Grubba's avatar
Gus Grubba committed
202
    //-- Editor Content
203 204 205 206
    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.left:       parent.left
Gus Grubba's avatar
Gus Grubba committed
207
        anchors.top:        header.bottom
208
        source:             missionItem.editorQml
209
        visible:            _currentItem
210 211 212
        property var    masterController:   _masterController
        property real   availableWidth:     _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:         _root
213
    }
Gus Grubba's avatar
Gus Grubba committed
214
}