ValuePageWidget.qml 6.62 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
import QGroundControl.Controllers   1.0
import QGroundControl.Palette       1.0
22
import QGroundControl.FlightMap     1.0
23 24
import QGroundControl               1.0

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

31
    property bool showSettingsIcon: true
32 33 34 35 36 37
    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
38
    property var    instrumentValue:                null
39 40 41 42
    property real   _columnButtonWidth:             ScreenTools.minTouchPixels / 2
    property real   _columnButtonHeight:            ScreenTools.minTouchPixels
    property real   _columnButtonSpacing:           2
    property real   _columnButtonsTotalHeight:      (_columnButtonHeight * 2) + _columnButtonSpacing
43 44

    QGCPalette { id:qgcPal; colorGroupEnabled: true }
45
    QGCPalette { id:qgcPalDisabled; colorGroupEnabled: false }
46

47
    ValuesWidgetController { id: controller }
48

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

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

62
    ButtonGroup { id: factRadioGroup }
63

64
    Component {
65
        id: valueItemMouseAreaComponent
66

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

            property var instrumentValue
            property int rowIndex

            onClicked: {
77 78
                instrumentValue = instrumentValue
                mainWindow.showPopupDialog(valueDialogComponent, { instrumentValue: instrumentValue })
79 80 81 82
            }
        }
    }

83 84 85
    Repeater {
        id:     rowRepeater
        model:  controller.valuesModel
86 87

        Column {
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
            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
103
                    property bool componentCompleted:   false
104

105
                    Component.onCompleted: componentCompleted = true
106 107
                    onItemAdded: valueItemMouseAreaComponent.createObject(item, { "instrumentValue": object.get(index), "rowIndex": index })

108
                    InstrumentValue {
109 110
                        id:                     columnItem
                        anchors.verticalCenter: parent.verticalCenter
111
                        width:                  columnRepeater.columnWidth
112 113
                        recalcOk:               columnRepeater.componentCompleted
                        instrumentValue:        object
114 115 116 117 118 119 120 121 122 123 124
                    }
                } // Repeater - columns

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

                    QGCButton {
                        Layout.fillHeight:      true
125
                        Layout.preferredHeight: ScreenTools.minTouchPixels
126 127 128 129 130 131 132
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("+")
                        onClicked:              controller.appendColumn(rowRepeaterLayout.rowIndex)
                    }

                    QGCButton {
                        Layout.fillHeight:      true
133
                        Layout.preferredHeight: ScreenTools.minTouchPixels
134 135 136 137 138 139 140 141 142 143
                        Layout.preferredWidth:  parent.width
                        text:                   qsTr("-")
                        enabled:                index !== 0 || columnRepeater.count !== 1
                        onClicked:              controller.deleteLastColumn(rowRepeaterLayout.rowIndex)
                    }
                }
            } // RowLayout

            RowLayout {
                width:      parent.width
144 145 146
                height:     ScreenTools.defaultFontPixelWidth * 2
                spacing:    1
                visible:    _settingsUnlocked
147 148 149 150 151

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("+")
152
                    onClicked:          controller.insertRow(index + 1)
153 154 155 156 157 158 159 160 161
                }

                QGCButton {
                    Layout.fillWidth:   true
                    Layout.preferredHeight: ScreenTools.defaultFontPixelWidth * 2
                    text:               qsTr("-")
                    enabled:            index !== 0
                    onClicked:          controller.deleteRow(index)
                }
162 163
            }
        }
164 165 166 167 168 169 170 171
    } // Repeater - rows

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

174
    Component {
175
        id: valueDialogComponent
176

177
        InstrumentValueEditDialog { }
178
    }
179
}