MissionItemEditor.qml 6.33 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: missionItem.isCurrentItem ?
23 24
                (missionItem.textFieldFacts.count * (measureTextField.height + _margin)) +
                    (missionItem.checkboxFacts.count * (measureCheckbox.height + _margin)) +
25
                    commandPicker.height + (deleteButton.visible ? deleteButton.height : 0) + (_margin * 9) :
26 27
                commandPicker.height + (_margin * 2)
    color:  missionItem.isCurrentItem ? qgcPal.buttonHighlight : qgcPal.windowShade
Don Gagne's avatar
Don Gagne committed
28

29
    readonly property real _editFieldWidth:     ScreenTools.defaultFontPixelWidth * 16
Don Gagne's avatar
Don Gagne committed
30
    readonly property real _margin:             ScreenTools.defaultFontPixelWidth / 3
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
    }

37 38 39 40 41 42 43 44 45 46
    QGCTextField {
        id:         measureTextField
        visible:    false
    }

    QGCCheckBox {
        id:         measureCheckbox
        visible:    false
    }

Don Gagne's avatar
Don Gagne committed
47 48 49
    Item {
        anchors.margins:    _margin
        anchors.fill:       parent
Don Gagne's avatar
Don Gagne committed
50

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

        MouseArea {
            anchors.fill:   parent
            visible:        !missionItem.isCurrentItem

            onClicked: _root.clicked()
Don Gagne's avatar
Don Gagne committed
63
        }
Don Gagne's avatar
Don Gagne committed
64

Don Gagne's avatar
Don Gagne committed
65 66
        QGCComboBox {
            id:                 commandPicker
67
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 10
Don Gagne's avatar
Don Gagne committed
68 69 70 71
            anchors.left:       label.right
            anchors.right:      parent.right
            currentIndex:       missionItem.commandByIndex
            model:              missionItem.commandNames
72
            visible:            missionItem.sequenceNumber != 0 // Item 0 is home position, can't change item type
Don Gagne's avatar
Don Gagne committed
73

Don Gagne's avatar
Don Gagne committed
74 75
            onActivated: missionItem.commandByIndex = index
        }
Don Gagne's avatar
Don Gagne committed
76

Don Gagne's avatar
Don Gagne committed
77 78 79
        Rectangle {
            anchors.fill:   commandPicker
            color:          qgcPal.button
80
            visible:        missionItem.sequenceNumber == 0 // Item 0 is home position, can't change item type
Don Gagne's avatar
Don Gagne committed
81 82 83 84 85 86 87 88 89 90 91

            QGCLabel {
                id:                 homeLabel
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth
                anchors.fill:       parent
                verticalAlignment:  Text.AlignVCenter
                text:               "Home"
                color:              qgcPal.buttonText
            }
        }

Don Gagne's avatar
Don Gagne committed
92
        Rectangle {
93
            anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
94 95 96 97 98
            anchors.top:        commandPicker.bottom
            anchors.bottom:     parent.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
            color:              qgcPal.windowShadeDark
99
            visible:            missionItem.isCurrentItem
Don Gagne's avatar
Don Gagne committed
100

Don Gagne's avatar
Don Gagne committed
101 102 103
            Item {
                anchors.margins:    _margin
                anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
104

Don Gagne's avatar
Don Gagne committed
105
                Column {
106 107 108 109 110
                    id:             valuesColumn
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    anchors.top:    parent.top
                    spacing:        _margin
Don Gagne's avatar
Don Gagne committed
111 112

                    Repeater {
113
                        model: missionItem.textFieldFacts
Don Gagne's avatar
Don Gagne committed
114 115

                        Item {
116
                            width:  valuesColumn.width
Don Gagne's avatar
Don Gagne committed
117 118 119
                            height: textField.height

                            QGCLabel {
120
                                id:                 textFieldLabel
Don Gagne's avatar
Don Gagne committed
121 122 123 124 125 126 127 128 129 130
                                anchors.baseline:   textField.baseline
                                text:               object.name
                            }

                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           object
131 132 133 134 135 136 137 138
                                visible:        !_root.readOnly
                            }

                            FactLabel {
                                anchors.baseline:   textFieldLabel.baseline
                                anchors.right:      parent.right
                                fact:               object
                                visible:            _root.readOnly
Don Gagne's avatar
Don Gagne committed
139 140 141
                            }
                        }
                    }
142

143 144 145 146
                    Item {
                        width:  10
                        height: missionItem.textFieldFacts.count ? _margin : 0
                    }
147

148 149
                    Repeater {
                        model: missionItem.checkboxFacts
150

151 152 153 154 155 156
                        FactCheckBox {
                            id:     textField
                            text:   object.name
                            fact:   object
                        }
                    }
157

158 159 160
                    Item {
                        width:  10
                        height: missionItem.checkboxFacts.count ? _margin : 0
161 162
                    }

163 164 165
                    Row {
                        width:      parent.width
                        spacing:    _margin
166

167 168 169
                        readonly property real buttonWidth: (width - (_margin * 2)) / 3

                        QGCButton {
170 171 172 173
                            id:         deleteButton
                            width:      parent.buttonWidth
                            text:       "Delete"
                            visible:    !readOnly
174 175 176

                            onClicked: _root.remove()
                        }
177
                    }
178 179

                } // Column
Don Gagne's avatar
Don Gagne committed
180 181 182
            } // Item
        } // Rectangle
    } // Item
Don Gagne's avatar
Don Gagne committed
183
} // Rectangle