MissionItemEditor.qml 6.6 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 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

24 25
    signal clicked
    signal remove
Adyasha Dash's avatar
Adyasha Dash committed
26
    signal insert
27
    signal moveHomeToMapCenter
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

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

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

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

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

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

69
    }
70

71
    QGCMouseArea {
72 73
        // The MouseArea for the hamburger is larger than the hamburger image itself in order to provide a larger
        // touch area on mobile
74 75 76 77 78 79 80 81 82 83 84 85
        anchors.leftMargin:     -_touchMarginHorizontal
        anchors.rightMargin:    -_touchMarginHorizontal
        anchors.topMargin:      -_touchMarginVertical
        anchors.bottomMargin:   -_touchMarginVertical
        anchors.fill:           hamburger
        visible:                hamburger.visible
        onClicked:              hamburgerMenu.popup()

        property real _touchWidth:              Math.max(hamburger.width, ScreenTools.minTouchPixels)
        property real _touchHeight:             Math.max(hamburger.height, ScreenTools.minTouchPixels)
        property real _touchMarginHorizontal:   ScreenTools.isMobile ? (_touchWidth - hamburger.width) / 2 : 0
        property real _touchMarginVertical:     ScreenTools.isMobile ? (_touchHeight - hamburger.height) / 2 : 0
86 87 88 89 90 91 92 93

        Menu {
            id: hamburgerMenu

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

95 96 97 98
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
99

100 101 102 103
            MenuItem {
                text:           "Change command..."
                onTriggered:    commandPicker.clicked()
            }
104

105 106 107
            MenuSeparator {
                visible: missionItem.isSimpleItem
            }
108

109 110 111 112 113
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem
114

115 116 117 118
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
119
                        } else {
120
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
121
                        }
122 123
                    } else {
                        missionItem.rawEdit = true
124
                    }
125
                    checked = missionItem.rawEdit
126 127 128 129 130 131 132
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
133
        anchors.topMargin:      _margin / 2
134 135 136
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
137
        anchors.top:            parent.top
138
        visible:                missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit && missionItem.isSimpleItem
139 140 141 142 143 144 145 146 147 148
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

149
        onClicked: qgcView.showDialog(commandDialog, qsTr("Select Mission Command"), qgcView.showDialogDefaultWidth, StandardButton.Cancel)
150 151 152 153
    }

    QGCLabel {
        anchors.fill:       commandPicker
154
        visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem || !missionItem.isSimpleItem
155
        verticalAlignment:  Text.AlignVCenter
156
        text:               missionItem.sequenceNumber == 0 ? qsTr("Mission Settings") : missionItem.commandName
157 158 159 160 161 162 163 164 165
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
166
        height:             item ? item.height : 0
167
        source:             missionItem.sequenceNumber == 0 ? "qrc:/qml/MissionSettingsEditor.qml" : missionItem.editorQml
168 169 170 171 172

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

173 174
        property real   availableWidth: _root.width - (_margin * 2) ///< How wide the editor should be
        property var    editorRoot:     _root
175
    }
Don Gagne's avatar
Don Gagne committed
176
} // Rectangle