MissionItemEditor.qml 5.84 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
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 22
    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
23
    property var    qgcView     ///< QGCView control used for showing dialogs
Don Gagne's avatar
Don Gagne committed
24

25 26
    signal clicked
    signal remove
27
    signal insert(int i)
28
    signal moveHomeToMapCenter
Don Gagne's avatar
Don Gagne committed
29

30 31 32
    property bool   _currentItem:       missionItem.isCurrentItem
    property color  _outerTextColor:    _currentItem ? "black" : qgcPal.text

Don Gagne's avatar
Don Gagne committed
33
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 16)
34 35
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
36

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

42 43 44 45 46 47 48 49 50 51 52 53

    MouseArea {
        anchors.fill:   parent
        visible:        !missionItem.isCurrentItem
        onClicked:      _root.clicked()
    }

    QGCLabel {
        id:                     label
        anchors.verticalCenter: commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
54
        text:                   missionItem.abbreviation
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        color:                  _outerTextColor
    }

    Image {
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
        width:                  commandPicker.height
        height:                 commandPicker.height
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0

        MouseArea {
            anchors.fill:   parent
            onClicked:      hamburgerMenu.popup()

            Menu {
                id: hamburgerMenu

                MenuItem {
76
                    text:           qsTr("Insert")
77 78 79 80
                    onTriggered:    insert(missionItem.sequenceNumber)
                }

                MenuItem {
81
                    text:           qsTr("Delete")
82 83 84
                    onTriggered:    remove()
                }

85 86 87 88 89
                MenuItem {
                    text:           "Change command..."
                    onTriggered:    commandPicker.clicked()
                }

90
                MenuSeparator {
91
                    visible: missionItem.isSimpleItem
92 93 94
                }

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

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

    QGCButton {
        id:                     commandPicker
119
        anchors.topMargin:      _margin / 2
120 121 122
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
123 124
        anchors.top:            parent.top
        //anchors.right:          hamburger.left
125
        visible:                missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit && missionItem.isSimpleItem
126 127 128 129 130 131 132 133 134 135
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

136
        onClicked:              qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
137 138 139 140
    }

    QGCLabel {
        anchors.fill:       commandPicker
141
        visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem || !missionItem.isSimpleItem
142
        verticalAlignment:  Text.AlignVCenter
143
        text:               missionItem.sequenceNumber == 0 ? qsTr("Home Position") : (missionItem.isSimpleItem ? missionItem.commandName : qsTr("Survey"))
144 145 146 147 148 149 150 151 152
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
153 154
        height:             _currentItem && item ? item.height : 0
        source:             _currentItem ? (missionItem.isSimpleItem ? "qrc:/qml/SimpleItemEditor.qml" : "qrc:/qml/SurveyItemEditor.qml") : ""
155

156 157
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
158
    }
Don Gagne's avatar
Don Gagne committed
159
} // Rectangle