2
* Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
Creates a simple plasma theme based text field widget.
32
This property holds the font used in the text field.
33
The default font value is the font from plasma desktop theme.
35
* Qt::InputMethodHints inputMethodHints:
36
This property holds the the currently supported input method hints
38
The default values is Qt.ImhNone.
40
* bool errorHighlight:
41
This property holds if the text field is highlighted or not
42
If it is true then the problematic lines will be highlighted.
43
This feature is defined in the Common API but is unimplemented in plasma components.
46
This property holds the current cursor position.
49
This property holds if the text field can be modified by the user interaction.
50
The default value is false.
52
* string selectedText:
53
This property holds the text selected by the user.
54
If no text is selected it holds an empty string.
55
This property is read-only.
58
This property holds the cursor position after the last character in the current selection.
59
This property is read-only.
62
This property holds the cursor position before the first character in the current selection.
63
This property is read-only.
66
This property holds the entire text in the text field.
68
* string placeholderText:
69
This property holds the text displayed in when the text is empty.
70
The default value is empty string, meaning no placeholderText shown.
72
* enumeration echoMode:
73
This property specifies how the text should be displayed in the TextField.
74
The acceptable values are:
75
- TextInput.Normal - Displays the text as it is. (Default)
76
- TextInput.Password - Displays asterixes instead of characters.
77
- TextInput.NoEcho - Displays nothing.
78
- TextInput.PasswordEchoOnEdit - Displays all but the current character as asterixes.
79
The default value is TextInput.Normal
82
Allows you to set an input mask on the TextField, restricting the allowable text inputs.
83
See QLineEdit::inputMask for further details, as the exact same mask strings are used by TextInput.
85
* Validator validator:
86
Allows you to set a validator on the TextField. When a validator is set the TextField
87
will only accept input which leaves the text property in an acceptable or intermediate state.
88
The accepted signal will only be sent if the text is in an acceptable state when enter is pressed.
89
Currently supported validators are IntValidator, DoubleValidator and RegExpValidator.
90
An example of using validators is shown below, which allows input of integers
91
between 11 and 31 into the text input:
95
validator: IntValidator{bottom: 11; top: 31;}
101
The maximum permitted length of the text in the TextField.
102
If the text is too long, it is truncated at the limit.
103
By default, this property contains a value of 32767.
105
* bool acceptableInput:
106
This property is always true unless a validator or input mask has been set.
107
If a validator or input mask has been set, this property will only be true if the current
108
text is acceptable to the validator or input mask as a final string (not as an intermediate string).
109
This property is always true unless a validator has been set.
110
If a validator has been set, this property will only be true if the current text is acceptable to the
111
validator as a final string (not as an intermediate string).
112
This property is read-only.
114
* bool clearButtonShown:
115
Holds if the button to clear the text from TextField is visible.
118
This signal is emitted when the text input is accepted.
122
Copies the currently selected text to the system clipboard.
125
Moves the currently selected text to the system clipboard.
128
Removes active text selection.
131
Replaces the currently selected text by the contents of the system clipboard.
133
* void select(int start, int end):
134
Causes the text from start to end to be selected.
135
If either start or end is out of range, the selection is not changed.
136
After calling this, selectionStart will become the lesser and selectionEnd will become the greater
137
(regardless of the order passed to this method).
140
Causes all text to be selected.
143
Causes the word closest to the current cursor position to be selected.
145
* void positionAt(int position):
146
This function returns the character position at x pixels from the left of the TextField.
147
Position 0 is before the first character, position 1 is after the first character but before the second,
148
and so on until position text.length, which is after all characters.
149
This means that for all x values before the first character this function returns 0,
150
and for all x values after the last character this function returns text.length.
152
* rectangle positionToRectangle(position):
153
Returns the rectangle at the given position in the text.
154
The x, y, and height properties correspond to the cursor that would describe that position.
158
import org.kde.plasma.core 0.1 as PlasmaCore
159
import "private" as Private
165
property bool errorHighlight: false // TODO
166
property string placeholderText
167
property alias inputMethodHints: textInput.inputMethodHints
168
property alias font: textInput.font
170
property alias cursorPosition: textInput.cursorPosition
171
property alias readOnly: textInput.readOnly
172
property alias echoMode: textInput.echoMode // Supports TextInput.Normal,TextInput.Password, TextInput.NoEcho, TextInput.PasswordEchoOnEdit
173
property alias passwordCharacter: textInput.passwordCharacter
174
property alias acceptableInput: textInput.acceptableInput // read-only
175
property alias inputMask: textInput.inputMask
176
property alias validator: textInput.validator
177
property alias selectedText: textInput.selectedText // read-only
178
property alias selectionEnd: textInput.selectionEnd // read-only
179
property alias selectionStart: textInput.selectionStart // read-only
180
property alias text: textInput.text
181
property alias maximumLength: textInput.maximumLength
186
property bool clearButtonShown: false
200
function select(start, end) {
201
textInput.select(start, end);
204
function selectAll() {
205
textInput.selectAll();
208
function selectWord() {
209
textInput.selectWord();
212
function positionAt(pos) {
213
return textInput.positionAt(pos);
216
function positionToRectangle(pos) {
217
return textInput.positionToRectangle(pos);
221
// Set active focus to it's internal textInput.
222
// Overriding QtQuick.Item forceActiveFocus function.
223
function forceActiveFocus() {
224
textInput.forceActiveFocus();
227
// Overriding QtQuick.Item activeFocus property.
228
property alias activeFocus: textInput.activeFocus
230
// TODO: fix default size
231
implicitWidth: theme.defaultFont.mSize.width*12
232
implicitHeight: theme.defaultFont.mSize.height*1.6
233
// TODO: needs to define if there will be specific graphics for
234
// disabled text fields
235
opacity: enabled ? 1.0 : 0.5
237
Private.TextFieldFocus {
239
state: textInput.activeFocus ? "focus" : (mouseWatcher.containsMouse ? "hover" : "hidden")
243
PlasmaCore.FrameSvgItem {
246
// TODO: see what is the correct policy for margins
248
imagePath: "widgets/lineedit"
257
textInput.forceActiveFocus();
265
verticalCenter: parent.verticalCenter
266
leftMargin: 2 * base.margins.left
267
rightMargin: 2 * base.margins.right
269
text: placeholderText
270
visible: textInput.text == "" && !textField.activeFocus
271
// XXX: using textColor and low opacity for theming placeholderText
272
color: theme.viewTextColor
274
elide: Text.ElideRight
276
font.capitalization: theme.defaultFont.capitalization
277
font.family: theme.defaultFont.family
278
font.italic: theme.defaultFont.italic
279
font.letterSpacing: theme.defaultFont.letterSpacing
280
font.pointSize: theme.defaultFont.pointSize
281
font.strikeout: theme.defaultFont.strikeout
282
font.underline: theme.defaultFont.underline
283
font.weight: theme.defaultFont.weight
284
font.wordSpacing: theme.defaultFont.wordSpacing
293
verticalCenter: parent.verticalCenter
294
// TODO: see what is the correct policy for margins
295
leftMargin: 2 * base.margins.left
296
rightMargin: 2 * base.margins.right + (clearButton.opacity > 0 ? clearButton.width : 0)
298
passwordCharacter: "•"
300
color: theme.textColor
301
enabled: textField.enabled
304
onActiveFocusChanged: {
305
if (!textField.activeFocus) {
306
textInput.closeSoftwareInputPanel()
309
onAccepted: textField.accepted()
314
source: "edit-clear-locationbar-rtl"
315
height: Math.max(textInput.height, theme.smallIconSize)
317
opacity: (textInput.text != "" && clearButtonShown) ? 1 : 0
318
Behavior on opacity {
321
easing.type: Easing.InOutQuad
327
verticalCenter: textInput.verticalCenter
333
textInput.forceActiveFocus()