InstrumentValueEditDialog.qml 21.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick          2.12
import QtQuick.Dialogs  1.3
import QtQuick.Layouts  1.2
import QtQuick.Controls 2.5

15
import QGroundControl               1.0
16 17 18 19 20 21 22 23 24 25 26 27
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Controllers   1.0
import QGroundControl.Palette       1.0

QGCPopupDialog {
    id:         root
    title:      qsTr("Value Display")
    buttons:    StandardButton.Close

28 29 30 31
    property var instrumentValueData: dialogProperties.instrumentValueData

    QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled }
    QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false }
32 33 34 35 36 37 38 39 40

    GridLayout {
        rowSpacing:     _margins
        columnSpacing:  _margins
        columns:        3

        QGCCheckBox {
            id:         valueCheckBox
            text:       qsTr("Value")
41
            checked:    instrumentValueData.fact
42 43
            onClicked: {
                if (checked) {
44
                    instrumentValueData.setFact(instrumentValueData.factGroupNames[0], instrumentValueData.factValueNames[0])
45
                } else {
46
                    instrumentValueData.clearFact()
47 48 49 50 51
                }
            }
        }

        QGCComboBox {
52 53 54
            id:                     factGroupCombo
            Layout.fillWidth:       true
            model:                  instrumentValueData.factGroupNames
55
            sizeToContents:         true
56 57
            enabled:                valueCheckBox.checked
            Component.onCompleted:  currentIndex = find(instrumentValueData.factGroupName)
58
            onActivated: {
59 60 61 62 63 64 65
                instrumentValueData.setFact(currentText, "")
                instrumentValueData.icon = ""
                instrumentValueData.text = instrumentValueData.fact.shortDescription
            }
            Connections {
                target: instrumentValueData
                onFactGroupNameChanged: factGroupCombo.currentIndex = factGroupCombo.find(instrumentValueData.factGroupName)
66 67 68 69
            }
        }

        QGCComboBox {
70 71 72
            id:                     factNamesCombo
            Layout.fillWidth:       true
            model:                  instrumentValueData.factValueNames
73
            sizeToContents:         true
74 75
            enabled:                valueCheckBox.checked
            Component.onCompleted:  currentIndex = find(instrumentValueData.factName)
76
            onActivated: {
77 78 79 80 81 82 83
                instrumentValueData.setFact(instrumentValueData.factGroupName, currentText)
                instrumentValueData.icon = ""
                instrumentValueData.text = instrumentValueData.fact.shortDescription
            }
            Connections {
                target: instrumentValueData
                onFactNameChanged: factNamesCombo.currentIndex = factNamesCombo.find(instrumentValueData.factName)
84 85 86 87
            }
        }

        QGCRadioButton {
88
            id:                     iconRadio
89
            text:                   qsTr("Icon")
90
            Component.onCompleted:  checked = instrumentValueData.icon != ""
91
            onClicked: {
92 93 94 95
                instrumentValueData.text = ""
                instrumentValueData.icon = instrumentValueData.iconNames[0]
                var updateFunction = function(icon){ instrumentValueData.icon = icon }
                mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValueData.instrumentValueArea.iconNames, icon: instrumentValueData.icon, updateIconFunction: updateFunction })
96 97 98 99 100
            }
        }

        QGCColoredImage {
            Layout.alignment:   Qt.AlignHCenter
101
            height:             ScreenTools.implicitComboBoxHeight
102
            width:              height
103
            source:             "/InstrumentValueIcons/" + (instrumentValueData.icon ? instrumentValueData.icon : instrumentValueData.instrumentValueArea.iconNames[0])
104 105 106 107 108
            sourceSize.height:  height
            fillMode:           Image.PreserveAspectFit
            mipmap:             true
            smooth:             true
            color:              enabled ? qgcPal.text : qgcPalDisabled.text
109
            enabled:            iconRadio.checked
110 111 112 113

            MouseArea {
                anchors.fill:   parent
                onClicked: {
114 115
                    var updateFunction = function(icon){ instrumentValueData.icon = icon }
                    mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValueData.instrumentValueArea.iconNames, icon: instrumentValueData.icon, updateIconFunction: updateFunction })
116 117 118 119
                }
            }
        }

120
        Item { height: 1; width: 1 }
121 122

        QGCRadioButton {
123
            id:                     textRadio
124
            text:                   qsTr("Text")
125
            Component.onCompleted:  checked = instrumentValueData.icon == ""
126
            onClicked: {
127 128
                instrumentValueData.icon = ""
                instrumentValueData.text = instrumentValueData.fact ? instrumentValueData.fact.shortDescription : qsTr("Label")
129 130 131 132
            }
        }

        QGCTextField {
133 134 135 136 137 138 139
            id:                     labelTextField
            Layout.fillWidth:       true
            Layout.columnSpan:      2
            Layout.preferredWidth:  ScreenTools.defaultFontPixelWidth * 10
            text:                   instrumentValueData.text
            enabled:                textRadio.checked
            onEditingFinished:      instrumentValueData.text = text
140 141 142 143 144 145
        }

        QGCLabel { text: qsTr("Size") }

        QGCComboBox {
            id:                 fontSizeCombo
146 147 148
            Layout.fillWidth:   true
            model:              instrumentValueData.instrumentValueArea.fontSizeNames
            currentIndex:       instrumentValueData.instrumentValueArea.fontSize
149
            sizeToContents:     true
150
            onActivated:        instrumentValueData.instrumentValueArea.fontSize = index
151 152 153 154
        }

        QGCCheckBox {
            text:               qsTr("Show Units")
155 156
            checked:            instrumentValueData.showUnits
            onClicked:          instrumentValueData.showUnits = checked
157 158 159 160 161 162 163
        }

        QGCLabel { text: qsTr("Range") }

        QGCComboBox {
            id:                 rangeTypeCombo
            Layout.columnSpan:  2
164 165 166
            Layout.fillWidth:   true
            model:              instrumentValueData.rangeTypeNames
            currentIndex:       instrumentValueData.rangeType
167
            sizeToContents:     true
168
            onActivated:        instrumentValueData.rangeType = index
169 170 171 172 173 174 175 176 177
        }

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

178
            property var instrumentValueData: root.instrumentValueData
179 180

            function updateSourceComponent() {
181 182
                switch (instrumentValueData.rangeType) {
                case InstrumentValueData.NoRangeInfo:
183 184
                    sourceComponent = undefined
                    break
185
                case InstrumentValueData.ColorRange:
186 187
                    sourceComponent = colorRangeDialog
                    break
188
                case InstrumentValueData.OpacityRange:
189 190
                    sourceComponent = opacityRangeDialog
                    break
191
                case InstrumentValueData.IconSelectRange:
192 193 194 195 196 197 198 199
                    sourceComponent = iconRangeDialog
                    break
                }
            }

            Component.onCompleted: updateSourceComponent()

            Connections {
200
                target:             instrumentValueData
201 202 203 204 205 206 207 208 209 210 211 212 213 214
                onRangeTypeChanged: rangeLoader.updateSourceComponent()
            }

        }
    }

    Component {
        id: colorRangeDialog

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

            function updateRangeValue(index, text) {
215
                var newValues = instrumentValueData.rangeValues
216
                newValues[index] = parseFloat(text)
217
                instrumentValueData.rangeValues = newValues
218 219 220
            }

            function updateColorValue(index, color) {
221
                var newColors = instrumentValueData.rangeColors
222
                newColors[index] = color
223
                instrumentValueData.rangeColors = newColors
224 225 226 227 228
            }

            ColorDialog {
                id:             colorPickerDialog
                modality:       Qt.ApplicationModal
229
                currentColor:   instrumentValueData.rangeColors.length ? instrumentValueData.rangeColors[colorIndex] : "white"
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
                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 {
254
                            model: instrumentValueData.rangeValues.length
255 256 257 258 259

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
260
                                onClicked:  instrumentValueData.removeRangeValue(index)
261 262 263 264 265 266 267 268 269
                            }
                        }
                    }

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

                        Repeater {
270
                            model: instrumentValueData.rangeValues.length
271 272

                            QGCTextField {
273
                                text:               instrumentValueData.rangeValues[index]
274 275 276 277 278 279 280 281
                                onEditingFinished:  updateRangeValue(index, text)
                            }
                        }
                    }

                    Column {
                        spacing: _margins
                        Repeater {
282
                            model: instrumentValueData.rangeColors
283 284 285

                            QGCCheckBox {
                                height:     ScreenTools.implicitTextFieldHeight
286 287
                                checked:    instrumentValueData.isValidColor(instrumentValueData.rangeColors[index])
                                onClicked:  updateColorValue(index, checked ? "green" : instrumentValueData.invalidColor())
288 289 290 291 292 293 294
                            }
                        }
                    }

                    Column {
                        spacing: _margins
                        Repeater {
295
                            model: instrumentValueData.rangeColors
296 297 298 299 300

                            Rectangle {
                                width:          ScreenTools.implicitTextFieldHeight
                                height:         width
                                border.color:   qgcPal.text
301
                                color:          instrumentValueData.isValidColor(modelData) ? modelData : qgcPal.text
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316

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

                QGCButton {
                    text:       qsTr("Add Row")
317
                    onClicked:  instrumentValueData.addRangeValue()
318 319 320 321 322 323 324 325 326 327 328 329 330
                }
            }
        }
    }

    Component {
        id: iconRangeDialog

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

            function updateRangeValue(index, text) {
331
                var newValues = instrumentValueData.rangeValues
332
                newValues[index] = parseFloat(text)
333
                instrumentValueData.rangeValues = newValues
334 335 336
            }

            function updateIconValue(index, icon) {
337
                var newIcons = instrumentValueData.rangeIcons
338
                newIcons[index] = icon
339
                instrumentValueData.rangeIcons = newIcons
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
            }

            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 {
361
                            model: instrumentValueData.rangeValues.length
362 363 364 365 366

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
367
                                onClicked:  instrumentValueData.removeRangeValue(index)
368 369 370 371 372 373 374 375 376
                            }
                        }
                    }

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

                        Repeater {
377
                            model: instrumentValueData.rangeValues.length
378 379

                            QGCTextField {
380
                                text:               instrumentValueData.rangeValues[index]
381 382 383 384 385 386 387 388 389
                                onEditingFinished:  updateRangeValue(index, text)
                            }
                        }
                    }

                    Column {
                        spacing: _margins

                        Repeater {
390
                            model: instrumentValueData.rangeIcons
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405

                            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: {
                                        var updateFunction = function(icon){ updateIconValue(index, icon) }
406
                                        mainWindow.showPopupDialog(iconPickerDialog, { iconNames: instrumentValueData.instrumentValueArea.iconNames, icon: modelData, updateIconFunction: updateFunction })
407 408 409 410 411 412 413 414 415
                                    }
                                }
                            }
                        }
                    }
                }

                QGCButton {
                    text:       qsTr("Add Row")
416
                    onClicked:  instrumentValueData.addRangeValue()
417 418 419 420 421 422 423 424 425 426 427 428 429
                }
            }
        }
    }

    Component {
        id: opacityRangeDialog

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

            function updateRangeValue(index, text) {
430
                var newValues = instrumentValueData.rangeValues
431
                newValues[index] = parseFloat(text)
432
                instrumentValueData.rangeValues = newValues
433 434 435
            }

            function updateOpacityValue(index, opacity) {
436
                var newOpacities = instrumentValueData.rangeOpacities
437
                newOpacities[index] = opacity
438
                instrumentValueData.rangeOpacities = newOpacities
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
            }

            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 {
460
                            model: instrumentValueData.rangeValues.length
461 462 463 464 465

                            QGCButton {
                                width:      ScreenTools.implicitTextFieldHeight
                                height:     width
                                text:       qsTr("-")
466
                                onClicked:  instrumentValueData.removeRangeValue(index)
467 468 469 470 471 472 473 474 475
                            }
                        }
                    }

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

                        Repeater {
476
                            model: instrumentValueData.rangeValues
477 478 479 480 481 482 483 484 485 486 487 488

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

                    Column {
                        spacing: _margins

                        Repeater {
489
                            model: instrumentValueData.rangeOpacities
490 491 492 493 494 495 496 497 498 499 500

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

                QGCButton {
                    text:       qsTr("Add Row")
501
                    onClicked:  instrumentValueData.addRangeValue()
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                }
            }
        }
    }

    Component {
        id: iconPickerDialog

        QGCPopupDialog {
            property var     iconNames:             dialogProperties.iconNames
            property string  icon:                  dialogProperties.icon
            property var     updateIconFunction:    dialogProperties.updateIconFunction

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

            GridLayout {
                columns:        10
                columnSpacing:  0
                rowSpacing:     0

                Repeater {
                    model: iconNames

                    Rectangle {
                        height: ScreenTools.minTouchPixels
                        width:  height
                        color:  currentSelection ? qgcPal.text  : qgcPal.window

                        property bool currentSelection: icon == modelData

                        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:  {
                                    icon = modelData
                                    updateIconFunction(modelData)
                                    hideDialog()
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}