Skip to content
MissionItemEditor.qml 11.9 KiB
Newer Older
import QtQuick                      2.11
import QtQuick.Controls             2.4
import QtQuick.Controls.Styles      1.4
import QtQuick.Dialogs              1.2
import QtQml                        2.2
DonLakeFlyer's avatar
 
DonLakeFlyer committed
import QtQuick.Layouts              1.11
import QGroundControl               1.0
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 {
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    id:             _root
    height:         editorLoader.visible ? (editorLoader.y + editorLoader.height + (_margin * 2)) : (commandPicker.y + commandPicker.height + _margin / 2)
    color:          _currentItem ? qgcPal.missionItemEditor : qgcPal.windowShade
    radius:         _radius
    opacity:        _currentItem ? 1.0 : 0.7
    border.width:   _readyForSave ? 0 : 1
    border.color:   qgcPal.warningText
    property var    map                 ///< Map control
    property var    masterController
    property var    missionItem         ///< MissionItem associated with this editor
    property bool   readOnly            ///< true: read only view, false: full editing view
    signal clicked
    signal remove
    signal insertWaypoint
    signal insertComplexItem(string complexItemName)
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    signal selectNextNotReadyItem
    property var    _masterController:          masterController
    property var    _missionController:         _masterController.missionController
    property bool   _currentItem:               missionItem.isCurrentItem
    property color  _outerTextColor:            _currentItem ? qgcPal.primaryButtonText : qgcPal.text
    property bool   _noMissionItemsAdded:       ListView.view.model.count === 1
    property real   _sectionSpacer:             ScreenTools.defaultFontPixelWidth / 2  // spacing between section headings
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    property bool   _readyForSave:              missionItem.readyForSaveState === VisualMissionItem.ReadyForSave
    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
    readonly property bool  _waypointsOnlyMode: QGroundControl.corePlugin.options.missionWaypointsOnly
Don Gagne's avatar
Don Gagne committed
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
    FocusScope {
        id:             currentItemScope
        anchors.fill:   parent

        MouseArea {
            anchors.fill:   parent
            onClicked: {
                currentItemScope.focus = true
                _root.clicked()
            }
        }
    Component {
        id: editPositionDialog

        EditPositionDialog {
            coordinate: missionItem.coordinate
            onCoordinateChanged: missionItem.coordinate = coordinate
        }
    }

DonLakeFlyer's avatar
 
DonLakeFlyer committed
    Rectangle {
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        id:                     notReadyForSaveIndicator
        anchors.verticalCenter: notReadyForSaveLabel.visible ? notReadyForSaveLabel.verticalCenter : commandPicker.verticalCenter
        anchors.leftMargin:     _margin
        anchors.left:           parent.left
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        width:                  readyForSaveLabel.contentHeight
        height:                 width
        border.width:           1
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        border.color:           qgcPal.warningText
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        color:                  "white"
        radius:                 width / 2
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        visible:                !_readyForSave
DonLakeFlyer's avatar
 
DonLakeFlyer committed

        QGCLabel {
            id:                 readyForSaveLabel
            anchors.centerIn:   parent
            //: Indicator in Plan view to show mission item is not ready for save/send
            text:               qsTr("?")
DonLakeFlyer's avatar
 
DonLakeFlyer committed
            color:              qgcPal.warningText
DonLakeFlyer's avatar
 
DonLakeFlyer committed
            font.pointSize:     ScreenTools.smallFontPointSize
        }
    }
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    QGCLabel {
        id:                     notReadyForSaveLabel
        anchors.margins:        _margin
        anchors.left:           notReadyForSaveIndicator.right
        anchors.right:          parent.right
        anchors.top:            commandPicker.bottom
        visible:                _currentItem && !_readyForSave
        text:                   missionItem.readyForSaveState === VisualMissionItem.NotReadyForSaveTerrain ?
                                    qsTr("Incomplete: Waiting on terrain data.") :
                                    qsTr("Incomplete: Item not fully specified.")
        wrapMode:               Text.WordWrap
        horizontalAlignment:    Text.AlignHCenter
        color:                  qgcPal.warningText
    }

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
Don Gagne's avatar
 
Don Gagne committed
        color:                  qgcPal.text
    QGCMouseArea {
        fillItem:   hamburger
        visible:    hamburger.visible
        onClicked: {
            currentItemScope.focus = true
DonLakeFlyer's avatar
DonLakeFlyer committed
            hamburgerMenu.popup()
        QGCMenu {
DonLakeFlyer's avatar
DonLakeFlyer committed
            id: hamburgerMenu
            QGCMenuItem {
                text:           qsTr("Insert waypoint")
                onTriggered:    insertWaypoint()
            QGCMenu {
                id:         patternMenu
                title:      qsTr("Insert pattern")
                visible:    !_singleComplexItem
                    model: _missionController.complexMissionItemNames
                    onObjectAdded:      patternMenu.insertItem(index, object)
                    onObjectRemoved:    patternMenu.removeItem(object)
                    QGCMenuItem {
                        text:           modelData
                        onTriggered:    insertComplexItem(modelData)
                    }
                }
            }

            QGCMenuItem {
                text:           qsTr("Insert ") + _missionController.complexMissionItemNames[0]
                visible:        _singleComplexItem
                onTriggered:    insertComplexItem(_missionController.complexMissionItemNames[0])
            QGCMenuItem {
                text:           qsTr("Delete")
                onTriggered:    remove()
            }

            QGCMenuItem {
                text:           qsTr("Change command...")
Don Gagne's avatar
Don Gagne committed
                onTriggered:    commandPicker.clicked()
Don Gagne's avatar
 
Don Gagne committed
                visible:        missionItem.isSimpleItem && !_waypointsOnlyMode
            QGCMenuItem {
                text:           qsTr("Edit position...")
                visible:        missionItem.specifiesCoordinate
                onTriggered:    mainWindow.showComponentDialog(editPositionDialog, qsTr("Edit Position"), mainWindow.showDialogDefaultWidth, StandardButton.Close)
            QGCMenuSeparator {
                visible: missionItem.isSimpleItem && !_waypointsOnlyMode
            QGCMenuItem {
Don Gagne's avatar
Don Gagne committed
                text:       qsTr("Show all values")
                checkable:  true
                checked:    missionItem.isSimpleItem ? missionItem.rawEdit : false
                visible:    missionItem.isSimpleItem && !_waypointsOnlyMode
Don Gagne's avatar
Don Gagne committed
                onTriggered:    {
                    if (missionItem.rawEdit) {
                        if (missionItem.friendlyEditAllowed) {
                            missionItem.rawEdit = false
                            mainWindow.showMessageDialog(qsTr("Mission Edit"), qsTr("You have made changes to the mission item which cannot be shown in Simple Mode"))
Don Gagne's avatar
Don Gagne committed
                    } else {
                        missionItem.rawEdit = true
Don Gagne's avatar
Don Gagne committed
                    checked = missionItem.rawEdit
Don Gagne's avatar
 
Don Gagne committed

            QGCMenuItem {
                text:       qsTr("Item #%1").arg(missionItem.sequenceNumber)
                enabled:    false
            }
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    QGCColoredImage {
        id:                     deleteButton
        anchors.margins:        _margin
Don Gagne's avatar
 
Don Gagne committed
        anchors.left:           parent.left
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        anchors.verticalCenter: commandPicker.verticalCenter
        height:                 _hamburgerSize
        width:                  height
        sourceSize.height:      height
        fillMode:               Image.PreserveAspectFit
        mipmap:                 true
        smooth:                 true
        color:                  qgcPal.text
        visible:                _currentItem && missionItem.sequenceNumber !== 0
        source:                 "/res/TrashDelete.svg"

        QGCMouseArea {
            fillItem:   parent
            onClicked:  remove()
        }
    }

    Rectangle {
        id:                 commandPicker
        anchors.margins:    _margin
        anchors.left:       deleteButton.right
        anchors.top:        parent.top
        height:             ScreenTools.implicitComboBoxHeight
        width:              innerLayout.x + innerLayout.width + ScreenTools.comboBoxPadding
        visible:            !commandLabel.visible
        color:              qgcPal.window
        border.width:       1
        border.color:       qgcPal.text

        RowLayout {
            id:                 innerLayout
            anchors.margins:    _padding
            anchors.left:       parent.left
            anchors.top:        parent.top
            spacing:            _padding

            property real _padding: ScreenTools.comboBoxPadding

            QGCLabel { text: missionItem.commandName }

            QGCColoredImage {
                height:             ScreenTools.implicitComboBoxHeight - (ScreenTools.comboBoxPadding * 2)
                width:              height
                sourceSize.height:  height
                fillMode:           Image.PreserveAspectFit
                smooth:             true
                antialiasing:       true
                color:              qgcPal.text
                source:             "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/double-arrow.png"
            }
        }

        QGCMouseArea {
            fillItem:   parent
            onClicked:  mainWindow.showComponentDialog(commandDialog, qsTr("Select Mission Command"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
        }

        Component {
            id: commandDialog

            MissionCommandDialog {
Don Gagne's avatar
 
Don Gagne committed
                missionItem:    _root.missionItem
                map:            _root.map
Don Gagne's avatar
 
Don Gagne committed
        id:                     commandLabel
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        anchors.leftMargin:     ScreenTools.comboBoxPadding
Don Gagne's avatar
 
Don Gagne committed
        anchors.fill:           commandPicker
        visible:                !missionItem.isCurrentItem || !missionItem.isSimpleItem || _waypointsOnlyMode
        verticalAlignment:      Text.AlignVCenter
        text:                   missionItem.commandName
        color:                  _outerTextColor
    }

    Loader {
        id:                 editorLoader
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        anchors.margins:    _margin
        anchors.left:       parent.left
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        anchors.top:        _readyForSave ? commandPicker.bottom : notReadyForSaveLabel.bottom
        source:             missionItem.editorQml
        visible:            _currentItem
        property var    masterController:   _masterController
        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