ValuePageWidget.qml 35 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

DonLakeFlyer's avatar
DonLakeFlyer committed
10
import QtQuick          2.12
11
import QtQuick.Dialogs  1.3
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
    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
37
    property var    instrumentValue:    null
38
    property var    _rgFontSizes:                   [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ]
39 40 41 42
    property var    _rgFontSizeRatios:              [ 1, ScreenTools.smallFontPointRatio, ScreenTools.mediumFontPointRatio, ScreenTools.largeFontPointRatio ]
    property real   _doubleDescent:                 ScreenTools.defaultFontDescent * 2
    property real   _tightDefaultFontHeight:        ScreenTools.defaultFontPixelHeight - _doubleDescent
    property var    _rgFontSizeTightHeights:        [ _tightDefaultFontHeight * _rgFontSizeRatios[0] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[1] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[2] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[3] + 2 ]
43 44 45 46 47
    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
48 49

    QGCPalette { id:qgcPal; colorGroupEnabled: true }
50
    QGCPalette { id:qgcPalDisabled; colorGroupEnabled: false }
51

52
    ValuesWidgetController { id: controller }
53

54 55
    function showSettings(settingsUnlocked) {
        _settingsUnlocked = settingsUnlocked
56 57
    }

58 59 60 61 62 63 64 65 66
    function listContains(list, value) {
        for (var i=0; i<list.length; i++) {
            if (list[i] === value) {
                return true
            }
        }
        return false
    }

67
    ButtonGroup { id: factRadioGroup }
68

69
    Component {
70
        id: valueItemMouseAreaComponent
71

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

            property var instrumentValue
            property int rowIndex

            onClicked: {
82 83
                instrumentValue = instrumentValue
                mainWindow.showPopupDialog(valueDialogComponent, { instrumentValue: instrumentValue })
84 85 86 87
            }
        }
    }

88 89 90
    Repeater {
        id:     rowRepeater
        model:  controller.valuesModel
91 92

        Column {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
            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
108
                    property bool componentCompleted:   false
109

110
                    Component.onCompleted: componentCompleted = true
111 112 113
                    onItemAdded: valueItemMouseAreaComponent.createObject(item, { "instrumentValue": object.get(index), "rowIndex": index })

                    Item {
114 115
                        id:                     columnItem
                        anchors.verticalCenter: parent.verticalCenter
116 117
                        width:                  columnRepeater.columnWidth
                        height:                 value.y + value.height
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

                        property real columnWidth:                  columnRepeater.columnWidth
                        property bool repeaterComponentCompleted:   columnRepeater.componentCompleted

                        // After fighting with using layout and/or anchors I gave up and just do a manual recalc to position items which ends up being much simpler
                        function recalcPositions() {
                            if (!repeaterComponentCompleted) {
                                return
                            }
                            var smallSpacing = 2
                            if (object.icon) {
                                if (object.iconPosition === InstrumentValue.IconAbove) {
                                    valueIcon.x = (width - valueIcon.width) / 2
                                    valueIcon.y = 0
                                    value.x = (width - value.width) / 2
                                    value.y = valueIcon.height + smallSpacing
                                } else {
                                    var iconPlusValueWidth = valueIcon.width + value.width + ScreenTools.defaultFontPixelWidth
                                    valueIcon.x = (width - iconPlusValueWidth) / 2
                                    valueIcon.y = (value.height - valueIcon.height) / 2
                                    value.x = valueIcon.x + valueIcon.width + (ScreenTools.defaultFontPixelWidth / 2)
                                    value.y = 0
                                }
                                label.x = label.y = 0
                            } else {
                                // label above value
144
                                if (object.label) {
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
                                    label.x = (width - label.width) / 2
                                    label.y = 0
                                    value.y = label.height + smallSpacing
                                } else {
                                    value.y = 0
                                }
                                value.x = (width - value.width) / 2
                                valueIcon.x = valueIcon.y = 0
                            }
                        }

                        onRepeaterComponentCompletedChanged:    recalcPositions()
                        onColumnWidthChanged:                   recalcPositions()

                        Connections {
                            target:                 object
                            onIconChanged:          recalcPositions()
                            onIconPositionChanged:  recalcPositions()
                        }

                        QGCColoredImage {
                            id:                         valueIcon
                            height:                     _rgFontSizeTightHeights[object.fontSize]
                            width:                      height
169
                            source:                     icon
170 171 172 173
                            sourceSize.height:          height
                            fillMode:                   Image.PreserveAspectFit
                            mipmap:                     true
                            smooth:                     true
174 175
                            color:                      object.isValidColor(object.currentColor) ? object.currentColor : qgcPal.text
                            opacity:                    object.currentOpacity
176 177 178
                            visible:                    object.icon
                            onWidthChanged:             columnItem.recalcPositions()
                            onHeightChanged:            columnItem.recalcPositions()
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

                            property string icon
                            readonly property string iconPrefix: "/InstrumentValueIcons/"

                            function updateIcon() {
                                if (object.rangeType == InstrumentValue.IconSelectRange) {
                                    icon = iconPrefix + object.currentIcon
                                } else if (object.icon) {
                                    icon = iconPrefix + object.icon
                                } else {
                                    icon = ""
                                }
                            }

                            Connections {
                                target:                 object
                                onRangeTypeChanged:     valueIcon.updateIcon()
                                onCurrentIconChanged:   valueIcon.updateIcon()
                                onIconChanged:          valueIcon.updateIcon()
                            }
                            Component.onCompleted:      updateIcon();
200
                        }
201 202

                        QGCLabel {
203
                            id:                         blank
204 205 206 207 208 209 210
                            anchors.horizontalCenter:   parent.horizontalCenter
                            height:                     _columnButtonsTotalHeight
                            font.pointSize:             ScreenTools.smallFontPointSize
                            text:                       _settingsUnlocked ? qsTr("BLANK") : ""
                            horizontalAlignment:        Text.AlignHCenter
                            verticalAlignment:          Text.AlignVCenter
                            visible:                    !object.fact
211 212
                            onWidthChanged:             columnItem.recalcPositions()
                            onHeightChanged:            columnItem.recalcPositions()
213 214 215
                        }

                        QGCLabel {
216
                            id:                         label
217
                            height:                     _rgFontSizeTightHeights[InstrumentValue.SmallFontSize]
218 219
                            font.pointSize:             ScreenTools.smallFontPointSize
                            text:                       object.label.toUpperCase()
220 221 222 223
                            verticalAlignment:          Text.AlignVCenter
                            visible:                    object.fact && object.label && !object.icon
                            onWidthChanged:             columnItem.recalcPositions()
                            onHeightChanged:            columnItem.recalcPositions()
224 225 226
                        }

                        QGCLabel {
227 228 229
                            id:                         value
                            font.pointSize:             _rgFontSizes[object.fontSize]
                            text:                       visible ? (object.fact.enumOrValueString + (object.showUnits ? object.fact.units : "")) : ""
230
                            verticalAlignment:          Text.AlignVCenter
231
                            visible:                    object.fact
232 233
                            onWidthChanged:             columnItem.recalcPositions()
                            onHeightChanged:            columnItem.recalcPositions()
234 235 236 237 238 239 240 241 242 243 244 245
                        }
                    }
                } // Repeater - columns

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

                    QGCButton {
                        Layout.fillHeight:      true
246
                        Layout.preferredHeight: ScreenTools.minTouchPixels
247 248 249 250 251 252 253
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("+")
                        onClicked:              controller.appendColumn(rowRepeaterLayout.rowIndex)
                    }

                    QGCButton {
                        Layout.fillHeight:      true
254
                        Layout.preferredHeight: ScreenTools.minTouchPixels
255 256 257 258 259 260 261 262 263 264
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("-")
                        enabled:                index !== 0 || columnRepeater.count !== 1
                        onClicked:              controller.deleteLastColumn(rowRepeaterLayout.rowIndex)
                    }
                }
            } // RowLayout

            RowLayout {
                width:      parent.width
265 266 267
                height:     ScreenTools.defaultFontPixelWidth * 2
                spacing:    1
                visible:    _settingsUnlocked
268 269 270 271 272

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("+")
273
                    onClicked:          controller.insertRow(index + 1)
274 275 276 277 278 279 280 281 282
                }

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("-")
                    enabled:            index !== 0
                    onClicked:          controller.deleteRow(index)
                }
283 284
            }
        }
285 286 287 288 289 290 291 292
    } // Repeater - rows

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

295
    Component {
296
        id: valueDialogComponent
297 298

        QGCPopupDialog {
299 300 301 302 303 304
            id:         valueDisplayDialog
            title:      qsTr("Value Display")
            buttons:    StandardButton.Close

            property var instrumentValue: dialogProperties.instrumentValue

305 306 307 308 309 310 311 312
            GridLayout {
                rowSpacing:     _margins
                columnSpacing:  _margins
                columns:        3

                QGCCheckBox {
                    id:         valueCheckBox
                    text:       qsTr("Value")
313
                    checked:    instrumentValue.fact
314 315
                    onClicked: {
                        if (checked) {
316
                            instrumentValue.setFact(instrumentValue.factGroupNames[0], instrumentValue.factValueNames[0])
317
                        } else {
318
                            instrumentValue.clearFact()
319 320
                        }
                    }
321
                }
322

323
                QGCComboBox {
324
                    model:                  instrumentValue.factGroupNames
325 326
                    sizeToContents:         true
                    enabled:                valueCheckBox.enabled
327 328
                    onModelChanged:         currentIndex = find(instrumentValue.factGroupName)
                    Component.onCompleted:  currentIndex = find(instrumentValue.factGroupName)
329
                    onActivated: {
330 331 332
                        instrumentValue.setFact(currentText, "")
                        instrumentValue.icon = ""
                        instrumentValue.label = instrumentValue.fact.shortDescription
333
                    }
334
                }
335

336
                QGCComboBox {
337
                    model:                  instrumentValue.factValueNames
338 339
                    sizeToContents:         true
                    enabled:                valueCheckBox.enabled
340 341
                    onModelChanged:         currentIndex = instrumentValue.fact ? find(instrumentValue.factName) : -1
                    Component.onCompleted:  currentIndex = instrumentValue.fact ? find(instrumentValue.factName) : -1
342
                    onActivated: {
343 344 345
                        instrumentValue.setFact(instrumentValue.factGroupName, currentText)
                        instrumentValue.icon = ""
                        instrumentValue.label = instrumentValue.fact.shortDescription
346
                    }
347
                }
348

349 350 351
                QGCRadioButton {
                    id:                     iconCheckBox
                    text:                   qsTr("Icon")
352
                    Component.onCompleted:  checked = instrumentValue.icon != ""
353
                    onClicked: {
354 355 356 357
                        instrumentValue.label = ""
                        instrumentValue.icon = instrumentValue.iconNames[0]
                        var updateFunction = function(icon){ instrumentValue.icon = icon }
                        mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValue.iconNames, icon: instrumentValue.icon, updateIconFunction: updateFunction })
358
                    }
359
                }
360

361 362 363 364
                QGCColoredImage {
                    Layout.alignment:   Qt.AlignHCenter
                    height:             iconPositionCombo.height
                    width:              height
365
                    source:             "/InstrumentValueIcons/" + (instrumentValue.icon ? instrumentValue.icon : instrumentValue.iconNames[0])
366 367 368 369 370 371 372 373 374
                    sourceSize.height:  height
                    fillMode:           Image.PreserveAspectFit
                    mipmap:             true
                    smooth:             true
                    color:              enabled ? qgcPal.text : qgcPalDisabled.text
                    enabled:            iconCheckBox.checked

                    MouseArea {
                        anchors.fill:   parent
375
                        onClicked: {
376 377
                            var updateFunction = function(icon){ instrumentValue.icon = icon }
                            mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValue.iconNames, icon: instrumentValue.icon, updateIconFunction: updateFunction })
378
                        }
DonLakeFlyer's avatar
DonLakeFlyer committed
379
                    }
380
                }
DonLakeFlyer's avatar
DonLakeFlyer committed
381

382 383
                QGCComboBox {
                    id:             iconPositionCombo
384 385
                    model:          instrumentValue.iconPositionNames
                    currentIndex:   instrumentValue.iconPosition
386
                    sizeToContents: true
387
                    onActivated:    instrumentValue.iconPosition = index
388 389
                    enabled:        iconCheckBox.checked
                }
DonLakeFlyer's avatar
DonLakeFlyer committed
390

391 392 393
                QGCRadioButton {
                    id:                     labelCheckBox
                    text:                   qsTr("Label")
394
                    Component.onCompleted:  checked = instrumentValue.label != ""
395
                    onClicked: {
396 397
                        instrumentValue.icon = ""
                        instrumentValue.label = instrumentValue.fact ? instrumentValue.fact.shortDescription : qsTr("Label")
398
                    }
399
                }
400

401 402 403 404
                QGCTextField {
                    id:                 labelTextField
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
405
                    text:               instrumentValue.label
406
                    enabled:            labelCheckBox.checked
DonLakeFlyer's avatar
DonLakeFlyer committed
407 408
                }

409 410 411 412
                QGCLabel { text: qsTr("Size") }

                QGCComboBox {
                    id:                 fontSizeCombo
413 414
                    model:              instrumentValue.fontSizeNames
                    currentIndex:       instrumentValue.fontSize
415
                    sizeToContents:     true
416
                    onActivated:        instrumentValue.fontSize = index
DonLakeFlyer's avatar
DonLakeFlyer committed
417 418
                }

419 420
                QGCCheckBox {
                    text:               qsTr("Show Units")
421 422
                    checked:            instrumentValue.showUnits
                    onClicked:          instrumentValue.showUnits = checked
DonLakeFlyer's avatar
DonLakeFlyer committed
423
                }
424 425 426 427 428 429

                QGCLabel { text: qsTr("Range") }

                QGCComboBox {
                    id:                 rangeTypeCombo
                    Layout.columnSpan:  2
430 431
                    model:              instrumentValue.rangeTypeNames
                    currentIndex:       instrumentValue.rangeType
432
                    sizeToContents:     true
433
                    onActivated:        instrumentValue.rangeType = index
434 435 436 437 438 439 440 441 442
                }

                Loader {
                    id:                     rangeLoader
                    Layout.columnSpan:      3
                    Layout.fillWidth:       true
                    Layout.preferredWidth:  item ? item.width : 0
                    Layout.preferredHeight: item ? item.height : 0

443 444
                    property var instrumentValue: valueDisplayDialog.instrumentValue

445
                    function updateSourceComponent() {
446
                        switch (instrumentValue.rangeType) {
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
                        case InstrumentValue.NoRangeInfo:
                            sourceComponent = undefined
                            break
                        case InstrumentValue.ColorRange:
                            sourceComponent = colorRangeDialog
                            break
                        case InstrumentValue.OpacityRange:
                            sourceComponent = opacityRangeDialog
                            break
                        case InstrumentValue.IconSelectRange:
                            sourceComponent = iconRangeDialog
                            break
                        }
                    }

                    Component.onCompleted: updateSourceComponent()

                    Connections {
465
                        target:             instrumentValue
466 467 468 469
                        onRangeTypeChanged: rangeLoader.updateSourceComponent()
                    }

                }
DonLakeFlyer's avatar
DonLakeFlyer committed
470 471 472 473
            }
        }
    }

474
    Component {
475
        id: iconPickerDialog
476

477
        QGCPopupDialog {
478 479 480 481 482 483
            property var     iconNames:             dialogProperties.iconNames
            property string  icon:                  dialogProperties.icon
            property var     updateIconFunction:    dialogProperties.updateIconFunction

            title:      qsTr("Select Icon")
            buttons:    StandardButton.Close
484

485 486 487 488
            GridLayout {
                columns:        10
                columnSpacing:  0
                rowSpacing:     0
DonLakeFlyer's avatar
DonLakeFlyer committed
489 490

                Repeater {
491
                    model: iconNames
492

493 494 495 496
                    Rectangle {
                        height: ScreenTools.minTouchPixels
                        width:  height
                        color:  currentSelection ? qgcPal.text  : qgcPal.window
497

498
                        property bool currentSelection: icon == modelData
499

500 501 502 503 504 505 506 507 508 509 510 511 512 513
                        QGCColoredImage {
                            anchors.centerIn:   parent
                            height:             parent.height * 0.75
                            width:              height
                            source:             "/InstrumentValueIcons/" + modelData
                            sourceSize.height:  height
                            fillMode:           Image.PreserveAspectFit
                            mipmap:             true
                            smooth:             true
                            color:              currentSelection ? qgcPal.window : qgcPal.text

                            MouseArea {
                                anchors.fill:   parent
                                onClicked:  {
514 515
                                    icon = modelData
                                    updateIconFunction(modelData)
516 517
                                    hideDialog()
                                }
518
                            }
DonLakeFlyer's avatar
DonLakeFlyer committed
519
                        }
520 521 522 523 524
                    }
                }
            }
        }
    }
525 526 527 528 529 530 531 532 533

    Component {
        id: colorRangeDialog

        Item {
            width:  childrenRect.width
            height: childrenRect.height

            function updateRangeValue(index, text) {
534
                var newValues = instrumentValue.rangeValues
535
                newValues[index] = parseFloat(text)
536
                instrumentValue.rangeValues = newValues
537 538 539
            }

            function updateColorValue(index, color) {
540
                var newColors = instrumentValue.rangeColors
541
                newColors[index] = color
542
                instrumentValue.rangeColors = newColors
543 544 545 546 547
            }

            ColorDialog {
                id:             colorPickerDialog
                modality:       Qt.ApplicationModal
548
                currentColor:   instrumentValue.rangeColors.length ? instrumentValue.rangeColors[colorIndex] : "white"
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
                onAccepted:     updateColorValue(colorIndex, color)

                property int colorIndex: 0
            }

            Column {
                id:         mainColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2

                QGCLabel {
                    width:      rowLayout.width
                    text:       qsTr("Specify the color you want to apply based on value ranges. The color will be applied to the icon if available, otherwise to the value itself.")
                    wrapMode:   Text.WordWrap
                }

                Row {
                    id:         rowLayout
                    spacing:    _margins

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
573
                            model: instrumentValue.rangeValues.length
574 575 576 577 578

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
579
                                onClicked:  instrumentValue.removeRangeValue(index)
580 581 582 583 584 585 586 587 588
                            }
                        }
                    }

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
589
                            model: instrumentValue.rangeValues.length
590 591

                            QGCTextField {
592
                                text:               instrumentValue.rangeValues[index]
593 594 595 596 597 598 599 600
                                onEditingFinished:  updateRangeValue(index, text)
                            }
                        }
                    }

                    Column {
                        spacing: _margins
                        Repeater {
601
                            model: instrumentValue.rangeColors
602 603 604

                            QGCCheckBox {
                                height:     ScreenTools.implicitTextFieldHeight
605 606
                                checked:    instrumentValue.isValidColor(instrumentValue.rangeColors[index])
                                onClicked:  updateColorValue(index, checked ? "green" : instrumentValue.invalidColor())
607 608 609 610 611 612 613
                            }
                        }
                    }

                    Column {
                        spacing: _margins
                        Repeater {
614
                            model: instrumentValue.rangeColors
615 616 617 618 619

                            Rectangle {
                                width:          ScreenTools.implicitTextFieldHeight
                                height:         width
                                border.color:   qgcPal.text
620
                                color:          instrumentValue.isValidColor(modelData) ? modelData : qgcPal.text
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635

                                MouseArea {
                                    anchors.fill: parent
                                    onClicked: {
                                        colorPickerDialog.colorIndex = index
                                        colorPickerDialog.open()
                                    }
                                }
                            }
                        }
                    }
                }

                QGCButton {
                    text:       qsTr("Add Row")
636
                    onClicked:  instrumentValue.addRangeValue()
637 638 639 640 641 642 643 644 645 646 647 648 649
                }
            }
        }
    }

    Component {
        id: iconRangeDialog

        Item {
            width:  childrenRect.width
            height: childrenRect.height

            function updateRangeValue(index, text) {
650
                var newValues = instrumentValue.rangeValues
651
                newValues[index] = parseFloat(text)
652
                instrumentValue.rangeValues = newValues
653 654 655
            }

            function updateIconValue(index, icon) {
656
                var newIcons = instrumentValue.rangeIcons
657
                newIcons[index] = icon
658
                instrumentValue.rangeIcons = newIcons
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
            }

            Column {
                id:         mainColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2

                QGCLabel {
                    width:      rowLayout.width
                    text:       qsTr("Specify the icon you want to display based on value ranges.")
                    wrapMode:   Text.WordWrap
                }

                Row {
                    id:         rowLayout
                    spacing:    _margins

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
680
                            model: instrumentValue.rangeValues.length
681 682 683 684 685

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
686
                                onClicked:  instrumentValue.removeRangeValue(index)
687 688 689 690 691 692 693 694 695
                            }
                        }
                    }

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
696
                            model: instrumentValue.rangeValues.length
697 698

                            QGCTextField {
699
                                text:               instrumentValue.rangeValues[index]
700 701 702 703 704 705 706 707 708
                                onEditingFinished:  updateRangeValue(index, text)
                            }
                        }
                    }

                    Column {
                        spacing: _margins

                        Repeater {
709
                            model: instrumentValue.rangeIcons
710 711 712 713 714 715 716 717 718 719 720 721 722 723

                            QGCColoredImage {
                                height:             ScreenTools.implicitTextFieldHeight
                                width:              height
                                source:             "/InstrumentValueIcons/" + modelData
                                sourceSize.height:  height
                                fillMode:           Image.PreserveAspectFit
                                mipmap:             true
                                smooth:             true
                                color:              qgcPal.text

                                MouseArea {
                                    anchors.fill:   parent
                                    onClicked: {
724 725
                                        var updateFunction = function(icon){ updateIconValue(index, icon) }
                                        mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValue.iconNames, icon: modelData, updateIconFunction = updateFunction })
726 727 728 729 730 731 732 733 734
                                    }
                                }
                            }
                        }
                    }
                }

                QGCButton {
                    text:       qsTr("Add Row")
735
                    onClicked:  instrumentValue.addRangeValue()
736 737 738 739 740 741 742 743 744 745 746 747 748
                }
            }
        }
    }

    Component {
        id: opacityRangeDialog

        Item {
            width:  childrenRect.width
            height: childrenRect.height

            function updateRangeValue(index, text) {
749
                var newValues = instrumentValue.rangeValues
750
                newValues[index] = parseFloat(text)
751
                instrumentValue.rangeValues = newValues
752 753 754
            }

            function updateOpacityValue(index, opacity) {
755
                var newOpacities = instrumentValue.rangeOpacities
756
                newOpacities[index] = opacity
757
                instrumentValue.rangeOpacities = newOpacities
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
            }

            Column {
                id:         mainColumn
                spacing:    ScreenTools.defaultFontPixelHeight / 2

                QGCLabel {
                    width:      rowLayout.width
                    text:       qsTr("Specify the icon opacity you want based on value ranges.")
                    wrapMode:   Text.WordWrap
                }

                Row {
                    id:         rowLayout
                    spacing:    _margins

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
779
                            model: instrumentValue.rangeValues.length
780 781 782 783 784

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
785
                                onClicked:  instrumentValue.removeRangeValue(index)
786 787 788 789 790 791 792 793 794
                            }
                        }
                    }

                    Column {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing:                _margins

                        Repeater {
795
                            model: instrumentValue.rangeValues
796 797 798 799 800 801 802 803 804 805 806 807

                            QGCTextField {
                                text:               modelData
                                onEditingFinished:  updateRangeValue(index, text)
                            }
                        }
                    }

                    Column {
                        spacing: _margins

                        Repeater {
808
                            model: instrumentValue.rangeOpacities
809 810 811 812 813 814 815 816 817 818 819

                            QGCTextField {
                                text:               modelData
                                onEditingFinished:  updateOpacityValue(index, text)
                            }
                        }
                    }
                }

                QGCButton {
                    text:       qsTr("Add Row")
820
                    onClicked:  instrumentValue.addRangeValue()
821 822 823 824
                }
            }
        }
    }
825
}