MissionItemEditor.qml 5.72 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
Don Gagne's avatar
Don Gagne committed
5 6 7

import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
Don Gagne's avatar
Don Gagne committed
8 9
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
10 11
import QGroundControl.Palette       1.0

Don Gagne's avatar
Don Gagne committed
12 13 14

/// Mission item edit control
Rectangle {
15 16
    id: _root

17
    height: editorLoader.y + editorLoader.height + (_margin * 2)
18
    color:  _currentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
19 20
    radius: _radius

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

25 26
    signal clicked
    signal remove
Adyasha Dash's avatar
Adyasha Dash committed
27
    signal insert
Don Gagne's avatar
Don Gagne committed
28

29 30 31
    property bool   _currentItem:           missionItem.isCurrentItem
    property color  _outerTextColor:        _currentItem ? "black" : qgcPal.text
    property bool   _noMissionItemsAdded:   ListView.view.model.count == 1
32
    property real   _sectionSpacer:         ScreenTools.defaultFontPixelWidth / 2  // spacing between section headings
33

34
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 12)
35 36
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
37
    readonly property real  _hamburgerSize:     commandPicker.height * 0.75
38

Don Gagne's avatar
Don Gagne committed
39 40 41
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
42 43
    }

44 45 46 47 48 49 50 51 52 53
    MouseArea {
        anchors.fill:   parent
        onClicked:      _root.clicked()
    }

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
54
        text:                   missionItem.abbreviation
55 56 57
        color:                  _outerTextColor
    }

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

70
    }
71

72
    QGCMouseArea {
73 74 75
        fillItem:   hamburger
        visible:    hamburger.visible
        onClicked:  hamburgerMenu.popup()
76 77 78 79 80 81 82 83

        Menu {
            id: hamburgerMenu

            MenuItem {
                text:           qsTr("Insert")
                onTriggered:    insert()
            }
84

85 86 87 88
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
89

90 91 92 93
            MenuItem {
                text:           "Change command..."
                onTriggered:    commandPicker.clicked()
            }
94

95 96 97
            MenuSeparator {
                visible: missionItem.isSimpleItem
            }
98

99 100 101 102 103
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem
104

105 106 107 108
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
109
                        } else {
110
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
111
                        }
112 113
                    } else {
                        missionItem.rawEdit = true
114
                    }
115
                    checked = missionItem.rawEdit
116 117 118 119 120 121 122
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
123
        anchors.topMargin:      _margin / 2
124 125 126
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
127
        anchors.top:            parent.top
128
        visible:                missionItem.isCurrentItem && !missionItem.rawEdit && missionItem.isSimpleItem
129 130 131 132 133 134 135 136 137 138
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

139
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
140 141 142 143
    }

    QGCLabel {
        anchors.fill:       commandPicker
144
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem
145
        verticalAlignment:  Text.AlignVCenter
146
        text:               missionItem.commandName
147 148 149 150 151 152 153 154 155
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
156
        height:             item ? item.height : 0
157
        source:             missionItem.editorQml
158 159 160 161 162

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

163 164
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
165
    }
Don Gagne's avatar
Don Gagne committed
166
} // Rectangle