MissionItemEditor.qml 7.01 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2

import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
Don Gagne's avatar
Don Gagne committed
7 8
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
9 10
import QGroundControl.Palette       1.0

Don Gagne's avatar
Don Gagne committed
11 12 13

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

16 17
    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
18

19 20
    signal clicked
    signal remove
Don Gagne's avatar
Don Gagne committed
21

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

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

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

Don Gagne's avatar
Don Gagne committed
35
    Item {
36
        id:                 innerItem
Don Gagne's avatar
Don Gagne committed
37
        anchors.margins:    _margin
38 39 40 41
        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
42

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

            onClicked: _root.clicked()
        }

Don Gagne's avatar
Don Gagne committed
50
        MissionItemIndexLabel {
51 52 53
            id:                     label
            anchors.verticalCenter: commandPicker.verticalCenter
            isCurrentItem:          missionItem.isCurrentItem
Don Gagne's avatar
Don Gagne committed
54
            label:                  missionItem.sequenceNumber == 0 ? "H" : missionItem.sequenceNumber
55 56
        }

57 58 59 60 61 62 63 64 65 66 67 68 69 70
        Image {
            id:                     rawEdit
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 8
            anchors.left:           label.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
71
        }
Don Gagne's avatar
Don Gagne committed
72

73
        FactComboBox {
Don Gagne's avatar
Don Gagne committed
74
            id:                 commandPicker
75 76
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.left:       rawEdit.right
Don Gagne's avatar
Don Gagne committed
77
            anchors.right:      parent.right
78 79 80
            indexModel:         false
            fact:               missionItem.supportedCommand
            visible:            missionItem.sequenceNumber != 0 && missionItem.isCurrentItem && !missionItem.rawEdit
Don Gagne's avatar
Don Gagne committed
81

Don Gagne's avatar
Don Gagne committed
82 83
            onActivated: missionItem.commandByIndex = index
        }
Don Gagne's avatar
Don Gagne committed
84

Don Gagne's avatar
Don Gagne committed
85 86 87
        Rectangle {
            anchors.fill:   commandPicker
            color:          qgcPal.button
88
            visible:        missionItem.sequenceNumber == 0 || !missionItem.isCurrentItem
Don Gagne's avatar
Don Gagne committed
89 90 91 92 93

            QGCLabel {
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth
                anchors.fill:       parent
                verticalAlignment:  Text.AlignVCenter
94
                text:               missionItem.sequenceNumber == 0 ? "Home" : missionItem.commandName
Don Gagne's avatar
Don Gagne committed
95 96 97 98
                color:              qgcPal.buttonText
            }
        }

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

Don Gagne's avatar
Don Gagne committed
110
            Item {
111
                id:                 valuesItem
Don Gagne's avatar
Don Gagne committed
112
                anchors.margins:    _margin
113 114 115 116
                anchors.left:       parent.left
                anchors.right:      parent.right
                anchors.top:        parent.top
                height:             valuesColumn.height + _margin
Don Gagne's avatar
Don Gagne committed
117

Don Gagne's avatar
Don Gagne committed
118
                Column {
119 120 121 122 123
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed
124

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

                    Repeater {
                        model: missionItem.comboboxFacts

                        FactComboBox {
                            width:      valuesColumn.width
                            indexModel: false
                            model:      object.enumStrings
                            fact:       object
                        }
142 143
                    }

Don Gagne's avatar
Don Gagne committed
144
                    Repeater {
145
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
146 147

                        Item {
148
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
149 150 151
                            height: textField.height

                            QGCLabel {
152
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
153 154 155 156 157 158 159 160 161 162
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
163 164 165 166 167 168 169 170
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
171 172 173
                            }
                        }
                    }
174

175 176
                    Repeater {
                        model: missionItem.checkboxFacts
177

178 179 180 181 182 183
                        FactCheckBox {
                            text:   object.name
                            fact:   object
                        }
                    }
                } // Column
Don Gagne's avatar
Don Gagne committed
184 185 186
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
187
} // Rectangle