6import QGroundControl.Controls
10 color: qgcPal.textFieldText
11 selectionColor: qgcPal.textFieldText
12 selectedTextColor: qgcPal.textField
13 activeFocusOnPress: true
15 font.pointSize: ScreenTools.defaultFontPointSize
16 font.family: ScreenTools.normalFontFamily
17 inputMethodHints: numericValuesOnly && !ScreenTools.isiOS ?
18 Qt.ImhFormattedNumbersOnly: // Forces use of virtual numeric keyboard instead of full keyboard
19 Qt.ImhNone // iOS numeric keyboard has no done button, we can't use it.
20 leftPadding: _marginPadding
21 rightPadding: _marginPadding + unitsHelpLayout.width
22 topPadding: _marginPadding
23 bottomPadding: _marginPadding
24 EnterKey.type: Qt.EnterKeyDone
26 property bool showUnits: false
27 property bool showHelp: false
28 property string unitsLabel: ""
29 property string extraUnitsLabel: ""
30 property bool numericValuesOnly: false // true: Used as hint for mobile devices to show numeric only keyboard
31 property alias textColor: control.color
32 property bool validationError: false
34 property real _helpLayoutWidth: 0
35 property real _marginPadding: ScreenTools.defaultFontPixelHeight / 3
39 Component.onCompleted: checkActiveFocus()
40 onActiveFocusChanged: checkActiveFocus()
42 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
45 if (ScreenTools.isMobile) {
46 // Toss focus on mobile after Done on virtual keyboard. Prevent strange interactions.
51 function checkActiveFocus() {
54 if (validationError) {
55 validationToolTip.visible = true
58 validationToolTip.visible = false
62 function showValidationError(errorString, originalValidValue = undefined, preventViewSiwtch = true) {
63 validationToolTip.text = errorString
64 validationToolTip.originalValidValue = originalValidValue
65 validationToolTip.visible = true
66 if (!validationError) {
67 validationError = true
68 if (preventViewSiwtch) {
69 globals.validationErrorCount++
74 function clearValidationError(preventViewSiwtch = true) {
75 validationToolTip.visible = false
76 validationToolTip.originalValidValue = undefined
77 if (validationError) {
78 validationError = false
79 if (preventViewSiwtch) {
80 globals.validationErrorCount--
85 background: Rectangle {
86 border.width: control.validationError ? 2 : (qgcPal.globalTheme === QGCPalette.Light ? 1 : 0)
87 border.color: control.validationError ? qgcPal.colorRed : qgcPal.buttonBorder
88 radius: ScreenTools.defaultBorderRadius
89 color: qgcPal.textField
90 implicitWidth: ScreenTools.implicitTextFieldWidth
91 implicitHeight: ScreenTools.implicitTextFieldHeight
95 anchors.top: parent.top
96 anchors.bottom: parent.bottom
97 anchors.right: parent.right
98 anchors.rightMargin: control.activeFocus ? 2 : control._marginPadding
99 spacing: ScreenTools.defaultFontPixelWidth / 4
100 layoutDirection: Qt.RightToLeft
102 Component.onCompleted: control._helpLayoutWidth = unitsHelpLayout.width
103 onWidthChanged: control._helpLayoutWidth = unitsHelpLayout.width
110 Layout.rightMargin: 1
111 Layout.fillHeight: true
112 Layout.preferredWidth: helpLabel.contentWidth * 3
113 Layout.alignment: Qt.AlignVCenter
115 visible: control.showHelp && control.activeFocus
119 anchors.centerIn: parent
120 color: qgcPal.textField
128 Layout.alignment: Qt.AlignVCenter
129 text: control.extraUnitsLabel
130 font.pointSize: ScreenTools.smallFontPointSize
131 font.family: ScreenTools.normalFontFamily
134 visible: control.showUnits && text !== ""
139 Layout.alignment: Qt.AlignVCenter
140 text: control.unitsLabel
141 font.pointSize: control.activeFocus ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
142 font.family: ScreenTools.normalFontFamily
145 visible: control.showUnits && text !== ""
151 id: validationToolTip
153 property var originalValidValue: undefined
158 if (validationToolTip.originalValidValue !== undefined) {
159 control.text = validationToolTip.originalValidValue
160 control.clearValidationError()
167 anchors.top: parent.top
168 anchors.bottom: parent.bottom
169 anchors.right: parent.right
170 width: control._helpLayoutWidth
171 enabled: helpButton.visible
172 onClicked: control.helpClicked()