Merge lp:~zsombi/ubuntu-ui-toolkit/textfield-api into lp:ubuntu-ui-toolkit

Proposed by Zsombor Egri
Status: Merged
Approved by: Tim Peeters
Approved revision: 578
Merged at revision: 576
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/textfield-api
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 963 lines (+519/-73)
3 files modified
components.api (+27/-2)
modules/Ubuntu/Components/TextField.qml (+343/-70)
tests/unit_x11/tst_components/tst_textfield.qml (+149/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/textfield-api
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Tim Peeters Pending
Review via email: mp+172781@code.launchpad.net

Commit message

TextField API extended with API left out from TextInput. wrapMode is not inlcuded as does not make sense to be used in single line input.

To post a comment you must log in.
578. By Zsombor Egri

forceActiveFocus moved back to internal

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2013-07-02 00:19:41 +0000
+++ components.api 2013-07-03 10:36:26 +0000
@@ -255,22 +255,40 @@
255 property alias secondaryItem255 property alias secondaryItem
256 property bool errorHighlight256 property bool errorHighlight
257 property alias acceptableInput257 property alias acceptableInput
258 property alias activeFocusOnPress
259 property alias autoScroll
260 property alias canPaste
261 property alias canRedo
262 property alias canUndo
263 property alias color
264 property alias contentHeight
265 property alias contentWidth
266 property alias cursorDelegate
258 property alias cursorPosition267 property alias cursorPosition
268 property alias cursorRectangle
269 property alias cursorVisible
270 property alias displayText
259 property alias echoMode271 property alias echoMode
260 property alias font272 property alias font
261 property alias inputMask273 property alias inputMask
262 property alias inputMethodComposing274 property alias inputMethodComposing
263 property alias inputMethodHints275 property alias inputMethodHints
276 property alias length
264 property alias maximumLength277 property alias maximumLength
278 property alias mouseSelectionMode
279 property alias persistentSelection
265 property alias readOnly280 property alias readOnly
266 property alias selectedText281 property alias renderType
282 property alias selectByMouse
283 readonly property alias selectedText
267 property alias selectionStart284 property alias selectionStart
268 property alias selectionEnd285 property alias selectionEnd
269 property alias text286 property alias text
270 property alias validator287 property alias validator
271 property alias horizontalAlignment288 property alias horizontalAlignment
289 property alias effectiveHorizontalAlignment
290 property alias verticalAlignment
272 property alias passwordCharacter291 property alias passwordCharacter
273 property alias color
274 property alias selectionColor292 property alias selectionColor
275 property alias selectedTextColor293 property alias selectedTextColor
276 signal accepted()294 signal accepted()
@@ -278,12 +296,19 @@
278 function cut()296 function cut()
279 function paste(data)297 function paste(data)
280 function deselect()298 function deselect()
299 function insert(position, text)
281 function positionAt(x, position)300 function positionAt(x, position)
282 function positionToRectangle(pos)301 function positionToRectangle(pos)
283 function select(start, end)302 function select(start, end)
284 function selectAll()303 function selectAll()
285 function selectWord()304 function selectWord()
286 function forceActiveFocus()305 function forceActiveFocus()
306 function isRightToLeft(start, end)
307 function moveCursorSelection(position, mode)
308 function redo()
309 function undo()
310 function remove(start, end)
311 function getText(start, end)
287 property alias __internal312 property alias __internal
288modules/Ubuntu/Components/TextInputPopover.qml313modules/Ubuntu/Components/TextInputPopover.qml
289ActionSelectionPopover314ActionSelectionPopover
290315
=== modified file 'modules/Ubuntu/Components/TextField.qml'
--- modules/Ubuntu/Components/TextField.qml 2013-06-27 15:20:12 +0000
+++ modules/Ubuntu/Components/TextField.qml 2013-07-03 10:36:26 +0000
@@ -85,7 +85,6 @@
85 property bool highlighted: focus85 property bool highlighted: focus
8686
87 /*!87 /*!
88 \preliminary
89 Text that appears when there is no focus and no content in the component.88 Text that appears when there is no focus and no content in the component.
9089
91 \qmlproperty string placeholderText90 \qmlproperty string placeholderText
@@ -93,7 +92,6 @@
93 property alias placeholderText: hint.text92 property alias placeholderText: hint.text
9493
95 /*!94 /*!
96 \preliminary
97 Specifies whether the control has a clear button or not.95 Specifies whether the control has a clear button or not.
98 */96 */
99 property bool hasClearButton: true97 property bool hasClearButton: true
@@ -112,7 +110,6 @@
112 property var popover110 property var popover
113111
114 /*!112 /*!
115 \preliminary
116 Overlaid component that can be set for the fore side of the TextField,113 Overlaid component that can be set for the fore side of the TextField,
117 e.g.showing a magnifier to implement search functionality.114 e.g.showing a magnifier to implement search functionality.
118115
@@ -121,7 +118,6 @@
121 property alias primaryItem: leftPane.data118 property alias primaryItem: leftPane.data
122119
123 /*!120 /*!
124 \preliminary
125 Overlaid component that can be set for the rear side of the TextField,121 Overlaid component that can be set for the rear side of the TextField,
126 e.g.showing a CAPS LOCK or NUM LOCK indication. The overlaid components122 e.g.showing a CAPS LOCK or NUM LOCK indication. The overlaid components
127 will be placed right after the clear button.123 will be placed right after the clear button.
@@ -131,14 +127,12 @@
131 property alias secondaryItem: rightPane.data127 property alias secondaryItem: rightPane.data
132128
133 /*!129 /*!
134 \preliminary
135 Allows highlighting errors in the TextField.130 Allows highlighting errors in the TextField.
136 */131 */
137 property bool errorHighlight: !acceptableInput132 property bool errorHighlight: !acceptableInput
138133
139 // aliased properties from TextInput134 // aliased properties from TextInput
140 /*!135 /*!
141 \preliminary
142 This property is always true unless a validator or input mask has been set.136 This property is always true unless a validator or input mask has been set.
143 If a validator or input mask has been set, this property will only be true137 If a validator or input mask has been set, this property will only be true
144 if the current text is acceptable to the validator or input mask as a final138 if the current text is acceptable to the validator or input mask as a final
@@ -149,7 +143,84 @@
149 property alias acceptableInput: editor.acceptableInput143 property alias acceptableInput: editor.acceptableInput
150144
151 /*!145 /*!
152 \preliminary146 Whether the TextField should gain active focus on a mouse press. By default
147 this is set to true.
148
149 \qmlproperty bool activeFocusOnPress
150 */
151 property alias activeFocusOnPress: editor.activeFocusOnPress
152
153 /*!
154 Whether the TextField should scroll when the text is longer than the width.
155 By default this is set to true.
156
157 \qmlproperty bool autoScroll
158 */
159 property alias autoScroll: editor.autoScroll
160
161 /*!
162 Returns true if the TextField is writable and the content of the clipboard
163 is suitable for pasting into the TextField.
164
165 \qmlproperty bool canPaste
166 */
167 property alias canPaste: editor.canPaste
168
169 /*!
170 Returns true if the TextField is writable and there are undone operations
171 that can be redone.
172
173 \qmlproperty bool canRedo
174 */
175 property alias canRedo: editor.canRedo
176
177 /*!
178 Returns true if the TextField is writable and there are previous operations
179 that can be undone.
180
181 \qmlproperty bool canUndo
182 */
183 property alias canUndo: editor.canUndo
184
185 /*!
186 The text color.
187 \qmlproperty color color
188 */
189 property alias color: editor.color
190
191 /*!
192 Returns the height of the text, including the height past the height that
193 is covered if the text does not fit within the set height.
194
195 \qmlproperty real contentHeight
196 */
197 property alias contentHeight: editor.contentHeight
198
199 /*!
200 Returns the width of the text, including the width past the width which
201 is covered due to insufficient wrapping if wrapMode is set.
202
203 \qmlproperty real contentWidth
204 */
205 property alias contentWidth: editor.contentWidth
206
207 /*!
208 The delegate for the cursor in the TextField.
209
210 If you set a cursorDelegate for a TextField, this delegate will be used for
211 drawing the cursor instead of the standard cursor. An instance of the delegate
212 will be created and managed by the TextField when a cursor is needed, and
213 the x property of delegate instance will be set so as to be one pixel before
214 the top left of the current character.
215
216 Note that the root item of the delegate component must be a QQuickItem or
217 QQuickItem derived item.
218
219 \qmlproperty Component cursorDelegate
220 */
221 property alias cursorDelegate: editor.cursorDelegate
222
223 /*!
153 The position of the cursor in the TextField.224 The position of the cursor in the TextField.
154225
155 \qmlproperty int cursorPosition226 \qmlproperty int cursorPosition
@@ -157,21 +228,70 @@
157 property alias cursorPosition: editor.cursorPosition228 property alias cursorPosition: editor.cursorPosition
158229
159 /*!230 /*!
160 \preliminary231 The rectangle where the standard text cursor is rendered within the text
232 input. Read only.
233
234 The position and height of a custom cursorDelegate are updated to follow
235 the cursorRectangle automatically when it changes. The width of the delegate
236 is unaffected by changes in the cursor rectangle.
237
238 \qmlproperty rectangle cursorRectangle
239 */
240 property alias cursorRectangle: editor.cursorRectangle
241
242 /*!
243 Set to true when the TextField shows a cursor.
244
245 This property is set and unset when the TextField gets active focus, so that
246 other properties can be bound to whether the cursor is currently showing.
247 As it gets set and unset automatically, when you set the value yourself you
248 must keep in mind that your value may be overwritten.
249
250 It can be set directly in script, for example if a KeyProxy might forward keys
251 to it and you desire it to look active when this happens (but without actually
252 giving it active focus).
253
254 It should not be set directly on the item, like in the below QML, as the specified
255 value will be overridden an lost on focus changes.
256 \qml
257 TextField {
258 text: "Text"
259 cursorVisible: false
260 }
261 \endqml
262 In the above snippet the cursor will still become visible when the TextField
263 gains active focus.
264
265 \qmlproperty bool cursorVisible
266 */
267 property alias cursorVisible: editor.cursorVisible
268
269 /*!
270 This is the text displayed in the TextField.
271
272 If echoMode is set to TextInput::Normal, this holds the same value as the
273 \l text property. Otherwise, this property holds the text visible to the
274 user, while the text property holds the actual entered text.
275
276 \qmlproperty string displayText
277 */
278 property alias displayText: editor.displayText
279
280 /*!
161 Specifies how the text should be displayed in the TextField.281 Specifies how the text should be displayed in the TextField.
162282 \list
163 - TextInput.Normal - Displays the text as it is. (Default)283 \li - TextInput.Normal - Displays the text as it is. (Default)
164 - TextInput.Password - Displays asterixes instead of characters.284 \li - TextInput.Password - Displays asterixes instead of characters.
165 - TextInput.NoEcho - Displays nothing.285 \li - TextInput.NoEcho - Displays nothing.
166 - TextInput.PasswordEchoOnEdit - Displays characters as they are entered while286 \li - TextInput.PasswordEchoOnEdit - Displays characters as they are entered while
167 editing, otherwise displays asterisks.287 editing, otherwise displays asterisks.
288 \endlist
168289
169 \qmlproperty enumeration echoMode290 \qmlproperty enumeration echoMode
170 */291 */
171 property alias echoMode: editor.echoMode292 property alias echoMode: editor.echoMode
172293
173 /*!294 /*!
174 \preliminary
175 Font used in the TextField.295 Font used in the TextField.
176296
177 \qmlproperty font font297 \qmlproperty font font
@@ -179,7 +299,6 @@
179 property alias font: editor.font299 property alias font: editor.font
180300
181 /*!301 /*!
182 \preliminary
183 Allows you to set an input mask on the TextField, restricting the text302 Allows you to set an input mask on the TextField, restricting the text
184 inputs. See QLineEdit::inputMask for further details, as the exact same mask strings303 inputs. See QLineEdit::inputMask for further details, as the exact same mask strings
185 are used by TextField.304 are used by TextField.
@@ -189,7 +308,6 @@
189 property alias inputMask: editor.inputMask308 property alias inputMask: editor.inputMask
190309
191 /*!310 /*!
192 \preliminary
193 This property holds whether the TextInput has partial text input from an input method.311 This property holds whether the TextInput has partial text input from an input method.
194312
195 While it is composing an input method may rely on mouse or key events from the313 While it is composing an input method may rely on mouse or key events from the
@@ -202,7 +320,6 @@
202 property alias inputMethodComposing: editor.inputMethodComposing320 property alias inputMethodComposing: editor.inputMethodComposing
203321
204 /*!322 /*!
205 \preliminary
206 Provides hints to the input method about the expected content of the text input and how it323 Provides hints to the input method about the expected content of the text input and how it
207 should operate.324 should operate.
208325
@@ -211,37 +328,37 @@
211 Flags that alter behaviour are:328 Flags that alter behaviour are:
212329
213 \list330 \list
214 \li Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.331 \li - Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.
215 This is automatically set when setting echoMode to \c TextInput.Password.332 This is automatically set when setting echoMode to \c TextInput.Password.
216 \li Qt.ImhSensitiveData - Typed text should not be stored by the active input method333 \li - Qt.ImhSensitiveData - Typed text should not be stored by the active input method
217 in any persistent storage like predictive user dictionary.334 in any persistent storage like predictive user dictionary.
218 \li Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case335 \li - Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case
219 when a sentence ends.336 when a sentence ends.
220 \li Qt.ImhPreferNumbers - Numbers are preferred (but not required).337 \li - Qt.ImhPreferNumbers - Numbers are preferred (but not required).
221 \li Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).338 \li - Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).
222 \li Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).339 \li - Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).
223 \li Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.340 \li - Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.
224341
225 \li Qt.ImhDate - The text editor functions as a date field.342 \li - Qt.ImhDate - The text editor functions as a date field.
226 \li Qt.ImhTime - The text editor functions as a time field.343 \li - Qt.ImhTime - The text editor functions as a time field.
227 \endlist344 \endlist
228345
229 Flags that restrict input (exclusive flags) are:346 Flags that restrict input (exclusive flags) are:
230347
231 \list348 \list
232 \li Qt.ImhDigitsOnly - Only digits are allowed.349 \li - Qt.ImhDigitsOnly - Only digits are allowed.
233 \li Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign.350 \li - Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign.
234 \li Qt.ImhUppercaseOnly - Only upper case letter input is allowed.351 \li - Qt.ImhUppercaseOnly - Only upper case letter input is allowed.
235 \li Qt.ImhLowercaseOnly - Only lower case letter input is allowed.352 \li - Qt.ImhLowercaseOnly - Only lower case letter input is allowed.
236 \li Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed.353 \li - Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed.
237 \li Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed.354 \li - Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed.
238 \li Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed.355 \li - Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed.
239 \endlist356 \endlist
240357
241 Masks:358 Masks:
242359
243 \list360 \list
244 \li Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.361 \li - Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.
245 \endlist362 \endlist
246363
247 \qmlproperty enumeration inputMethodHints364 \qmlproperty enumeration inputMethodHints
@@ -249,7 +366,20 @@
249 property alias inputMethodHints: editor.inputMethodHints366 property alias inputMethodHints: editor.inputMethodHints
250367
251 /*!368 /*!
252 \preliminary369 Returns the total number of characters in the TextField item.
370
371 If the TextField has an inputMask the length will include mask characters
372 and may differ from the length of the string returned by the text property.
373
374 This property can be faster than querying the length the text property as
375 it doesn't require any copying or conversion of the TextField's internal
376 string data.
377
378 \qmlproperty int length
379 */
380 property alias length: editor.length
381
382 /*!
253 The maximum permitted length of the text in the TextField.383 The maximum permitted length of the text in the TextField.
254384
255 If the text is too long, it is truncated at the limit.385 If the text is too long, it is truncated at the limit.
@@ -261,7 +391,27 @@
261 property alias maximumLength: editor.maximumLength391 property alias maximumLength: editor.maximumLength
262392
263 /*!393 /*!
264 \preliminary394 Specifies how text should be selected using a mouse.
395 \list
396 \li -TextInput.SelectCharacters - The selection is updated with individual
397 characters. (Default)
398 \li -TextInput.SelectWords - The selection is updated with whole words.
399 \endlist
400 This property only applies when selectByMouse is true.
401
402 \qmlproperty enumeration mouseSelectionMode
403 */
404 property alias mouseSelectionMode: editor.mouseSelectionMode
405
406 /*!
407 Whether the TextField should keep its selection when it loses active focus
408 to another item in the scene. By default this is set to false.
409
410 \qmlproperty bool persistentSelection
411 */
412 property alias persistentSelection: editor.persistentSelection
413
414 /*!
265 Sets whether user input can modify the contents of the TextField.415 Sets whether user input can modify the contents of the TextField.
266416
267 If readOnly is set to true, then user input will not affect the417 If readOnly is set to true, then user input will not affect the
@@ -273,15 +423,48 @@
273 property alias readOnly: editor.readOnly423 property alias readOnly: editor.readOnly
274424
275 /*!425 /*!
426 Override the default rendering type for this component.
427
428 Supported render types are:
429 \list
430 \li - Text.QtRendering - (default)
431 \li - Text.NativeRendering
432 \endlist
433
434 Select Text.NativeRendering if you prefer text to look native on the target
435 platform and do not require advanced features such as transformation of the
436 text. Using such features in combination with the NativeRendering render type
437 will lend poor and sometimes pixelated results.
438
439 \qmlproperty enumeration renderType
440 */
441 property alias renderType: editor.renderType
442
443 /*!
444 Defaults to true.
445
446 If false, the user cannot use the mouse to select text, only can use it to
447 focus the input.
448
449 \qmlproperty bool selectByMouse
276 \preliminary450 \preliminary
451 */
452 property alias selectByMouse: virtualKbdHandler.enabled
453
454 /*!
277 This read-only property provides the text currently selected in the text input.455 This read-only property provides the text currently selected in the text input.
278456
457 It is equivalent to the following snippet, but is faster and easier to use.
458 \code
459 myTextInput.text.toString().substring(myTextInput.selectionStart,
460 myTextInput.selectionEnd);
461 \endcode
462
279 \qmlproperty string selectedText463 \qmlproperty string selectedText
280 */464 */
281 property alias selectedText: editor.selectedText465 readonly property alias selectedText: editor.selectedText
282466
283 /*!467 /*!
284 \preliminary
285 The cursor position before the first character in the current selection.468 The cursor position before the first character in the current selection.
286469
287 This property is read-only. To change the selection, use select(start,end),470 This property is read-only. To change the selection, use select(start,end),
@@ -292,7 +475,6 @@
292 property alias selectionStart: editor.selectionStart475 property alias selectionStart: editor.selectionStart
293476
294 /*!477 /*!
295 \preliminary
296 The cursor position after the last character in the current selection.478 The cursor position after the last character in the current selection.
297479
298 This property is read-only. To change the selection, use select(start,end),480 This property is read-only. To change the selection, use select(start,end),
@@ -303,7 +485,6 @@
303 property alias selectionEnd: editor.selectionEnd485 property alias selectionEnd: editor.selectionEnd
304486
305 /*!487 /*!
306 \preliminary
307 The text in the TextField.488 The text in the TextField.
308489
309 \qmlproperty string text490 \qmlproperty string text
@@ -311,7 +492,6 @@
311 property alias text: editor.text492 property alias text: editor.text
312493
313 /*!494 /*!
314 \preliminary
315 Allows you to set a validator on the TextInput. When a validator is set the495 Allows you to set a validator on the TextInput. When a validator is set the
316 TextField will only accept input which leaves the text property in an acceptable496 TextField will only accept input which leaves the text property in an acceptable
317 or intermediate state. The accepted signal will only be sent if the text is in497 or intermediate state. The accepted signal will only be sent if the text is in
@@ -323,23 +503,25 @@
323503
324 \qml504 \qml
325 import QtQuick 2.0505 import QtQuick 2.0
326 TextInput{506 import Ubuntu.Components 0.1
507 TextField{
327 validator: IntValidator{bottom: 11; top: 31;}508 validator: IntValidator{bottom: 11; top: 31;}
328 focus: true509 focus: true
329 }510 }
330 \endqml511 \endqml
331512
513 \sa acceptableInput, inputMask
514
332 \qmlproperty Validator validator515 \qmlproperty Validator validator
333 */516 */
334 property alias validator: editor.validator517 property alias validator: editor.validator
335518
336 /*!519 /*!
337 \preliminary
338 Sets the horizontal alignment of the text within the item's width and height.520 Sets the horizontal alignment of the text within the item's width and height.
339 By default, the text alignment follows the natural alignment of the text, for521 By default, the text alignment follows the natural alignment of the text, for
340 example text that is read from left to right will be aligned to the left.522 example text that is read from left to right will be aligned to the left.
341523
342 TextInput does not have vertical alignment, as the natural height is exactly524 TextField does not have vertical alignment, as the natural height is exactly
343 the height of the single line of text. If you set the height manually to something525 the height of the single line of text. If you set the height manually to something
344 larger, TextInput will always be top aligned vertically. You can use anchors to526 larger, TextInput will always be top aligned vertically. You can use anchors to
345 align it however you want within another item.527 align it however you want within another item.
@@ -347,36 +529,51 @@
347 The valid values for horizontalAlignment are TextInput.AlignLeft,529 The valid values for horizontalAlignment are TextInput.AlignLeft,
348 TextInput.AlignRight and TextInput.AlignHCenter.530 TextInput.AlignRight and TextInput.AlignHCenter.
349531
532 Valid values for verticalAlignment are TextInput.AlignTop (default), TextInput.AlignBottom
533 TextInput.AlignVCenter.
534
535 When using the attached property LayoutMirroring::enabled to mirror application
536 layouts, the horizontal alignment of text will also be mirrored. However,
537 the property horizontalAlignment will remain unchanged. To query the effective
538 horizontal alignment of TextField, use the read-only property effectiveHorizontalAlignment.
539
350 \qmlproperty enumeration horizontalAlignment540 \qmlproperty enumeration horizontalAlignment
541 \qmlproperty enumeration effectiveHorizontalAlignment
542 \qmlproperty enumeration verticalAlignment
351 */543 */
352 property alias horizontalAlignment: editor.horizontalAlignment544 property alias horizontalAlignment: editor.horizontalAlignment
545 /*! \internal */
546 property alias effectiveHorizontalAlignment: editor.effectiveHorizontalAlignment
547 /*! \internal */
548 property alias verticalAlignment: editor.verticalAlignment
353549
354 /*!550 /*!
355 \internal551 This is the character displayed when echoMode is set to Password or
356 FIXME: property added for styling purposes552 PasswordEchoOnEdit. By default it is the unicode character 2022.
553
554 If this property is set to a string with more than one character, the first
555 character is used. If the string is empty, the value is ignored and the property
556 is not set.
557
558 \qmlproperty string passwordCharacter
357 */559 */
358 property alias passwordCharacter: editor.passwordCharacter560 property alias passwordCharacter: editor.passwordCharacter
359561
360 /*!562 /*!
361 \internal563 The text highlight color, used behind selections.
362 FIXME: property added for styling purposes
363 */
364 property alias color: editor.color
365564
366 /*!565 \qmlproperty color selectionColor
367 \internal
368 FIXME: property added for styling purposes
369 */566 */
370 property alias selectionColor: editor.selectionColor567 property alias selectionColor: editor.selectionColor
371568
372 /*!569 /*!
373 \internal570 The highlighted text color, used in selections.
374 FIXME: property added for styling purposes571
572 \qmlproperty color selctedTextColor
375 */573 */
376 property alias selectedTextColor: editor.selectedTextColor574 property alias selectedTextColor: editor.selectedTextColor
377575
378 /*!576 /*!
379 \preliminary
380 This handler is called when the Return or Enter key is pressed. Note that if577 This handler is called when the Return or Enter key is pressed. Note that if
381 there is a validator or inputMask set on the text input, the handler will only578 there is a validator or inputMask set on the text input, the handler will only
382 be emitted if the input is in an acceptable state.579 be emitted if the input is in an acceptable state.
@@ -385,7 +582,6 @@
385582
386583
387 /*!584 /*!
388 \preliminary
389 Copies the currently selected text to the system clipboard.585 Copies the currently selected text to the system clipboard.
390 */586 */
391 function copy()587 function copy()
@@ -394,7 +590,6 @@
394 }590 }
395591
396 /*!592 /*!
397 \preliminary
398 Moves the currently selected text to the system clipboard.593 Moves the currently selected text to the system clipboard.
399 */594 */
400 function cut()595 function cut()
@@ -403,7 +598,6 @@
403 }598 }
404599
405 /*!600 /*!
406 \preliminary
407 Places the clipboard or the data given as parameter into the text input.601 Places the clipboard or the data given as parameter into the text input.
408 The selected text will be replaces with the data.602 The selected text will be replaces with the data.
409 */603 */
@@ -424,7 +618,6 @@
424 }618 }
425619
426 /*!620 /*!
427 \preliminary
428 Removes active text selection.621 Removes active text selection.
429 */622 */
430 function deselect()623 function deselect()
@@ -433,7 +626,13 @@
433 }626 }
434627
435 /*!628 /*!
436 \preliminary629 Inserts \a text into the TextField at \a position.
630 */
631 function insert(position, text) {
632 editor.insert(position, text);
633 }
634
635 /*!
437 This function returns the character position at x pixels from the left of636 This function returns the character position at x pixels from the left of
438 the TextField. Position 0 is before the first character, position 1 is after637 the TextField. Position 0 is before the first character, position 1 is after
439 the first character but before the second, and so on until position text.length,638 the first character but before the second, and so on until position text.length,
@@ -443,11 +642,12 @@
443 and for all x values after the last character this function returns text.length.642 and for all x values after the last character this function returns text.length.
444643
445 The cursor position type specifies how the cursor position should be resolved.644 The cursor position type specifies how the cursor position should be resolved.
446645 \list
447 - TextInput.CursorBetweenCharacters - Returns the position between characters646 \li - TextInput.CursorBetweenCharacters - Returns the position between characters
448 that is nearest x.647 that is nearest x.
449 - TextInput.CursorOnCharacter - Returns the position before the character that648 \li - TextInput.CursorOnCharacter - Returns the position before the character that
450 is nearest x.649 is nearest x.
650 \endlist
451 */651 */
452 function positionAt(x, position)652 function positionAt(x, position)
453 {653 {
@@ -458,7 +658,6 @@
458 }658 }
459659
460 /*!660 /*!
461 \preliminary
462 This function takes a character position and returns the rectangle that the661 This function takes a character position and returns the rectangle that the
463 cursor would occupy, if it was placed at that character position.662 cursor would occupy, if it was placed at that character position.
464663
@@ -471,7 +670,6 @@
471 }670 }
472671
473 /*!672 /*!
474 \preliminary
475 Causes the text from start to end to be selected.673 Causes the text from start to end to be selected.
476674
477 If either start or end is out of range, the selection is not changed.675 If either start or end is out of range, the selection is not changed.
@@ -485,7 +683,6 @@
485 }683 }
486684
487 /*!685 /*!
488 \preliminary
489 Causes all text to be selected.686 Causes all text to be selected.
490 */687 */
491 function selectAll()688 function selectAll()
@@ -494,7 +691,6 @@
494 }691 }
495692
496 /*!693 /*!
497 \preliminary
498 Causes the word closest to the current cursor position to be selected.694 Causes the word closest to the current cursor position to be selected.
499 */695 */
500 function selectWord()696 function selectWord()
@@ -511,9 +707,86 @@
511 internal.activateEditor();707 internal.activateEditor();
512 }708 }
513709
710 /*!
711 Returns true if the natural reading direction of the editor text found between
712 positions start and end is right to left.
713 */
714 function isRightToLeft(start, end) {
715 return editor.isRightToLeft(start, end);
716 }
717
718 /*!
719 Moves the cursor to position and updates the selection according to the
720 optional mode parameter. (To only move the cursor, set the cursorPosition property.)
721
722 When this method is called it additionally sets either the selectionStart
723 or the selectionEnd (whichever was at the previous cursor position) to the
724 specified position. This allows you to easily extend and contract the selected
725 text range.
726
727 The selection mode specifies whether the selection is updated on a per character
728 or a per word basis. If not specified the selection mode will default to
729 TextInput.SelectCharacters.
730 \list
731 \li - TextInput.SelectCharacters - Sets either the selectionStart or selectionEnd
732 (whichever was at the previous cursor position) to the specified position.
733 \li - TextInput.SelectWords - Sets the selectionStart and selectionEnd to
734 include all words between the specified position and the previous cursor
735 position. Words partially in the range are included.
736 \endlist
737
738 For example, take this sequence of calls:
739 \code
740 cursorPosition = 5
741 moveCursorSelection(9, TextInput.SelectCharacters)
742 moveCursorSelection(7, TextInput.SelectCharacters)
743 \endcode
744 This moves the cursor to position 5, extend the selection end from 5 to 9
745 and then retract the selection end from 9 to 7, leaving the text from position
746 5 to 7 selected (the 6th and 7th characters).
747
748 The same sequence with TextInput.SelectWords will extend the selection
749 start to a word boundary before or on position 5 and extend the selection
750 end to a word boundary on or past position 9.
751 */
752 function moveCursorSelection(position, mode) {
753 editor.moveCursorSelection(position, mode)
754 }
755
756 /*!
757 Redoes the last operation if redo is \l {canRedo}{available}.
758 */
759 function redo() {
760 editor.redo();
761 }
762
763 /*!
764 Undoes the last operation if undo is \l {canUndo}{available}. Deselects any current
765 selection, and updates the selection start to the current cursor position.
766 */
767 function undo() {
768 editor.undo();
769 }
770
771 /*!
772 Removes the section of text that is between the start and end positions from the TextField.
773 */
774 function remove(start, end) {
775 editor.remove(start, end);
776 }
777
778 /*!
779 Returns the section of text that is between the start and end positions.
780
781 If the TextField has an inputMask the length will include mask characters.
782 */
783 function getText(start, end) {
784 return editor.getText(start, end);
785 }
786
514 // internals787 // internals
515788
516 /*! internal */789 /*! \internal */
517 onVisibleChanged: {790 onVisibleChanged: {
518 if (!visible)791 if (!visible)
519 control.focus = false;792 control.focus = false;
520793
=== modified file 'tests/unit_x11/tst_components/tst_textfield.qml'
--- tests/unit_x11/tst_components/tst_textfield.qml 2013-06-04 09:42:07 +0000
+++ tests/unit_x11/tst_components/tst_textfield.qml 2013-07-03 10:36:26 +0000
@@ -65,6 +65,8 @@
65 function initTestCase() {65 function initTestCase() {
66 textField.forceActiveFocus();66 textField.forceActiveFocus();
67 compare(textField.focus, true, "TextField is focused");67 compare(textField.focus, true, "TextField is focused");
68 // clear clipboard
69 Clipboard.clear();
68 }70 }
6971
70 function test_0_popover() {72 function test_0_popover() {
@@ -79,14 +81,64 @@
79 compare(textField.acceptableInput,true,"acceptableInput true by default")81 compare(textField.acceptableInput,true,"acceptableInput true by default")
80 }82 }
8183
84 function test_0_activeFocusOnPress() {
85 compare(textField.activeFocusOnPress, true,"activeFocusOnPress true by default")
86 }
87
88 function test_0_autoScroll() {
89 compare(textField.autoScroll, true,"autoScroll true by default")
90 }
91
92 function test_0_canPaste() {
93 compare(textField.canPaste, false,"calPaste false when clipboard is empty")
94 }
95
96 function test_0_canRedo() {
97 compare(textField.canRedo, false,"calRedo false when no data was entered")
98 }
99
100 function test_0_canUndo() {
101 compare(textField.canUndo, false,"calUndo false when no data entered")
102 }
103
104 function test_0_color() {
105 compare(textField.color, "#000000","color #000000 by default")
106 }
107
108 function test_0_contentWidth() {
109 compare(textField.contentWidth, 0,"contentWidth by default")
110 }
111
112 function test_0_contentHeight() {
113 // line size is the font pixel size + 3 dp
114 var lineSize = textField.font.pixelSize + units.dp(3)
115 compare(textField.contentHeight, lineSize,"contentHeight by default")
116 }
117
118 function test_0_cursorDelegate() {
119 verify(textField.cursorDelegate, "cursorDelegate set by default")
120 }
121
82 function test_0_cursorPosition() {122 function test_0_cursorPosition() {
83 compare(textField.cursorPosition,0,"cursorPosition 0 by default")123 compare(textField.cursorPosition, 0, "cursorPosition 0 by default")
124 }
125
126 function test_0_cursorRectangle() {
127 compare(textField.cursorRectangle, Qt.rect(0, 0, 0, 0), "cursorRectangle 0 by default")
128 }
129
130 function test_0_cursorVisible() {
131 compare(textField.cursorVisible, true, "cursorVisible true by default")
84 }132 }
85133
86 function test_0_customSoftwareInputPanel() {134 function test_0_customSoftwareInputPanel() {
87 compare(textField.customSoftwareInputPanel,null,"customSoftwareInputPanel is null by default")135 compare(textField.customSoftwareInputPanel,null,"customSoftwareInputPanel is null by default")
88 }136 }
89137
138 function test_0_displayText() {
139 compare(textField.displayText, "", "displayText empty by default")
140 }
141
90 function test_0_echoMode() {142 function test_0_echoMode() {
91 compare(textField.echoMode, TextInput.Normal,"echoMode is TextInput.Normal by default")143 compare(textField.echoMode, TextInput.Normal,"echoMode is TextInput.Normal by default")
92 }144 }
@@ -101,6 +153,12 @@
101 verify((textField.font),"font is set")153 verify((textField.font),"font is set")
102 }154 }
103155
156 function test_0_alignments() {
157 compare(textField.horizontalAlignment, TextInput.AlignLeft, "horizontalAlignmen is Left by default")
158 compare(textField.effectiveHorizontalAlignment, TextInput.AlignLeft, "effectiveHorizontalAlignmen is Left by default")
159 compare(textField.verticalAlignment, TextInput.AlignTop, "verticalAlignmen is Top by default")
160 }
161
104 function test_hasClearButton() {162 function test_hasClearButton() {
105 compare(textField.hasClearButton, true, "hasClearButton is false by default")163 compare(textField.hasClearButton, true, "hasClearButton is false by default")
106 textField.hasClearButton = false164 textField.hasClearButton = false
@@ -119,10 +177,42 @@
119 compare(textField.inputMethodHints, Qt.ImhNone, "inputMethodHints is Qt.ImhNone by default")177 compare(textField.inputMethodHints, Qt.ImhNone, "inputMethodHints is Qt.ImhNone by default")
120 }178 }
121179
180 function test_0_length() {
181 compare(textField.length, 0, "length is 0 by default")
182 }
183
122 function test_0_maximumLength() {184 function test_0_maximumLength() {
123 compare(textField.maximumLength, 32767, "maximumLength is 32767 by default")185 compare(textField.maximumLength, 32767, "maximumLength is 32767 by default")
124 }186 }
125187
188 function test_0_mouseSelectionMode() {
189 compare(textField.mouseSelectionMode, TextInput.SelectCharacters, "mouseSelectionMode default")
190 }
191
192 function test_0_passwordCharacter() {
193 compare(textField.passwordCharacter, "\u2022", "passwordCharacter default")
194 }
195
196 function test_0_persistentSelection() {
197 compare(textField.persistentSelection, false, "persistentSelection default")
198 }
199
200 function test_0_renderType() {
201 compare(textField.renderType, Text.QtRendering, "renderType default")
202 }
203
204 function test_0_selectByMouse() {
205 compare(textField.selectByMouse, true, "selectByMouse default")
206 }
207
208 function test_0_selectedTextColor() {
209 compare(textField.selectedTextColor, "#f3f3e7", "selectedTextColor default")
210 }
211
212 function test_0_selectionColor() {
213 compare(textField.selectionColor, "#19b6ee", "selectionColor default")
214 }
215
126 function test_0_placeholderText() {216 function test_0_placeholderText() {
127 compare(textField.placeholderText, "", "placeholderText is '' by default")217 compare(textField.placeholderText, "", "placeholderText is '' by default")
128 }218 }
@@ -197,6 +287,64 @@
197 compare(textField.keyReleaseData, Qt.Key_Control, "Key release filtered");287 compare(textField.keyReleaseData, Qt.Key_Control, "Key release filtered");
198 }288 }
199289
290 function test_1_undo_redo() {
291 textField.readOnly = false;
292 textField.text = "";
293 textField.focus = true;
294 keyClick(Qt.Key_T); keyClick(Qt.Key_E); keyClick(Qt.Key_S); keyClick(Qt.Key_T);
295 compare(textField.text, "test", "new text");
296 if (!textField.canUndo) expectFail("", "undo is not allowed in this input");
297 textField.undo();
298 compare(textField.text, "", "undone");
299 textField.redo();
300 compare(textField.text, "test", "redone");
301 }
302
303 function test_1_getText() {
304 textField.text = "this is a longer text";
305 compare(textField.getText(0, 10), "this is a ", "getText(0, 10)");
306 compare(textField.getText(10, 0), "this is a ", "getText(10, 0)");
307 compare(textField.getText(0), "", "getText(0)");
308 compare(textField.getText(4, 0), "this", "getText(4, 0)");
309 }
310
311 function test_1_removeText() {
312 textField.text = "this is a longer text";
313 textField.remove(0, 10);
314 compare(textField.text, "longer text", "remove(0, 10)");
315
316 textField.text = "this is a longer text";
317 textField.remove(10, 0);
318 compare(textField.text, "longer text", "remove(0, 10)");
319
320 textField.text = "this is a longer text";
321 textField.remove(0);
322 compare(textField.text, "this is a longer text", "remove(0)");
323
324 textField.text = "this is a longer text";
325 textField.remove(4, 0);
326 compare(textField.text, " is a longer text", "remove(4, 0)");
327
328 textField.text = "this is a longer text";
329 textField.select(0, 4);
330 textField.remove();
331 compare(textField.text, "this is a longer text", "select(0, 4) && remove()");
332 }
333
334 function test_1_moveCursorSelection() {
335 textField.text = "this is a longer text";
336 textField.cursorPosition = 5;
337 textField.moveCursorSelection(9, TextInput.SelectCharacters);
338 compare(textField.selectedText, "is a", "moveCursorSelection from 5 to 9, selecting the text");
339 }
340
341 function test_1_isRightToLeft() {
342 textField.text = "this is a longer text";
343 compare(textField.isRightToLeft(0), false, "isRightToLeft(0)");
344 compare(textField.isRightToLeft(0, 0), false, "isRightToLeft(0, 0)");
345 compare(textField.isRightToLeft(5, 10), false, "isRightToLeft(5, 10)");
346 }
347
200 function test_cut() {348 function test_cut() {
201 Clipboard.clear();349 Clipboard.clear();
202 textField.readOnly = false;350 textField.readOnly = false;

Subscribers

People subscribed via source and target branches

to status/vote changes: