~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to plasma/declarativeimports/plasmacomponents/qml/TextField.qml

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
18
*/
19
19
 
20
 
/**Documentanted API
 
20
/**Documented API
21
21
Inherits:
22
22
        Item
23
23
 
25
25
        QtQuick 1.1
26
26
 
27
27
Description:
28
 
        Creates a simple plasma theme based text field.
29
 
        Like kates..
 
28
        Creates a simple plasma theme based text field widget.
30
29
 
31
30
Properties:
32
 
        alias font:
33
 
        Sets the font for the text area.
34
 
 
35
 
        int inputMethodHints:
36
 
 
37
 
        bool errorHighlight:
38
 
        If it is true then the problematic lines will be highlighted.
39
 
 
40
 
        alias cursorPosition:
41
 
        Returns the cursor's position.
42
 
 
43
 
        alias readOnly:
44
 
        If this property is set to true the text cannot be edited by user interaction.
45
 
 
46
 
        alias selectedText:
47
 
        This read-only property provides the text currently selected in the text edit.
48
 
 
49
 
        alias selectionEnd:
50
 
        The cursor position after the last character in the current selection.
51
 
        This property is read-only.
52
 
 
53
 
        alias selectionStart:
54
 
        The cursor position before the first character in the current selection.
55
 
        This property is read-only.
56
 
 
57
 
        alias text:
58
 
        The text to display
59
 
 
60
 
        string placeholderText:TODO
61
 
 
62
 
        alias echoMode:
63
 
        Specifies how the text should be displayed in the TextInput.
64
 
 
65
 
        TextInput.Normal - Displays the text as it is. (Default)
66
 
        TextInput.Password - Displays asterixes instead of characters.
67
 
        TextInput.NoEcho - Displays nothing.
68
 
        TextInput.PasswordEchoOnEdit - Displays all but the current character as asterixes.
69
 
 
70
 
        alias validator:
71
 
        Allows you to set a validator on the TextInput. When a validator is set the TextInput
72
 
        will only accept input which leaves the text property in an acceptable or intermediate state.
73
 
        The accepted signal will only be sent if the text is in an acceptable state when enter is pressed.
74
 
        Currently supported validators are IntValidator, DoubleValidator and RegExpValidator.
75
 
        An example of using validators is shown below, which allows input of integers
76
 
        between 11 and 31 into the text input:
77
 
        <code>
78
 
        import QtQuick 1.0
79
 
        TextInput{
80
 
            validator: IntValidator{bottom: 11; top: 31;}
81
 
            focus: true
82
 
            }
83
 
        </code>
84
 
 
85
 
        alias maximumLength:
86
 
        Sets the maximum length that the string can have.
87
 
 
88
 
        alias acceptableInput:
89
 
        This property is always true unless a validator has been set. If a validator has been set,
90
 
        this property will only be true if the current text is acceptable to the validator as a final string
91
 
        (not as an intermediate string)
92
 
 
93
 
        alias activeFocus:
94
 
        This property indicates whether the item has active focus.
95
 
        An item with active focus will receive keyboard input.
 
31
      * font font:
 
32
        This property holds the font used in the text field.
 
33
    The default font value is the font from plasma desktop theme.
 
34
 
 
35
      * Qt::InputMethodHints inputMethodHints:
 
36
        This property holds the the currently supported input method hints
 
37
     for the text field.
 
38
     The default values is Qt.ImhNone.
 
39
 
 
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.
 
44
 
 
45
      * int cursorPosition:
 
46
        This property holds the current cursor position.
 
47
 
 
48
      * bool readOnly:
 
49
        This property holds if the text field can be modified by the user interaction.
 
50
    The default value is false.
 
51
 
 
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.
 
56
 
 
57
      * int selectionEnd:
 
58
        This property holds the cursor position after the last character in the current selection.
 
59
    This property is read-only.
 
60
 
 
61
      * int selectionStart:
 
62
        This property holds the cursor position before the first character in the current selection.
 
63
    This property is read-only.
 
64
 
 
65
      * string text:
 
66
        This property holds the entire text in the text field.
 
67
 
 
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.
 
71
 
 
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
 
80
 
 
81
      * string inputMask:
 
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.
 
84
 
 
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:
 
92
    <code>
 
93
    import QtQuick 1.0
 
94
    TextInput {
 
95
        validator: IntValidator { bottom: 11; top: 31 }
 
96
        focus: true
 
97
    }
 
98
    </code>
 
99
 
 
100
      * int maximumLength:
 
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.
 
104
 
 
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.
 
113
 
 
114
       * bool clearButtonShown:
 
115
         Holds if the button to clear the text from TextField is visible.
 
116
Signals:
 
117
       * accepted():
 
118
        This signal is emitted when the text input is accepted.
 
119
 
 
120
Methods:
 
121
       * void copy():
 
122
         Copies the currently selected text to the system clipboard.
 
123
 
 
124
       * void cut():
 
125
         Moves the currently selected text to the system clipboard.
 
126
 
 
127
       * void deselect():
 
128
         Removes active text selection.
 
129
 
 
130
       * void paste():
 
131
         Replaces the currently selected text by the contents of the system clipboard.
 
132
 
 
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).
 
138
 
 
139
       * void selectAll():
 
140
         Causes all text to be selected.
 
141
 
 
142
       * void selectWord():
 
143
         Causes the word closest to the current cursor position to be selected.
 
144
 
 
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.
 
151
 
 
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.
96
155
**/
97
156
 
98
157
import QtQuick 1.1
99
158
import org.kde.plasma.core 0.1 as PlasmaCore
 
159
import "private" as Private
100
160
 
101
 
Item {
 
161
FocusScope {
102
162
    id: textField
103
163
 
104
164
    // Common API
110
170
    property alias cursorPosition: textInput.cursorPosition
111
171
    property alias readOnly: textInput.readOnly
112
172
    property alias echoMode: textInput.echoMode // Supports TextInput.Normal,TextInput.Password, TextInput.NoEcho, TextInput.PasswordEchoOnEdit
 
173
    property alias passwordCharacter: textInput.passwordCharacter
113
174
    property alias acceptableInput: textInput.acceptableInput // read-only
114
175
    property alias inputMask: textInput.inputMask
115
176
    property alias validator: textInput.validator
119
180
    property alias text: textInput.text
120
181
    property alias maximumLength: textInput.maximumLength
121
182
 
 
183
    signal accepted()
 
184
 
122
185
    //Plasma api
123
186
    property bool clearButtonShown: false
124
187
 
147
210
    }
148
211
 
149
212
    function positionAt(pos) {
150
 
        textInput.positionAt(pos);
 
213
        return textInput.positionAt(pos);
151
214
    }
152
215
 
153
216
    function positionToRectangle(pos) {
154
 
        textInput.positionToRectangle(pos);
 
217
        return textInput.positionToRectangle(pos);
155
218
    }
156
219
 
157
220
 
171
234
    //     disabled text fields
172
235
    opacity: enabled ? 1.0 : 0.5
173
236
 
174
 
    TextFieldFocus {
 
237
    Private.TextFieldFocus {
175
238
        id: hover
176
239
        state: textInput.activeFocus ? "focus" : (mouseWatcher.containsMouse ? "hover" : "hidden")
177
240
        anchors.fill: base
190
253
        id: mouseWatcher
191
254
        anchors.fill: hover
192
255
        hoverEnabled: true
 
256
        onClicked: {
 
257
            // If we don't set focus on click here then clicking between the
 
258
            // line of text and the bottom or top of the widget will not focus
 
259
            // it.
 
260
            textInput.forceActiveFocus();
 
261
        }
193
262
    }
194
263
 
195
264
    Text {
203
272
        text: placeholderText
204
273
        visible: textInput.text == "" && !textField.activeFocus
205
274
        // XXX: using textColor and low opacity for theming placeholderText
206
 
        color: theme.viewTextColor
 
275
        //color: theme.viewTextColor
 
276
        color: Qt.color("black")
207
277
        opacity: 0.5
208
278
        elide: Text.ElideRight
209
279
        clip: true
229
299
            leftMargin: 2 * base.margins.left
230
300
            rightMargin: 2 * base.margins.right + (clearButton.opacity > 0 ? clearButton.width : 0)
231
301
        }
 
302
        passwordCharacter: "•"
232
303
        selectByMouse: true
233
 
        color: theme.textColor
 
304
        color: Qt.color("black")
 
305
//         color: theme.textColor
234
306
        enabled: textField.enabled
235
307
        clip: true
 
308
        focus: true
236
309
        onActiveFocusChanged: {
237
310
            if (!textField.activeFocus) {
238
311
                textInput.closeSoftwareInputPanel()
239
312
            }
240
313
        }
241
 
 
242
 
        // Proxying keys events  is not required by the
243
 
        //     common API but is desired in the plasma API.
244
 
        Keys.onPressed: textField.Keys.pressed(event);
245
 
        Keys.onReleased: textField.Keys.released(event);
 
314
        onAccepted: textField.accepted()
246
315
    }
247
316
 
248
 
    PlasmaCore.SvgItem {
 
317
    Private.IconLoader {
249
318
        id: clearButton
250
 
        svg: PlasmaCore.Svg {imagePath: "widgets/lineedit"}
251
 
        elementId: "clearbutton"
252
 
        width: textInput.height
253
 
        height: textInput.height
 
319
        source: "edit-clear-locationbar-rtl"
 
320
        height: Math.max(textInput.height, theme.smallIconSize)
 
321
        width: height
254
322
        opacity: (textInput.text != "" && clearButtonShown) ? 1 : 0
255
323
        Behavior on opacity {
256
324
            NumberAnimation {
271
339
            }
272
340
        }
273
341
    }
274
 
}
 
 
b'\\ No newline at end of file'
 
342
}