MissionItemEditor.qml 7.94 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 18
    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
19
    property var    qgcView     ///< QGCView control used for showing dialogs
Don Gagne's avatar
Don Gagne committed
20

21 22
    signal clicked
    signal remove
Don Gagne's avatar
Don Gagne committed
23

24
    height: innerItem.height + (_margin * 3)
25
    color:  missionItem.isCurrentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
26
    radius: _radius
Don Gagne's avatar
Don Gagne committed
27

28
    readonly property real _editFieldWidth:     ScreenTools.defaultFontPixelWidth * 16
29 30
    readonly property real _margin:             ScreenTools.defaultFontPixelWidth / 2
    readonly property real _radius:             ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
31

Don Gagne's avatar
Don Gagne committed
32 33 34
    QGCPalette {
        id: qgcPal
        colorGroupEnabled: enabled
Don Gagne's avatar
Don Gagne committed
35 36
    }

Don Gagne's avatar
Don Gagne committed
37
    Item {
38
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
39
        anchors.margins:    _margin
40 41 42 43
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
        height:             valuesRect.visible ? valuesRect.y + valuesRect.height : valuesRect.y
Don Gagne's avatar
Don Gagne committed
44

45 46 47 48 49 50 51
        MouseArea {
            anchors.fill:   parent
            visible:        !missionItem.isCurrentItem

            onClicked: _root.clicked()
        }

52
        QGCLabel {
53 54
            id:                     label
            anchors.verticalCenter: commandPicker.verticalCenter
55 56
            color:                  missionItem.isCurrentItem ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:                   missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
57 58
        }

59 60
        Image {
            id:                     rawEdit
Don Gagne's avatar
Don Gagne committed
61 62
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          parent.right
63 64 65 66 67 68 69 70 71 72
            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
73
        }
Don Gagne's avatar
Don Gagne committed
74

Don Gagne's avatar
Don Gagne committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        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
91

Don Gagne's avatar
Don Gagne committed
92
            onClicked:              qgcView.showDialog(commandDialog, "Select Mission Command", 40, StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
93
        }
Don Gagne's avatar
Don Gagne committed
94

95 96 97 98 99 100
        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
101 102
        }

Don Gagne's avatar
Don Gagne committed
103
        Rectangle {
104
            id:                 valuesRect
105
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
106 107 108
            anchors.top:        commandPicker.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
109
            height:             valuesItem.height
Don Gagne's avatar
Don Gagne committed
110
            color:              qgcPal.windowShadeDark
111
            visible:            missionItem.sequenceNumber != 0 && missionItem.isCurrentItem
112
            radius:             _radius
Don Gagne's avatar
Don Gagne committed
113

Don Gagne's avatar
Don Gagne committed
114
            Item {
115
                id:                 valuesItem
Don Gagne's avatar
Don Gagne committed
116
                anchors.margins:    _margin
117 118 119 120
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
                height:             valuesColumn.height + _margin
Don Gagne's avatar
Don Gagne committed
121

Don Gagne's avatar
Don Gagne committed
122
                Column {
123 124 125 126 127
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed
128

129 130 131
                    QGCLabel {
                        width:      parent.width
                        wrapMode:   Text.WordWrap
132 133 134 135 136 137 138 139
                        text:       missionItem.rawEdit ?
                                        "Provides advanced access to all commands/parameters. Be very careful!" :
                                        missionItem.commandDescription
                    }

                    Repeater {
                        model: missionItem.comboboxFacts

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
                        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
                            }
159
                        }
160 161
                    }

Don Gagne's avatar
Don Gagne committed
162
                    Repeater {
163
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
164 165

                        Item {
166
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
167 168 169
                            height: textField.height

                            QGCLabel {
170
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
171 172 173 174 175 176 177 178 179 180
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
181 182 183 184 185 186 187 188
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
189 190 191
                            }
                        }
                    }
192

193 194
                    Repeater {
                        model: missionItem.checkboxFacts
195

196 197 198 199 200 201
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
                } // Column
Don Gagne's avatar
Don Gagne committed
202 203 204
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
205
} // Rectangle