-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
TextEdit.qml
190 lines (154 loc) · 4.68 KB
/
TextEdit.qml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import QtQuick 2.14
import QtQuick.Controls 2.14
import Theme 1.0
import org.qfield 1.0
import "."
EditorWidgetBase {
id: topItem
property bool isEditable: isEnabled &&
LayerUtils.fieldType( field ) !== 'QStringList' &&
LayerUtils.fieldType( field ) !== 'QVariantList' &&
LayerUtils.fieldType( field ) !== 'QVariantMap'
height: childrenRect.height
// Due to QTextEdit::onLinkActivated does not work on Android & iOS, we need a separate `Text` element to support links https://bugreports.qt.io/browse/QTBUG-38487
Label {
id: textReadonlyValue
height: !textArea.visible ? textField.height : 0
topPadding: 10
bottomPadding: 10
visible: height !== 0 && !isEditable
anchors.left: parent.left
anchors.right: parent.right
font: Theme.defaultFont
color: Theme.mainTextColor
opacity: 0.45
wrapMode: Text.Wrap
textFormat: config['IsMultiline'] === true && config['UseHtml'] ? TextEdit.RichText : TextEdit.AutoText
text: value == null ? '' : config['IsMultiline'] === true
? config['UseHtml'] === true ? value : stringUtilities.insertLinks(value)
: stringUtilities.insertLinks(value).replace('\n','')
onLinkActivated: Qt.openUrlExternally(link)
}
TextField {
id: textField
topPadding: 10
bottomPadding: 10
visible: (config['IsMultiline'] === undefined || config['IsMultiline'] == false) && isEditable
anchors.left: parent.left
anchors.right: parent.right
font: Theme.defaultFont
color: Theme.mainTextColor
maximumLength: field != undefined && field.length > 0 ? field.length : -1
wrapMode: TextInput.Wrap
text: value == null ? '' : value
validator: {
if (field && field.isNumeric)
if ( LayerUtils.fieldType( field ) === 'double')
{
doubleValidator;
}
else
{
intValidator;
}
else {
null;
}
}
IntValidator {
id: intValidator
}
DoubleValidator {
id: doubleValidator
locale: 'C'
}
inputMethodHints: field && field.isNumeric ? Qt.ImhFormattedNumbersOnly : Qt.ImhNone
background: Rectangle {
width: parent.width
height: parent.height
color: "transparent";
}
onTextChanged: {
valueChangeRequested( text, text == '' )
}
}
TextArea {
id: textArea
height: config['IsMultiline'] === true ? undefined : 0
visible: config['IsMultiline'] === true && isEditable
enabled: isEditable
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.Wrap
font: Theme.defaultFont
color: Theme.mainTextColor
text: value !== undefined ? value : ''
textFormat: config['UseHtml'] ? TextEdit.RichText : TextEdit.PlainText
background: Rectangle {
width: parent.width
height: parent.height
color: "transparent";
}
onTextChanged: {
valueChangeRequested( text, text == '' )
}
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
y: Math.max( textField.height, textArea.height ) - height - textField.bottomPadding / 2
implicitWidth: 120
height: textField.activeFocus || textArea.activeFocus ? 2: 1
color: textField.activeFocus || textArea.activeFocus ? Theme.accentColor : Theme.accentLightColor
}
FontMetrics {
id: fontMetrics
font: textField.font
}
Component.onCompleted: {
menu.addItem( copyTextItem );
menu.addItem( pasteTextItem );
menu.addItem( separatorItem );
menu.addItem( scanCodeItem );
hasMenu = true;
}
MenuItem {
id: copyTextItem
text: qsTr( 'Copy Text' )
font: Theme.defaultFont
icon.source: Theme.getThemeVectorIcon( "ic_copy_black_24dp" )
height: 48
leftPadding: 10
onTriggered: {
platformUtilities.copyTextToClipboard(value)
}
}
MenuItem {
id: pasteTextItem
text: qsTr( 'Paste Text' )
font: Theme.defaultFont
icon.source: Theme.getThemeVectorIcon( "ic_paste_black_24dp" )
height: 48
leftPadding: 10
onTriggered: {
var text = platformUtilities.getTextFromClipboard();
text = text.trim()
valueChangeRequested(text, text == '')
}
}
MenuSeparator { id: separatorItem; width: parent.width }
MenuItem {
id: scanCodeItem
text: qsTr( 'Scan Code' )
font: Theme.defaultFont
icon.source: Theme.getThemeVectorIcon( "ic_qrcode_black_24dp" )
height: 48
leftPadding: 10
onTriggered: {
requestBarcode(topItem)
}
}
function requestedBarcodeReceived(string) {
valueChangeRequested(string, false)
}
}