Skip to content
MissionItemEditor.qml 5.73 KiB
Newer Older
import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed
import QtQuick.Dialogs          1.2
Don Gagne's avatar
Don Gagne committed

import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
Don Gagne's avatar
Don Gagne committed
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
import QGroundControl.Palette       1.0

Don Gagne's avatar
Don Gagne committed

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

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

    property var    map             ///< Map control
    property var    missionItem     ///< MissionItem associated with this editor
    property bool   readOnly        ///< true: read only view, false: full editing view
    signal clicked
    signal remove
Adyasha Dash's avatar
Adyasha Dash committed
    signal insert
    property bool   _currentItem:           missionItem.isCurrentItem
    property color  _outerTextColor:        _currentItem ? "black" : qgcPal.text
DonLakeFlyer's avatar
DonLakeFlyer committed
    property bool   _noMissionItemsAdded:   ListView.view.model.count === 1
    property real   _sectionSpacer:         ScreenTools.defaultFontPixelWidth / 2  // spacing between section headings
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 12)
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _hamburgerSize:     commandPicker.height * 0.75
Don Gagne's avatar
Don Gagne committed
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
    MouseArea {
        anchors.fill:   parent
        onClicked:      _root.clicked()
    }

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

Gus Grubba's avatar
Gus Grubba committed
    QGCColoredImage {
        id:                     hamburger
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.right:          parent.right
        anchors.verticalCenter: commandPicker.verticalCenter
        width:                  _hamburgerSize
        height:                 _hamburgerSize
        sourceSize.height:      _hamburgerSize
        source:                 "qrc:/qmlimages/Hamburger.svg"
        visible:                missionItem.isCurrentItem && missionItem.sequenceNumber != 0
Gus Grubba's avatar
Gus Grubba committed
        color:                  qgcPal.windowShade
    QGCMouseArea {
        fillItem:   hamburger
        visible:    hamburger.visible
        onClicked:  hamburgerMenu.popup()
Don Gagne's avatar
Don Gagne committed

        Menu {
            id: hamburgerMenu

            MenuItem {
                text:           qsTr("Insert")
                onTriggered:    insert()
            }
Don Gagne's avatar
Don Gagne committed
            MenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }
Don Gagne's avatar
Don Gagne committed
            MenuItem {
                text:           "Change command..."
                onTriggered:    commandPicker.clicked()
            }
Don Gagne's avatar
Don Gagne committed
            MenuSeparator {
                visible: missionItem.isSimpleItem
            }
Don Gagne's avatar
Don Gagne committed
            MenuItem {
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem
Don Gagne's avatar
Don Gagne committed
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
Don Gagne's avatar
Don Gagne committed
                            qgcView.showMessage(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"), StandardButton.Ok)
Don Gagne's avatar
Don Gagne committed
                    } else {
                        missionItem.rawEdit = true
Don Gagne's avatar
Don Gagne committed
                    checked = missionItem.rawEdit
                }
            }
        }
    }

    QGCButton {
        id:                     commandPicker
        anchors.topMargin:      _margin / 2
        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
        anchors.left:           label.right
        anchors.top:            parent.top
        visible:                missionItem.isCurrentItem && !missionItem.rawEdit && missionItem.isSimpleItem
        text:                   missionItem.commandName

        Component {
            id: commandDialog

            MissionCommandDialog {
                missionItem: _root.missionItem
            }
        }

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

    QGCLabel {
        anchors.fill:       commandPicker
        visible:            !missionItem.isCurrentItem || !missionItem.isSimpleItem
        verticalAlignment:  Text.AlignVCenter
        text:               missionItem.commandName
        color:              _outerTextColor
    }

    Loader {
        id:                 editorLoader
        anchors.leftMargin: _margin
        anchors.topMargin:  _margin
        anchors.left:       parent.left
        anchors.top:        commandPicker.bottom
        height:             item ? item.height : 0
        source:             missionItem.editorQml

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

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