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
1=== modified file 'components.api'
2--- components.api 2013-07-02 00:19:41 +0000
3+++ components.api 2013-07-03 10:36:26 +0000
4@@ -255,22 +255,40 @@
5 property alias secondaryItem
6 property bool errorHighlight
7 property alias acceptableInput
8+ property alias activeFocusOnPress
9+ property alias autoScroll
10+ property alias canPaste
11+ property alias canRedo
12+ property alias canUndo
13+ property alias color
14+ property alias contentHeight
15+ property alias contentWidth
16+ property alias cursorDelegate
17 property alias cursorPosition
18+ property alias cursorRectangle
19+ property alias cursorVisible
20+ property alias displayText
21 property alias echoMode
22 property alias font
23 property alias inputMask
24 property alias inputMethodComposing
25 property alias inputMethodHints
26+ property alias length
27 property alias maximumLength
28+ property alias mouseSelectionMode
29+ property alias persistentSelection
30 property alias readOnly
31- property alias selectedText
32+ property alias renderType
33+ property alias selectByMouse
34+ readonly property alias selectedText
35 property alias selectionStart
36 property alias selectionEnd
37 property alias text
38 property alias validator
39 property alias horizontalAlignment
40+ property alias effectiveHorizontalAlignment
41+ property alias verticalAlignment
42 property alias passwordCharacter
43- property alias color
44 property alias selectionColor
45 property alias selectedTextColor
46 signal accepted()
47@@ -278,12 +296,19 @@
48 function cut()
49 function paste(data)
50 function deselect()
51+ function insert(position, text)
52 function positionAt(x, position)
53 function positionToRectangle(pos)
54 function select(start, end)
55 function selectAll()
56 function selectWord()
57 function forceActiveFocus()
58+ function isRightToLeft(start, end)
59+ function moveCursorSelection(position, mode)
60+ function redo()
61+ function undo()
62+ function remove(start, end)
63+ function getText(start, end)
64 property alias __internal
65 modules/Ubuntu/Components/TextInputPopover.qml
66 ActionSelectionPopover
67
68=== modified file 'modules/Ubuntu/Components/TextField.qml'
69--- modules/Ubuntu/Components/TextField.qml 2013-06-27 15:20:12 +0000
70+++ modules/Ubuntu/Components/TextField.qml 2013-07-03 10:36:26 +0000
71@@ -85,7 +85,6 @@
72 property bool highlighted: focus
73
74 /*!
75- \preliminary
76 Text that appears when there is no focus and no content in the component.
77
78 \qmlproperty string placeholderText
79@@ -93,7 +92,6 @@
80 property alias placeholderText: hint.text
81
82 /*!
83- \preliminary
84 Specifies whether the control has a clear button or not.
85 */
86 property bool hasClearButton: true
87@@ -112,7 +110,6 @@
88 property var popover
89
90 /*!
91- \preliminary
92 Overlaid component that can be set for the fore side of the TextField,
93 e.g.showing a magnifier to implement search functionality.
94
95@@ -121,7 +118,6 @@
96 property alias primaryItem: leftPane.data
97
98 /*!
99- \preliminary
100 Overlaid component that can be set for the rear side of the TextField,
101 e.g.showing a CAPS LOCK or NUM LOCK indication. The overlaid components
102 will be placed right after the clear button.
103@@ -131,14 +127,12 @@
104 property alias secondaryItem: rightPane.data
105
106 /*!
107- \preliminary
108 Allows highlighting errors in the TextField.
109 */
110 property bool errorHighlight: !acceptableInput
111
112 // aliased properties from TextInput
113 /*!
114- \preliminary
115 This property is always true unless a validator or input mask has been set.
116 If a validator or input mask has been set, this property will only be true
117 if the current text is acceptable to the validator or input mask as a final
118@@ -149,7 +143,84 @@
119 property alias acceptableInput: editor.acceptableInput
120
121 /*!
122- \preliminary
123+ Whether the TextField should gain active focus on a mouse press. By default
124+ this is set to true.
125+
126+ \qmlproperty bool activeFocusOnPress
127+ */
128+ property alias activeFocusOnPress: editor.activeFocusOnPress
129+
130+ /*!
131+ Whether the TextField should scroll when the text is longer than the width.
132+ By default this is set to true.
133+
134+ \qmlproperty bool autoScroll
135+ */
136+ property alias autoScroll: editor.autoScroll
137+
138+ /*!
139+ Returns true if the TextField is writable and the content of the clipboard
140+ is suitable for pasting into the TextField.
141+
142+ \qmlproperty bool canPaste
143+ */
144+ property alias canPaste: editor.canPaste
145+
146+ /*!
147+ Returns true if the TextField is writable and there are undone operations
148+ that can be redone.
149+
150+ \qmlproperty bool canRedo
151+ */
152+ property alias canRedo: editor.canRedo
153+
154+ /*!
155+ Returns true if the TextField is writable and there are previous operations
156+ that can be undone.
157+
158+ \qmlproperty bool canUndo
159+ */
160+ property alias canUndo: editor.canUndo
161+
162+ /*!
163+ The text color.
164+ \qmlproperty color color
165+ */
166+ property alias color: editor.color
167+
168+ /*!
169+ Returns the height of the text, including the height past the height that
170+ is covered if the text does not fit within the set height.
171+
172+ \qmlproperty real contentHeight
173+ */
174+ property alias contentHeight: editor.contentHeight
175+
176+ /*!
177+ Returns the width of the text, including the width past the width which
178+ is covered due to insufficient wrapping if wrapMode is set.
179+
180+ \qmlproperty real contentWidth
181+ */
182+ property alias contentWidth: editor.contentWidth
183+
184+ /*!
185+ The delegate for the cursor in the TextField.
186+
187+ If you set a cursorDelegate for a TextField, this delegate will be used for
188+ drawing the cursor instead of the standard cursor. An instance of the delegate
189+ will be created and managed by the TextField when a cursor is needed, and
190+ the x property of delegate instance will be set so as to be one pixel before
191+ the top left of the current character.
192+
193+ Note that the root item of the delegate component must be a QQuickItem or
194+ QQuickItem derived item.
195+
196+ \qmlproperty Component cursorDelegate
197+ */
198+ property alias cursorDelegate: editor.cursorDelegate
199+
200+ /*!
201 The position of the cursor in the TextField.
202
203 \qmlproperty int cursorPosition
204@@ -157,21 +228,70 @@
205 property alias cursorPosition: editor.cursorPosition
206
207 /*!
208- \preliminary
209+ The rectangle where the standard text cursor is rendered within the text
210+ input. Read only.
211+
212+ The position and height of a custom cursorDelegate are updated to follow
213+ the cursorRectangle automatically when it changes. The width of the delegate
214+ is unaffected by changes in the cursor rectangle.
215+
216+ \qmlproperty rectangle cursorRectangle
217+ */
218+ property alias cursorRectangle: editor.cursorRectangle
219+
220+ /*!
221+ Set to true when the TextField shows a cursor.
222+
223+ This property is set and unset when the TextField gets active focus, so that
224+ other properties can be bound to whether the cursor is currently showing.
225+ As it gets set and unset automatically, when you set the value yourself you
226+ must keep in mind that your value may be overwritten.
227+
228+ It can be set directly in script, for example if a KeyProxy might forward keys
229+ to it and you desire it to look active when this happens (but without actually
230+ giving it active focus).
231+
232+ It should not be set directly on the item, like in the below QML, as the specified
233+ value will be overridden an lost on focus changes.
234+ \qml
235+ TextField {
236+ text: "Text"
237+ cursorVisible: false
238+ }
239+ \endqml
240+ In the above snippet the cursor will still become visible when the TextField
241+ gains active focus.
242+
243+ \qmlproperty bool cursorVisible
244+ */
245+ property alias cursorVisible: editor.cursorVisible
246+
247+ /*!
248+ This is the text displayed in the TextField.
249+
250+ If echoMode is set to TextInput::Normal, this holds the same value as the
251+ \l text property. Otherwise, this property holds the text visible to the
252+ user, while the text property holds the actual entered text.
253+
254+ \qmlproperty string displayText
255+ */
256+ property alias displayText: editor.displayText
257+
258+ /*!
259 Specifies how the text should be displayed in the TextField.
260-
261- - TextInput.Normal - Displays the text as it is. (Default)
262- - TextInput.Password - Displays asterixes instead of characters.
263- - TextInput.NoEcho - Displays nothing.
264- - TextInput.PasswordEchoOnEdit - Displays characters as they are entered while
265+ \list
266+ \li - TextInput.Normal - Displays the text as it is. (Default)
267+ \li - TextInput.Password - Displays asterixes instead of characters.
268+ \li - TextInput.NoEcho - Displays nothing.
269+ \li - TextInput.PasswordEchoOnEdit - Displays characters as they are entered while
270 editing, otherwise displays asterisks.
271+ \endlist
272
273- \qmlproperty enumeration echoMode
274+ \qmlproperty enumeration echoMode
275 */
276 property alias echoMode: editor.echoMode
277
278 /*!
279- \preliminary
280 Font used in the TextField.
281
282 \qmlproperty font font
283@@ -179,7 +299,6 @@
284 property alias font: editor.font
285
286 /*!
287- \preliminary
288 Allows you to set an input mask on the TextField, restricting the text
289 inputs. See QLineEdit::inputMask for further details, as the exact same mask strings
290 are used by TextField.
291@@ -189,7 +308,6 @@
292 property alias inputMask: editor.inputMask
293
294 /*!
295- \preliminary
296 This property holds whether the TextInput has partial text input from an input method.
297
298 While it is composing an input method may rely on mouse or key events from the
299@@ -202,7 +320,6 @@
300 property alias inputMethodComposing: editor.inputMethodComposing
301
302 /*!
303- \preliminary
304 Provides hints to the input method about the expected content of the text input and how it
305 should operate.
306
307@@ -211,37 +328,37 @@
308 Flags that alter behaviour are:
309
310 \list
311- \li Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.
312+ \li - Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.
313 This is automatically set when setting echoMode to \c TextInput.Password.
314- \li Qt.ImhSensitiveData - Typed text should not be stored by the active input method
315+ \li - Qt.ImhSensitiveData - Typed text should not be stored by the active input method
316 in any persistent storage like predictive user dictionary.
317- \li Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case
318+ \li - Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case
319 when a sentence ends.
320- \li Qt.ImhPreferNumbers - Numbers are preferred (but not required).
321- \li Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).
322- \li Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).
323- \li Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.
324+ \li - Qt.ImhPreferNumbers - Numbers are preferred (but not required).
325+ \li - Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).
326+ \li - Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).
327+ \li - Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.
328
329- \li Qt.ImhDate - The text editor functions as a date field.
330- \li Qt.ImhTime - The text editor functions as a time field.
331+ \li - Qt.ImhDate - The text editor functions as a date field.
332+ \li - Qt.ImhTime - The text editor functions as a time field.
333 \endlist
334
335 Flags that restrict input (exclusive flags) are:
336
337 \list
338- \li Qt.ImhDigitsOnly - Only digits are allowed.
339- \li Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign.
340- \li Qt.ImhUppercaseOnly - Only upper case letter input is allowed.
341- \li Qt.ImhLowercaseOnly - Only lower case letter input is allowed.
342- \li Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed.
343- \li Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed.
344- \li Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed.
345+ \li - Qt.ImhDigitsOnly - Only digits are allowed.
346+ \li - Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign.
347+ \li - Qt.ImhUppercaseOnly - Only upper case letter input is allowed.
348+ \li - Qt.ImhLowercaseOnly - Only lower case letter input is allowed.
349+ \li - Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed.
350+ \li - Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed.
351+ \li - Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed.
352 \endlist
353
354 Masks:
355
356 \list
357- \li Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.
358+ \li - Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.
359 \endlist
360
361 \qmlproperty enumeration inputMethodHints
362@@ -249,7 +366,20 @@
363 property alias inputMethodHints: editor.inputMethodHints
364
365 /*!
366- \preliminary
367+ Returns the total number of characters in the TextField item.
368+
369+ If the TextField has an inputMask the length will include mask characters
370+ and may differ from the length of the string returned by the text property.
371+
372+ This property can be faster than querying the length the text property as
373+ it doesn't require any copying or conversion of the TextField's internal
374+ string data.
375+
376+ \qmlproperty int length
377+ */
378+ property alias length: editor.length
379+
380+ /*!
381 The maximum permitted length of the text in the TextField.
382
383 If the text is too long, it is truncated at the limit.
384@@ -261,7 +391,27 @@
385 property alias maximumLength: editor.maximumLength
386
387 /*!
388- \preliminary
389+ Specifies how text should be selected using a mouse.
390+ \list
391+ \li -TextInput.SelectCharacters - The selection is updated with individual
392+ characters. (Default)
393+ \li -TextInput.SelectWords - The selection is updated with whole words.
394+ \endlist
395+ This property only applies when selectByMouse is true.
396+
397+ \qmlproperty enumeration mouseSelectionMode
398+ */
399+ property alias mouseSelectionMode: editor.mouseSelectionMode
400+
401+ /*!
402+ Whether the TextField should keep its selection when it loses active focus
403+ to another item in the scene. By default this is set to false.
404+
405+ \qmlproperty bool persistentSelection
406+ */
407+ property alias persistentSelection: editor.persistentSelection
408+
409+ /*!
410 Sets whether user input can modify the contents of the TextField.
411
412 If readOnly is set to true, then user input will not affect the
413@@ -273,15 +423,48 @@
414 property alias readOnly: editor.readOnly
415
416 /*!
417+ Override the default rendering type for this component.
418+
419+ Supported render types are:
420+ \list
421+ \li - Text.QtRendering - (default)
422+ \li - Text.NativeRendering
423+ \endlist
424+
425+ Select Text.NativeRendering if you prefer text to look native on the target
426+ platform and do not require advanced features such as transformation of the
427+ text. Using such features in combination with the NativeRendering render type
428+ will lend poor and sometimes pixelated results.
429+
430+ \qmlproperty enumeration renderType
431+ */
432+ property alias renderType: editor.renderType
433+
434+ /*!
435+ Defaults to true.
436+
437+ If false, the user cannot use the mouse to select text, only can use it to
438+ focus the input.
439+
440+ \qmlproperty bool selectByMouse
441 \preliminary
442+ */
443+ property alias selectByMouse: virtualKbdHandler.enabled
444+
445+ /*!
446 This read-only property provides the text currently selected in the text input.
447
448+ It is equivalent to the following snippet, but is faster and easier to use.
449+ \code
450+ myTextInput.text.toString().substring(myTextInput.selectionStart,
451+ myTextInput.selectionEnd);
452+ \endcode
453+
454 \qmlproperty string selectedText
455 */
456- property alias selectedText: editor.selectedText
457+ readonly property alias selectedText: editor.selectedText
458
459 /*!
460- \preliminary
461 The cursor position before the first character in the current selection.
462
463 This property is read-only. To change the selection, use select(start,end),
464@@ -292,7 +475,6 @@
465 property alias selectionStart: editor.selectionStart
466
467 /*!
468- \preliminary
469 The cursor position after the last character in the current selection.
470
471 This property is read-only. To change the selection, use select(start,end),
472@@ -303,7 +485,6 @@
473 property alias selectionEnd: editor.selectionEnd
474
475 /*!
476- \preliminary
477 The text in the TextField.
478
479 \qmlproperty string text
480@@ -311,7 +492,6 @@
481 property alias text: editor.text
482
483 /*!
484- \preliminary
485 Allows you to set a validator on the TextInput. When a validator is set the
486 TextField will only accept input which leaves the text property in an acceptable
487 or intermediate state. The accepted signal will only be sent if the text is in
488@@ -323,23 +503,25 @@
489
490 \qml
491 import QtQuick 2.0
492- TextInput{
493+ import Ubuntu.Components 0.1
494+ TextField{
495 validator: IntValidator{bottom: 11; top: 31;}
496 focus: true
497 }
498 \endqml
499
500+ \sa acceptableInput, inputMask
501+
502 \qmlproperty Validator validator
503 */
504 property alias validator: editor.validator
505
506 /*!
507- \preliminary
508 Sets the horizontal alignment of the text within the item's width and height.
509 By default, the text alignment follows the natural alignment of the text, for
510 example text that is read from left to right will be aligned to the left.
511
512- TextInput does not have vertical alignment, as the natural height is exactly
513+ TextField does not have vertical alignment, as the natural height is exactly
514 the height of the single line of text. If you set the height manually to something
515 larger, TextInput will always be top aligned vertically. You can use anchors to
516 align it however you want within another item.
517@@ -347,36 +529,51 @@
518 The valid values for horizontalAlignment are TextInput.AlignLeft,
519 TextInput.AlignRight and TextInput.AlignHCenter.
520
521+ Valid values for verticalAlignment are TextInput.AlignTop (default), TextInput.AlignBottom
522+ TextInput.AlignVCenter.
523+
524+ When using the attached property LayoutMirroring::enabled to mirror application
525+ layouts, the horizontal alignment of text will also be mirrored. However,
526+ the property horizontalAlignment will remain unchanged. To query the effective
527+ horizontal alignment of TextField, use the read-only property effectiveHorizontalAlignment.
528+
529 \qmlproperty enumeration horizontalAlignment
530+ \qmlproperty enumeration effectiveHorizontalAlignment
531+ \qmlproperty enumeration verticalAlignment
532 */
533 property alias horizontalAlignment: editor.horizontalAlignment
534+ /*! \internal */
535+ property alias effectiveHorizontalAlignment: editor.effectiveHorizontalAlignment
536+ /*! \internal */
537+ property alias verticalAlignment: editor.verticalAlignment
538
539 /*!
540- \internal
541- FIXME: property added for styling purposes
542+ This is the character displayed when echoMode is set to Password or
543+ PasswordEchoOnEdit. By default it is the unicode character 2022.
544+
545+ If this property is set to a string with more than one character, the first
546+ character is used. If the string is empty, the value is ignored and the property
547+ is not set.
548+
549+ \qmlproperty string passwordCharacter
550 */
551 property alias passwordCharacter: editor.passwordCharacter
552
553 /*!
554- \internal
555- FIXME: property added for styling purposes
556- */
557- property alias color: editor.color
558+ The text highlight color, used behind selections.
559
560- /*!
561- \internal
562- FIXME: property added for styling purposes
563+ \qmlproperty color selectionColor
564 */
565 property alias selectionColor: editor.selectionColor
566
567 /*!
568- \internal
569- FIXME: property added for styling purposes
570+ The highlighted text color, used in selections.
571+
572+ \qmlproperty color selctedTextColor
573 */
574 property alias selectedTextColor: editor.selectedTextColor
575
576 /*!
577- \preliminary
578 This handler is called when the Return or Enter key is pressed. Note that if
579 there is a validator or inputMask set on the text input, the handler will only
580 be emitted if the input is in an acceptable state.
581@@ -385,7 +582,6 @@
582
583
584 /*!
585- \preliminary
586 Copies the currently selected text to the system clipboard.
587 */
588 function copy()
589@@ -394,7 +590,6 @@
590 }
591
592 /*!
593- \preliminary
594 Moves the currently selected text to the system clipboard.
595 */
596 function cut()
597@@ -403,7 +598,6 @@
598 }
599
600 /*!
601- \preliminary
602 Places the clipboard or the data given as parameter into the text input.
603 The selected text will be replaces with the data.
604 */
605@@ -424,7 +618,6 @@
606 }
607
608 /*!
609- \preliminary
610 Removes active text selection.
611 */
612 function deselect()
613@@ -433,7 +626,13 @@
614 }
615
616 /*!
617- \preliminary
618+ Inserts \a text into the TextField at \a position.
619+ */
620+ function insert(position, text) {
621+ editor.insert(position, text);
622+ }
623+
624+ /*!
625 This function returns the character position at x pixels from the left of
626 the TextField. Position 0 is before the first character, position 1 is after
627 the first character but before the second, and so on until position text.length,
628@@ -443,11 +642,12 @@
629 and for all x values after the last character this function returns text.length.
630
631 The cursor position type specifies how the cursor position should be resolved.
632-
633- - TextInput.CursorBetweenCharacters - Returns the position between characters
634+ \list
635+ \li - TextInput.CursorBetweenCharacters - Returns the position between characters
636 that is nearest x.
637- - TextInput.CursorOnCharacter - Returns the position before the character that
638+ \li - TextInput.CursorOnCharacter - Returns the position before the character that
639 is nearest x.
640+ \endlist
641 */
642 function positionAt(x, position)
643 {
644@@ -458,7 +658,6 @@
645 }
646
647 /*!
648- \preliminary
649 This function takes a character position and returns the rectangle that the
650 cursor would occupy, if it was placed at that character position.
651
652@@ -471,7 +670,6 @@
653 }
654
655 /*!
656- \preliminary
657 Causes the text from start to end to be selected.
658
659 If either start or end is out of range, the selection is not changed.
660@@ -485,7 +683,6 @@
661 }
662
663 /*!
664- \preliminary
665 Causes all text to be selected.
666 */
667 function selectAll()
668@@ -494,7 +691,6 @@
669 }
670
671 /*!
672- \preliminary
673 Causes the word closest to the current cursor position to be selected.
674 */
675 function selectWord()
676@@ -511,9 +707,86 @@
677 internal.activateEditor();
678 }
679
680+ /*!
681+ Returns true if the natural reading direction of the editor text found between
682+ positions start and end is right to left.
683+ */
684+ function isRightToLeft(start, end) {
685+ return editor.isRightToLeft(start, end);
686+ }
687+
688+ /*!
689+ Moves the cursor to position and updates the selection according to the
690+ optional mode parameter. (To only move the cursor, set the cursorPosition property.)
691+
692+ When this method is called it additionally sets either the selectionStart
693+ or the selectionEnd (whichever was at the previous cursor position) to the
694+ specified position. This allows you to easily extend and contract the selected
695+ text range.
696+
697+ The selection mode specifies whether the selection is updated on a per character
698+ or a per word basis. If not specified the selection mode will default to
699+ TextInput.SelectCharacters.
700+ \list
701+ \li - TextInput.SelectCharacters - Sets either the selectionStart or selectionEnd
702+ (whichever was at the previous cursor position) to the specified position.
703+ \li - TextInput.SelectWords - Sets the selectionStart and selectionEnd to
704+ include all words between the specified position and the previous cursor
705+ position. Words partially in the range are included.
706+ \endlist
707+
708+ For example, take this sequence of calls:
709+ \code
710+ cursorPosition = 5
711+ moveCursorSelection(9, TextInput.SelectCharacters)
712+ moveCursorSelection(7, TextInput.SelectCharacters)
713+ \endcode
714+ This moves the cursor to position 5, extend the selection end from 5 to 9
715+ and then retract the selection end from 9 to 7, leaving the text from position
716+ 5 to 7 selected (the 6th and 7th characters).
717+
718+ The same sequence with TextInput.SelectWords will extend the selection
719+ start to a word boundary before or on position 5 and extend the selection
720+ end to a word boundary on or past position 9.
721+ */
722+ function moveCursorSelection(position, mode) {
723+ editor.moveCursorSelection(position, mode)
724+ }
725+
726+ /*!
727+ Redoes the last operation if redo is \l {canRedo}{available}.
728+ */
729+ function redo() {
730+ editor.redo();
731+ }
732+
733+ /*!
734+ Undoes the last operation if undo is \l {canUndo}{available}. Deselects any current
735+ selection, and updates the selection start to the current cursor position.
736+ */
737+ function undo() {
738+ editor.undo();
739+ }
740+
741+ /*!
742+ Removes the section of text that is between the start and end positions from the TextField.
743+ */
744+ function remove(start, end) {
745+ editor.remove(start, end);
746+ }
747+
748+ /*!
749+ Returns the section of text that is between the start and end positions.
750+
751+ If the TextField has an inputMask the length will include mask characters.
752+ */
753+ function getText(start, end) {
754+ return editor.getText(start, end);
755+ }
756+
757 // internals
758
759- /*! internal */
760+ /*! \internal */
761 onVisibleChanged: {
762 if (!visible)
763 control.focus = false;
764
765=== modified file 'tests/unit_x11/tst_components/tst_textfield.qml'
766--- tests/unit_x11/tst_components/tst_textfield.qml 2013-06-04 09:42:07 +0000
767+++ tests/unit_x11/tst_components/tst_textfield.qml 2013-07-03 10:36:26 +0000
768@@ -65,6 +65,8 @@
769 function initTestCase() {
770 textField.forceActiveFocus();
771 compare(textField.focus, true, "TextField is focused");
772+ // clear clipboard
773+ Clipboard.clear();
774 }
775
776 function test_0_popover() {
777@@ -79,14 +81,64 @@
778 compare(textField.acceptableInput,true,"acceptableInput true by default")
779 }
780
781+ function test_0_activeFocusOnPress() {
782+ compare(textField.activeFocusOnPress, true,"activeFocusOnPress true by default")
783+ }
784+
785+ function test_0_autoScroll() {
786+ compare(textField.autoScroll, true,"autoScroll true by default")
787+ }
788+
789+ function test_0_canPaste() {
790+ compare(textField.canPaste, false,"calPaste false when clipboard is empty")
791+ }
792+
793+ function test_0_canRedo() {
794+ compare(textField.canRedo, false,"calRedo false when no data was entered")
795+ }
796+
797+ function test_0_canUndo() {
798+ compare(textField.canUndo, false,"calUndo false when no data entered")
799+ }
800+
801+ function test_0_color() {
802+ compare(textField.color, "#000000","color #000000 by default")
803+ }
804+
805+ function test_0_contentWidth() {
806+ compare(textField.contentWidth, 0,"contentWidth by default")
807+ }
808+
809+ function test_0_contentHeight() {
810+ // line size is the font pixel size + 3 dp
811+ var lineSize = textField.font.pixelSize + units.dp(3)
812+ compare(textField.contentHeight, lineSize,"contentHeight by default")
813+ }
814+
815+ function test_0_cursorDelegate() {
816+ verify(textField.cursorDelegate, "cursorDelegate set by default")
817+ }
818+
819 function test_0_cursorPosition() {
820- compare(textField.cursorPosition,0,"cursorPosition 0 by default")
821+ compare(textField.cursorPosition, 0, "cursorPosition 0 by default")
822+ }
823+
824+ function test_0_cursorRectangle() {
825+ compare(textField.cursorRectangle, Qt.rect(0, 0, 0, 0), "cursorRectangle 0 by default")
826+ }
827+
828+ function test_0_cursorVisible() {
829+ compare(textField.cursorVisible, true, "cursorVisible true by default")
830 }
831
832 function test_0_customSoftwareInputPanel() {
833 compare(textField.customSoftwareInputPanel,null,"customSoftwareInputPanel is null by default")
834 }
835
836+ function test_0_displayText() {
837+ compare(textField.displayText, "", "displayText empty by default")
838+ }
839+
840 function test_0_echoMode() {
841 compare(textField.echoMode, TextInput.Normal,"echoMode is TextInput.Normal by default")
842 }
843@@ -101,6 +153,12 @@
844 verify((textField.font),"font is set")
845 }
846
847+ function test_0_alignments() {
848+ compare(textField.horizontalAlignment, TextInput.AlignLeft, "horizontalAlignmen is Left by default")
849+ compare(textField.effectiveHorizontalAlignment, TextInput.AlignLeft, "effectiveHorizontalAlignmen is Left by default")
850+ compare(textField.verticalAlignment, TextInput.AlignTop, "verticalAlignmen is Top by default")
851+ }
852+
853 function test_hasClearButton() {
854 compare(textField.hasClearButton, true, "hasClearButton is false by default")
855 textField.hasClearButton = false
856@@ -119,10 +177,42 @@
857 compare(textField.inputMethodHints, Qt.ImhNone, "inputMethodHints is Qt.ImhNone by default")
858 }
859
860+ function test_0_length() {
861+ compare(textField.length, 0, "length is 0 by default")
862+ }
863+
864 function test_0_maximumLength() {
865 compare(textField.maximumLength, 32767, "maximumLength is 32767 by default")
866 }
867
868+ function test_0_mouseSelectionMode() {
869+ compare(textField.mouseSelectionMode, TextInput.SelectCharacters, "mouseSelectionMode default")
870+ }
871+
872+ function test_0_passwordCharacter() {
873+ compare(textField.passwordCharacter, "\u2022", "passwordCharacter default")
874+ }
875+
876+ function test_0_persistentSelection() {
877+ compare(textField.persistentSelection, false, "persistentSelection default")
878+ }
879+
880+ function test_0_renderType() {
881+ compare(textField.renderType, Text.QtRendering, "renderType default")
882+ }
883+
884+ function test_0_selectByMouse() {
885+ compare(textField.selectByMouse, true, "selectByMouse default")
886+ }
887+
888+ function test_0_selectedTextColor() {
889+ compare(textField.selectedTextColor, "#f3f3e7", "selectedTextColor default")
890+ }
891+
892+ function test_0_selectionColor() {
893+ compare(textField.selectionColor, "#19b6ee", "selectionColor default")
894+ }
895+
896 function test_0_placeholderText() {
897 compare(textField.placeholderText, "", "placeholderText is '' by default")
898 }
899@@ -197,6 +287,64 @@
900 compare(textField.keyReleaseData, Qt.Key_Control, "Key release filtered");
901 }
902
903+ function test_1_undo_redo() {
904+ textField.readOnly = false;
905+ textField.text = "";
906+ textField.focus = true;
907+ keyClick(Qt.Key_T); keyClick(Qt.Key_E); keyClick(Qt.Key_S); keyClick(Qt.Key_T);
908+ compare(textField.text, "test", "new text");
909+ if (!textField.canUndo) expectFail("", "undo is not allowed in this input");
910+ textField.undo();
911+ compare(textField.text, "", "undone");
912+ textField.redo();
913+ compare(textField.text, "test", "redone");
914+ }
915+
916+ function test_1_getText() {
917+ textField.text = "this is a longer text";
918+ compare(textField.getText(0, 10), "this is a ", "getText(0, 10)");
919+ compare(textField.getText(10, 0), "this is a ", "getText(10, 0)");
920+ compare(textField.getText(0), "", "getText(0)");
921+ compare(textField.getText(4, 0), "this", "getText(4, 0)");
922+ }
923+
924+ function test_1_removeText() {
925+ textField.text = "this is a longer text";
926+ textField.remove(0, 10);
927+ compare(textField.text, "longer text", "remove(0, 10)");
928+
929+ textField.text = "this is a longer text";
930+ textField.remove(10, 0);
931+ compare(textField.text, "longer text", "remove(0, 10)");
932+
933+ textField.text = "this is a longer text";
934+ textField.remove(0);
935+ compare(textField.text, "this is a longer text", "remove(0)");
936+
937+ textField.text = "this is a longer text";
938+ textField.remove(4, 0);
939+ compare(textField.text, " is a longer text", "remove(4, 0)");
940+
941+ textField.text = "this is a longer text";
942+ textField.select(0, 4);
943+ textField.remove();
944+ compare(textField.text, "this is a longer text", "select(0, 4) && remove()");
945+ }
946+
947+ function test_1_moveCursorSelection() {
948+ textField.text = "this is a longer text";
949+ textField.cursorPosition = 5;
950+ textField.moveCursorSelection(9, TextInput.SelectCharacters);
951+ compare(textField.selectedText, "is a", "moveCursorSelection from 5 to 9, selecting the text");
952+ }
953+
954+ function test_1_isRightToLeft() {
955+ textField.text = "this is a longer text";
956+ compare(textField.isRightToLeft(0), false, "isRightToLeft(0)");
957+ compare(textField.isRightToLeft(0, 0), false, "isRightToLeft(0, 0)");
958+ compare(textField.isRightToLeft(5, 10), false, "isRightToLeft(5, 10)");
959+ }
960+
961 function test_cut() {
962 Clipboard.clear();
963 textField.readOnly = false;

Subscribers

People subscribed via source and target branches

to status/vote changes: