Skip to content
MissionItemEditor.qml 7.94 KiB
Newer Older
Don Gagne's avatar
Don Gagne committed
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
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

Don Gagne's avatar
Don Gagne committed
    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
    property var    qgcView     ///< QGCView control used for showing dialogs
    signal clicked
    signal remove
    height: innerItem.height + (_margin * 3)
    color:  missionItem.isCurrentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
    radius: _radius
Don Gagne's avatar
Don Gagne committed
    readonly property real _editFieldWidth:     ScreenTools.defaultFontPixelWidth * 16
    readonly property real _margin:             ScreenTools.defaultFontPixelWidth / 2
    readonly property real _radius:             ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
    Item {
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
        anchors.margins:    _margin
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
        height:             valuesRect.visible ? valuesRect.y + valuesRect.height : valuesRect.y
        MouseArea {
            anchors.fill:   parent
            visible:        !missionItem.isCurrentItem

            onClicked: _root.clicked()
        }

Don Gagne's avatar
Don Gagne committed
        QGCLabel {
            id:                     label
            anchors.verticalCenter: commandPicker.verticalCenter
Don Gagne's avatar
Don Gagne committed
            color:                  missionItem.isCurrentItem ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:                   missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
        Image {
            id:                     rawEdit
Don Gagne's avatar
Don Gagne committed
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          parent.right
            anchors.verticalCenter: commandPicker.verticalCenter
            width:                  commandPicker.height
            height:                 commandPicker.height
            visible:                missionItem.friendlyEditAllowed && missionItem.sequenceNumber != 0 && missionItem.isCurrentItem
            source:                 "qrc:/qmlimages/CogWheel.svg"

            MouseArea {
                anchors.fill:   parent
                onClicked:      missionItem.rawEdit = !missionItem.rawEdit
            }
Don Gagne's avatar
Don Gagne committed
        }
Don Gagne's avatar
Don Gagne committed
        QGCButton {
            id:                     commandPicker
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 2
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.left:           label.right
            anchors.right:          rawEdit.left
            visible:                missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit
            text:                   missionItem.commandName

            Component {
                id: commandDialog

                MissionCommandDialog {
                    missionItem: _root.missionItem
                }
            }
Don Gagne's avatar
Don Gagne committed
            onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", 40, StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
        }
Don Gagne's avatar
Don Gagne committed
        QGCLabel {
            anchors.fill:       commandPicker
            visible:            missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem
            verticalAlignment:  Text.AlignVCenter
            text:               missionItem.sequenceNumber == 0 ? "Home" : missionItem.commandName
            color:              qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
        Rectangle {
            id:                 valuesRect
Don Gagne's avatar
Don Gagne committed
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
            anchors.top:        commandPicker.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
            height:             valuesItem.height
Don Gagne's avatar
Don Gagne committed
            color:              qgcPal.windowShadeDark
            visible:            missionItem.sequenceNumber != 0 && missionItem.isCurrentItem
            radius:             _radius
Don Gagne's avatar
Don Gagne committed
            Item {
                id:                 valuesItem
Don Gagne's avatar
Don Gagne committed
                anchors.margins:    _margin
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
                height:             valuesColumn.height + _margin
Don Gagne's avatar
Don Gagne committed
                Column {
Don Gagne's avatar
Don Gagne committed
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed

                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
                        text:       missionItem.rawEdit ?
                                        "Provides advanced access to all commands/parameters. Be very careful!" :
                                        missionItem.commandDescription
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

                        Item {
                            width:  valuesColumn.width
                            height: comboBoxFact.height

                            QGCLabel {
                                id:                 comboBoxLabel
                                anchors.baseline:   comboBoxFact.baseline
                                text:               object.name
                                visible:            object.name != ""
                            }

                            FactComboBox {
                                id:             comboBoxFact
                                anchors.right:  parent.right
                                width:          comboBoxLabel.visible ? _editFieldWidth : parent.width
                                indexModel:     false
                                model:          object.enumStrings
                                fact:           object
                            }
Don Gagne's avatar
Don Gagne committed
                    Repeater {
Don Gagne's avatar
Don Gagne committed
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed

                        Item {
Don Gagne's avatar
Don Gagne committed
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
                            height: textField.height

                            QGCLabel {
Don Gagne's avatar
Don Gagne committed
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
Don Gagne's avatar
Don Gagne committed
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
                    Repeater {
                        model: missionItem.checkboxFacts
Don Gagne's avatar
Don Gagne committed
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
                } // Column
Don Gagne's avatar
Don Gagne committed
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
} // Rectangle