QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
InstrumentValueLabel.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3import QtQuick.Controls
4
5import QGroundControl
6import QGroundControl.Controls
7
8ColumnLayout {
9 property var instrumentValueData: null
10
11 property var _rgFontSizes: [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ]
12 property var _rgFontSizeRatios: [ 1, ScreenTools.smallFontPointRatio, ScreenTools.mediumFontPointRatio, ScreenTools.largeFontPointRatio ]
13 property real _doubleDescent: ScreenTools.defaultFontDescent * 2
14 property real _tightDefaultFontHeight: ScreenTools.defaultFontPixelHeight - _doubleDescent
15 property var _rgFontSizeTightHeights: [ _tightDefaultFontHeight * _rgFontSizeRatios[0] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[1] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[2] + 2, _tightDefaultFontHeight * _rgFontSizeRatios[3] + 2 ]
16 property real _tightHeight: _rgFontSizeTightHeights[instrumentValueData.factValueGrid.fontSize]
17 property bool _iconVisible: instrumentValueData.rangeType === InstrumentValueData.IconSelectRange || instrumentValueData.icon
18 property var _color: instrumentValueData.isValidColor(instrumentValueData.currentColor) ? instrumentValueData.currentColor : qgcPal.text
19
20 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
21
22 QGCColoredImage {
23 id: valueIcon
24 Layout.alignment: Qt.AlignVCenter
25 height: _tightHeight * 0.75
26 width: _tightHeight * 0.85
27 sourceSize.height: height
28 fillMode: Image.PreserveAspectFit
29 mipmap: true
30 smooth: true
31 color: _color
32 opacity: instrumentValueData.currentOpacity
33 visible: _iconVisible
34
35 readonly property string iconPrefix: "/InstrumentValueIcons/"
36
37 function updateIcon() {
38 if (instrumentValueData.rangeType === InstrumentValueData.IconSelectRange) {
39 valueIcon.source = instrumentValueData.currentIcon != "" ? iconPrefix + instrumentValueData.currentIcon : "";
40 } else if (instrumentValueData.icon) {
41 valueIcon.source = instrumentValueData.icon != "" ? iconPrefix + instrumentValueData.icon : "";
42 } else {
43 valueIcon.source = ""
44 }
45 }
46
47 Connections {
48 target: instrumentValueData
49 function onRangeTypeChanged() { valueIcon.updateIcon() }
50 function onCurrentIconChanged() { valueIcon.updateIcon() }
51 function onIconChanged() { valueIcon.updateIcon() }
52 }
53 Component.onCompleted: updateIcon();
54 }
55
56 QGCLabel {
57 Layout.alignment: Qt.AlignVCenter
58 height: _tightHeight
59 font.pointSize: ScreenTools.smallFontPointSize
60 text: instrumentValueData.text
61 color: _color
62 opacity: instrumentValueData.currentOpacity
63 visible: !_iconVisible
64 }
65}