ValuePageWidget.qml 13.4 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
import QtQuick          2.3
11
import QtQuick.Dialogs  1.2
12
import QtQuick.Layouts  1.2
13 14
import QtQuick.Controls 2.5
import QtQml            2.12
15 16 17 18

import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.FactSystem    1.0
19
import QGroundControl.FactControls  1.0
20 21 22 23
import QGroundControl.Controllers   1.0
import QGroundControl.Palette       1.0
import QGroundControl               1.0

24 25
/// Value page for InstrumentPanel PageView
Column {
26
    id:         _root
27
    width:      pageWidth
28
    spacing:    ScreenTools.defaultFontPixelHeight / 2
29

30
    property bool showSettingsIcon: true
31 32 33 34 35 36 37 38 39 40 41 42 43 44
    property bool showLockIcon:     true

    property var    _activeVehicle:                 QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle
    property real   _margins:                       ScreenTools.defaultFontPixelWidth / 2
    property int    _colMax:                        4
    property bool   _settingsUnlocked:              false
    property var    _valuePickerInstrumentValue:    null
    property int    _valuePickerRowIndex:           0
    property var    _rgFontSizes:                   [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ]
    property real   _blankEntryHeight:              ScreenTools.defaultFontPixelHeight * 2
    property real   _columnButtonWidth:             ScreenTools.minTouchPixels / 2
    property real   _columnButtonHeight:            ScreenTools.minTouchPixels
    property real   _columnButtonSpacing:           2
    property real   _columnButtonsTotalHeight:      (_columnButtonHeight * 2) + _columnButtonSpacing
45 46 47

    QGCPalette { id:qgcPal; colorGroupEnabled: true }

48
    ValuesWidgetController { id: controller }
49

50 51
    function showSettings(settingsUnlocked) {
        _settingsUnlocked = settingsUnlocked
52 53
    }

54 55 56 57 58 59 60 61 62
    function listContains(list, value) {
        for (var i=0; i<list.length; i++) {
            if (list[i] === value) {
                return true
            }
        }
        return false
    }

63
    ButtonGroup { id: factRadioGroup }
64

65
    Component {
66
        id: valueItemMouseAreaComponent
67

68 69 70 71 72 73 74 75 76 77 78 79 80
        MouseArea {
            anchors.centerIn:   parent
            width:              parent.width
            height:             _columnButtonsTotalHeight
            visible:            _settingsUnlocked

            property var instrumentValue
            property int rowIndex

            onClicked: {
                _valuePickerInstrumentValue = instrumentValue
                _valuePickerRowIndex = rowIndex
                mainWindow.showComponentDialog(valuePickerDialog, qsTr("Select Value"), mainWindow.showDialogDefaultWidth, StandardButton.Ok)
81 82 83 84
            }
        }
    }

85 86 87
    Repeater {
        id:     rowRepeater
        model:  controller.valuesModel
88 89

        Column {
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
            id:             rowRepeaterLayout
            spacing:        1

            property int rowIndex: index

            Row {
                id:         columnRow
                spacing:    1

                Repeater {
                    id:     columnRepeater
                    model:  object

                    property real _interColumnSpacing:  (columnRepeater.count - (_settingsUnlocked ? 0 : 1)) * columnRow.spacing
                    property real columnWidth:          (pageWidth - (_settingsUnlocked ? _columnButtonWidth : 0) - _interColumnSpacing) / columnRepeater.count

                    onItemAdded: valueItemMouseAreaComponent.createObject(item, { "instrumentValue": object.get(index), "rowIndex": index })

                    Item {
                        width:                  columnRepeater.columnWidth
                        height:                 value.y + value.height
                        anchors.verticalCenter: _settingsUnlocked ? parent.verticalCenter : undefined
                        anchors.bottom:         _settingsUnlocked ? undefined : parent.bottom

                        QGCLabel {
                            width:                  columnRepeater.columnWidth
                            height:                 _columnButtonsTotalHeight
                            font.pointSize:         ScreenTools.smallFontPointSize
                            text:                   _settingsUnlocked ? qsTr("BLANK") : ""
                            horizontalAlignment:    Text.AlignHCenter
                            verticalAlignment:      Text.AlignVCenter
                            visible:                !object.fact
                        }

                        QGCLabel {
                            id:                     label
                            width:                  columnRepeater.columnWidth
                            font.pointSize:         ScreenTools.smallFontPointSize
                            text:                   object.label.toUpperCase()
                            horizontalAlignment:    Text.AlignHCenter
                            visible:                object.fact && object.label
                        }

                        QGCLabel {
                            id:                     value
                            anchors.topMargin:      label.visible ? 2 : 0
                            anchors.top:            label.visible ? label.bottom : parent.top
                            width:                  columnRepeater.columnWidth
                            font.pointSize:         _rgFontSizes[object.fontSize]
                            text:                   visible ? (object.fact.enumOrValueString + (object.showUnits ? object.fact.units : "")) : ""
                            horizontalAlignment:    Text.AlignHCenter
                            visible:                object.fact
                        }
                    }
                } // Repeater - columns

                ColumnLayout {
                    id:                 columnsButtonsLayout
                    width:              _columnButtonWidth
                    spacing:            _columnButtonSpacing
                    visible:            _settingsUnlocked

                    QGCButton {
                        Layout.fillHeight:      true
                        Layout.minimumHeight:   ScreenTools.minTouchPixels
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("+")
                        onClicked:              controller.appendColumn(rowRepeaterLayout.rowIndex)
                    }

                    QGCButton {
                        Layout.fillHeight:      true
                        Layout.minimumHeight:   ScreenTools.minTouchPixels
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("-")
                        enabled:                index !== 0 || columnRepeater.count !== 1
                        onClicked:              controller.deleteLastColumn(rowRepeaterLayout.rowIndex)
                    }
                }
            } // RowLayout

            RowLayout {
                width:      parent.width
                height:             ScreenTools.defaultFontPixelWidth * 2
                spacing:            1
                visible:            _settingsUnlocked

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("+")
                    onClicked:          controller.insertRow(index)
                }

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("-")
                    enabled:            index !== 0
                    onClicked:          controller.deleteRow(index)
                }
191 192
            }
        }
193 194 195 196 197 198 199 200
    } // Repeater - rows

    QGCButton {
        anchors.left:   parent.left
        anchors.right:  parent.right
        text:           qsTr("Reset To Defaults")
        visible:        _settingsUnlocked
        onClicked:      controller.resetToDefaults()
201 202
    }

203
    Component {
204
        id: valuePickerDialog
205 206

        QGCViewDialog {
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
            function accept() {
                if (factRadioGroup.checkedButton) {
                    _valuePickerInstrumentValue.setFact(factRadioGroup.checkedButton.radioFactGroupName, factRadioGroup.checkedButton.radioFact.name, labelTextField.text, fontSizeCombo.currentIndex)
                } else {
                    _valuePickerInstrumentValue.clearFact()
                }

                hideDialog()
            }

            Connections {
                target: factRadioGroup
                onCheckedButtonChanged: labelTextField.text = factRadioGroup.checkedButton.radioFact.shortDescription
            }

            ButtonGroup { id: fontRadioGroup }
223

224 225
            QGCFlickable {
                anchors.fill:       parent
DonLakeFlyer's avatar
DonLakeFlyer committed
226
                contentHeight:      column.height
227
                flickableDirection: Flickable.VerticalFlick
Don Gagne's avatar
Don Gagne committed
228
                clip:               true
229

230
                ColumnLayout {
231 232 233 234 235
                    id:             column
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    spacing:        _margins

236 237 238 239 240 241 242 243 244 245 246
                    RowLayout {
                        Layout.fillWidth:   true
                        spacing:            ScreenTools.defaultFontPixelWidth

                        QGCLabel { text: qsTr("Label") }
                        QGCTextField {
                            id:                 labelTextField
                            Layout.fillWidth:   true
                            text:               _valuePickerInstrumentValue.label
                        }
                    }
247

248 249 250 251 252 253 254 255 256 257 258
                    RowLayout {
                        spacing: ScreenTools.defaultFontPixelWidth

                        QGCLabel { text: qsTr("Font Size (for whole row)") }
                        QGCComboBox {
                            id:             fontSizeCombo
                            model:          [ qsTr("Default"), qsTr("Small"), qsTr("Medium"), qsTr("Large") ]
                            currentIndex:   _valuePickerInstrumentValue.fontSize
                            sizeToContents: true
                            onActivated:    _valuePickerInstrumentValue.fontSize = index
                        }
259 260
                    }

261 262 263 264
                    QGCCheckBox {
                        text:       qsTr("Show Units")
                        checked:    _valuePickerInstrumentValue.showUnits
                        onClicked:  _valuePickerInstrumentValue.showUnits = checked
265 266
                    }

267 268 269
                    QGCButton {
                        text:       qsTr("Blank Entry")
                        onClicked:  { _valuePickerInstrumentValue.clearFact(); hideDialog() }
270 271 272
                    }

                    Loader {
273
                        Layout.fillWidth:   true
274 275
                        sourceComponent:    factGroupList

276
                        property var    factGroup:     _activeVehicle
277
                        property string factGroupName: "Vehicle"
DonLakeFlyer's avatar
DonLakeFlyer committed
278 279 280 281 282 283
                    }

                    Repeater {
                        model: _activeVehicle.factGroupNames

                        Loader {
284
                            Layout.fillWidth:   true
DonLakeFlyer's avatar
DonLakeFlyer committed
285 286 287 288 289
                            sourceComponent:    factGroupList

                            property var    factGroup:     _activeVehicle.getFactGroup(modelData)
                            property string factGroupName: modelData
                        }
290
                    }
291
                }
292 293 294 295 296 297 298 299 300 301 302 303
            }
        }
    }

    Component {
        id: factGroupList

        // You must push in the following properties from the Loader
        // property var factGroup
        // property string factGroupName

        Column {
DonLakeFlyer's avatar
DonLakeFlyer committed
304 305 306 307 308 309
            SectionHeader {
                id:             header
                anchors.left:   parent.left
                anchors.right:  parent.right
                text:           factGroupName.charAt(0).toUpperCase() + factGroupName.slice(1)
                checked:        false
310 311
            }

DonLakeFlyer's avatar
DonLakeFlyer committed
312
            Column {
313
                visible: header.checked
DonLakeFlyer's avatar
DonLakeFlyer committed
314 315 316

                Repeater {
                    model: factGroup ? factGroup.factNames : 0
317

318 319 320 321
                    QGCRadioButton {
                        text:               radioFact.shortDescription
                        ButtonGroup.group:  factRadioGroup
                        checked:            radioFactGroupName == _valuePickerInstrumentValue.factGroupName && radioFact == _valuePickerInstrumentValue.fact
322

323 324
                        property string radioFactGroupName: factGroupName
                        property var    radioFact:          factGroup.getFact(modelData)
325

326 327 328
                        Component.onCompleted: {
                            if (checked) {
                                header.checked = true
329
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
330
                        }
331 332 333 334 335 336
                    }
                }
            }
        }
    }
}