1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.2
import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
TextField {
id: root
textColor: qgcPal.textFieldText
implicitHeight: ScreenTools.implicitTextFieldHeight
activeFocusOnPress: true
antialiasing: true
property bool showUnits: false
property bool showHelp: false
property string unitsLabel: ""
property string extraUnitsLabel: ""
signal helpClicked
property real _helpLayoutWidth: 0
Component.onCompleted: selectAllIfActiveFocus()
onActiveFocusChanged: selectAllIfActiveFocus()
QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
onEditingFinished: {
if (ScreenTools.isMobile) {
// Toss focus on mobile after Done on virtual keyboard. Prevent strange interactions.
focus = false
}
}
function selectAllIfActiveFocus() {
if (activeFocus) {
selectAll()
}
}
QGCLabel {
id: unitsLabelWidthGenerator
text: unitsLabel
width: contentWidth + parent.__contentHeight * 0.666
visible: false
antialiasing: true
}
style: TextFieldStyle {
id: tfs
font.pointSize: ScreenTools.defaultFontPointSize
font.family: ScreenTools.normalFontFamily
renderType: ScreenTools.isWindows ? Text.QtRendering : tfs.renderType // This works around font rendering problems on windows
background: Item {
id: backgroundItem
property bool showHelp: control.showHelp && control.activeFocus
Rectangle {
anchors.fill: parent
anchors.bottomMargin: -1
color: "#44ffffff"
}
Rectangle {
anchors.fill: parent
border.width: enabled ? 1 : 0
border.color: root.activeFocus ? "#47b" : "#999"
color: qgcPal.textField
}
RowLayout {
id: unitsHelpLayout
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.rightMargin: backgroundItem.showHelp ? 0 : control.__contentHeight * 0.333
anchors.right: parent.right
spacing: ScreenTools.defaultFontPixelWidth / 4
Component.onCompleted: control._helpLayoutWidth = unitsHelpLayout.width
onWidthChanged: control._helpLayoutWidth = unitsHelpLayout.width
Text {
Layout.alignment: Qt.AlignVCenter
text: control.unitsLabel
font.pointSize: backgroundItem.showHelp ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
font.family: ScreenTools.normalFontFamily
antialiasing: true
color: control.textColor
visible: control.showUnits && text !== ""
}
Text {
Layout.alignment: Qt.AlignVCenter
text: control.extraUnitsLabel
font.pointSize: ScreenTools.smallFontPointSize
font.family: ScreenTools.normalFontFamily
antialiasing: true
color: control.textColor
visible: control.showUnits && text !== ""
}
Rectangle {
Layout.margins: 2
Layout.leftMargin: 0
Layout.rightMargin: 1
Layout.fillHeight: true
width: helpLabel.contentWidth * 3
color: control.textColor
visible: backgroundItem.showHelp
QGCLabel {
id: helpLabel
anchors.centerIn: parent
color: qgcPal.textField
text: qsTr("?")
}
}
}
MouseArea {
anchors.margins: ScreenTools.isMobile ? -(ScreenTools.defaultFontPixelWidth * 0.66) : 0 // Larger touch area for mobile
anchors.fill: unitsHelpLayout
enabled: control.activeFocus
onClicked: root.helpClicked()
}
}
padding.right: control._helpLayoutWidth //control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333
}
}