Debian Codegraph @

src/imports/Components/1.2/TextArea.qml

raw
1 /*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.2 as Lomiri
19 import Lomiri.Components.Popups 1.0
20
21 /*!
22 \qmltype TextArea
23 \inqmlmodule Lomiri.Components
24 \ingroup lomiri
25 \brief The TextArea item displays a block of editable, scrollable, formatted
26 text.
27
28 The TextArea supports fix-size and auto-expanding modes. In fix-size mode the
29 content is scrolled when exceeds the boundaries and can be scrolled both horizontally
30 and vertically, depending on the contentWidth and contentHeight set. The following
31 example will scroll the editing area both horizontally and vertically:
32
33 \qml
34 TextArea {
35 width: units.gu(20)
36 height: units.gu(12)
37 contentWidth: units.gu(30)
38 contentHeight: units.gu(60)
39 }
40 \endqml
41
42 The auto-expand mode is realized using two properties: autoSize and maximumLineCount.
43 Setting autoSize will set implicitHeight to one line, and the height will follow
44 the line count, meaning when lines are added the area will expand and when
45 removed the area will shrink. The maximumLineCount specifies how much the
46 editor should be expanded. If this value is set to 0, the area will always
47 expand vertically to fit the content. When autoSize is set, the contentHeight
48 property value is ignored, and the expansion only happens vertically.
49
50 \qml
51 TextArea {
52 width: units.gu(20)
53 height: units.gu(12)
54 contentWidth: units.gu(30)
55 autoSize: true
56 maximumLineCount: 0
57 }
58 \endqml
59
60 TextArea comes with 30 grid-units implicit width and one line height on auto-sizing
61 mode and 4 lines on fixed-mode. The line size is calculated from the font size and the
62 ovarlay and frame spacing specified in the style.
63
64 \section2 Scrolling and text selection
65 The input is activated when the tap or mouse is released after being pressed
66 over the component.
67
68 Scrolling the editing area can happen when the size is fixed or in auto-sizing mode when
69 the content size is bigger than the visible area. The scrolling is realized by swipe
70 gestures, or by navigating the cursor.
71
72 The content can be selected in the following ways:
73 \list
74 \li - double tapping/left mouse clicking over the content, when the word that
75 had been tapped over will be selected
76 \li - by pressing and dragging the selection cursor over the text input. Note
77 that there has to be a delay of approx. 200 ms between the press and drag
78 gesture, time when the input switches from scroll mode to selection mode
79 \endlist
80
81 The input is focused (activated) upon tap/left mouse button release. The cursor
82 will be placed at the position the mouse/tap point at release time. If the click
83 is happening on a selected area, the selection will be cleared. Long press above
84 a selected area brings up the clipboard context menu. When the long press happens
85 over a non-selected area, the cursor will be moved to the position and the component
86 enters in selection mode. The selection mode can also be activated by tapping and
87 keeping the tap/mouse over for approx 300 ms. If there is a move during this time,
88 the component enters into scrolling mode. The mode is exited once the scrolling
89 finishes. During the scrolling mode the selected text is preserved.
90
91 \note During text selection all interactive parent Flickables are turned off.
92 */
93
94 Lomiri.StyledItem {
95 id: control
96 implicitWidth: units.gu(30)
97 implicitHeight: (autoSize) ? internal.minimumSize : internal.linesHeight(4)
98
99 // new properties
100 /*!
101 The property presents whether the TextArea is highlighted or not. By
102 default the TextArea gets highlighted when gets the focus, so can accept
103 text input. This property allows to control the highlight separately from
104 the focused behavior.
105 */
106 property bool highlighted: focus
107 /*!
108 Text that appears when there is no focus and no content in the component
109 (hint text).
110
111 \qmlproperty string placeholderText
112 */
113 property alias placeholderText: hint.text
114
115 /*!
116 This property contains the text that is displayed on the screen. May differ
117 from the text property value when TextEdit.RichText format is selected.
118
119 \qmlproperty string displayText
120 */
121 readonly property alias displayText: internal.displayText
122
123 /*!
124 The property drives whether text selection should happen with the mouse or
125 not. The default value is true.
126 \qmlproperty bool selectByMouse
127 */
128 property alias selectByMouse: editor.selectByMouse
129
130 /*!
131 \deprecated
132 This property specifies whether the text area expands following the entered
133 text or not. The default value is false.
134 The property is deprecated, use autoSize instead
135 */
136 property bool autoExpand
137 /*! \internal */
138 onAutoExpandChanged: console.debug("WARNING: autoExpand deprecated, use autoSize instead.")
139
140 /*!
141 This property specifies whether the text area sizes following the line count
142 or not. The default value is false.
143 */
144 property bool autoSize: false
145
146 /*!
147 The property holds the maximum amount of lines to expand when autoSize is
148 enabled. The value of 0 does not put any upper limit and the control will
149 expand forever.
150
151 The default value is 5 lines.
152 */
153 property int maximumLineCount: 5
154
155 // altered TextEdit properties
156 /*!
157 The property folds the width of the text editing content. This can be equal or
158 bigger than the frame width minus the spacing between the frame and the input
159 area defined in the current theme. The default value is the same as the visible
160 input area's width.
161 */
162 property real contentWidth: control.width - 2 * internal.frameSpacing
163
164 /*!
165 The property folds the height of the text editing content. This can be equal or
166 bigger than the frame height minus the spacing between the frame and the input
167 area defined in the current theme. The default value is the same as the visible
168 input area's height.
169 */
170 property real contentHeight: control.height - 2 * internal.frameSpacing
171
172 /*!
173 The property overrides the default popover of the TextArea. When set, the
174 TextArea will open the given popover instead of the default one defined.
175 The popover can either be a component or a URL to be loaded.
176 */
177 property var popover
178
179 // forwarded properties
180 /*!
181 Whether the TextArea should gain active focus on a mouse press. By default this
182 is set to true.
183 \qmlproperty bool activeFocusOnPress
184 */
185 property alias activeFocusOnPress: editor.activeFocusOnPress
186
187 /*!
188 This property specifies a base URL which is used to resolve relative URLs within
189 the text. The default value is the url of the QML file instantiating the TextArea
190 item.
191
192 \qmlproperty url baseUrl
193 */
194 property alias baseUrl: editor.baseUrl
195
196 /*!
197 Returns true if the TextArea is writable and the content of the clipboard is
198 suitable for pasting into the TextArea.
199
200 \qmlproperty bool canPaste
201 */
202 property alias canPaste: editor.canPaste
203
204 /*!
205 Returns true if the TextArea is writable and there are undone operations that
206 can be redone.
207
208 \qmlproperty bool canRedo
209 */
210 property alias canRedo: editor.canRedo
211
212 /*!
213 Returns true if the TextArea is writable and there are previous operations
214 that can be undone.
215
216 \qmlproperty bool canUndo
217 */
218 property alias canUndo: editor.canUndo
219
220 /*!
221 The text color.
222
223 \qmlproperty color color
224 */
225 property alias color: editor.color
226
227 /*!
228 The delegate for the cursor in the TextArea.
229
230 If you set a cursorDelegate for a TextArea, this delegate will be used for
231 drawing the cursor instead of the standard cursor. An instance of the delegate
232 will be created and managed by the text edit when a cursor is needed, and
233 the x and y properties of delegate instance will be set so as to be one pixel
234 before the top left of the current character.
235
236 Note that the root item of the delegate component must be a QQuickItem or
237 QQuickItem derived item.
238 */
239 property Component cursorDelegate: null
240
241 /*!
242 The position of the cursor in the TextArea.
243
244 \qmlproperty int cursorPosition
245 */
246 property alias cursorPosition: editor.cursorPosition
247
248 /*!
249 The rectangle where the standard text cursor is rendered within the text
250 edit. Read-only.
251
252 The position and height of a custom cursorDelegate are updated to follow
253 the cursorRectangle automatically when it changes. The width of the delegate
254 is unaffected by changes in the cursor rectangle.
255
256 \qmlproperty rectangle cursorRectangle
257 */
258 property alias cursorRectangle: editor.cursorRectangle
259
260 /*!
261 If true the text edit shows a cursor.
262
263 This property is set and unset when the text edit gets active focus, but it
264 can also be set directly (useful, for example, if a KeyProxy might forward
265 keys to it).
266
267 \qmlproperty bool cursorVisible
268 */
269 property alias cursorVisible: editor.cursorVisible
270
271 /*!
272 Presents the effective horizontal alignment that can be different from the one
273 specified at horizontalAlignment due to layout mirroring.
274
275 \qmlproperty enumeration effectiveHorizontalAlignment
276 */
277 property alias effectiveHorizontalAlignment: editor.effectiveHorizontalAlignment
278
279 /*!
280 The property holds the font used by the editing.
281
282 \qmlproperty font font
283 */
284 property alias font: editor.font
285
286 /*!
287 Sets the horizontal alignment of the text within the TextAre item's width
288 and height. By default, the text alignment follows the natural alignment
289 of the text, for example text that is read from left to right will be
290 aligned to the left.
291
292 Valid values for effectiveHorizontalAlignment are:
293 \list
294 \li TextEdit.AlignLeft (default)
295 \li TextEdit.AlignRight
296 \li TextEdit.AlignHCenter
297 \li TextEdit.AlignJustify
298 \endlist
299
300 \qmlproperty enumeration horizontalAlignment
301 */
302 property alias horizontalAlignment: editor.horizontalAlignment
303
304 /*!
305 This property holds whether the TextArea has partial text input from an
306 input method.
307
308 While it is composing an input method may rely on mouse or key events
309 from the TextArea to edit or commit the partial text. This property can
310 be used to determine when to disable events handlers that may interfere
311 with the correct operation of an input method.
312
313 \qmlproperty bool inputMethodComposing
314 */
315 property alias inputMethodComposing: editor.inputMethodComposing
316
317 /*!
318 Provides hints to the input method about the expected content of the text
319 edit and how it should operate.
320
321 The value is a bit-wise combination of flags or Qt.ImhNone if no hints are set.
322
323 Flags that alter behaviour are:
324 \list
325 \li Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords.
326 \li Qt.ImhSensitiveData - Typed text should not be stored by the active input method in any persistent storage like predictive user dictionary.
327 \li Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case when a sentence ends.
328 \li Qt.ImhPreferNumbers - Numbers are preferred (but not required).
329 \li Qt.ImhPreferUppercase - Upper case letters are preferred (but not required).
330 \li Qt.ImhPreferLowercase - Lower case letters are preferred (but not required).
331 \li Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing.
332 \li Qt.ImhDate - The text editor functions as a date field.
333 \li Qt.ImhTime - The text editor functions as a time field.
334 \endlist
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 \endlist
346 Masks:
347
348 \list
349 \li Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used.
350 \endlist
351
352 \qmlproperty enumeration inputMethodHints
353 */
354 property alias inputMethodHints: editor.inputMethodHints
355
356 /*!
357 Returns the total number of plain text characters in the TextArea item.
358
359 As this number doesn't include any formatting markup it may not be the
360 same as the length of the string returned by the text property.
361
362 This property can be faster than querying the length the text property
363 as it doesn't require any copying or conversion of the TextArea's internal
364 string data.
365
366 \qmlproperty int length
367 */
368 property alias length: editor.length
369
370 /*!
371 Returns the total number of lines in the TextArea item.
372
373 \qmlproperty int lineCount
374 */
375 property alias lineCount: editor.lineCount
376
377 /*!
378 Specifies how text should be selected using a mouse.
379 \list
380 \li TextEdit.SelectCharacters - The selection is updated with individual characters. (Default)
381 \li TextEdit.SelectWords - The selection is updated with whole words.
382 \endlist
383 This property only applies when selectByMouse is true.
384
385 \qmlproperty enumeration mouseSelectionMode
386 */
387 property alias mouseSelectionMode: editor.mouseSelectionMode
388
389 /*!
390 Whether the TextArea should keep the selection visible when it loses active
391 focus to another item in the scene. By default this is set to true;
392
393 \qmlproperty enumeration persistentSelection
394 */
395 property alias persistentSelection: editor.persistentSelection
396
397 /*!
398 Whether the user can interact with the TextArea item. If this property is set
399 to true the text cannot be edited by user interaction.
400
401 By default this property is false.
402
403 \qmlproperty bool readOnly
404 */
405 property alias readOnly: editor.readOnly
406
407 /*!
408 Override the default rendering type for this component.
409
410 Supported render types are:
411 \list
412 \li Text.QtRendering - the default
413 \li Text.NativeRendering
414 \endlist
415 Select Text.NativeRendering if you prefer text to look native on the target
416 platform and do not require advanced features such as transformation of the
417 text. Using such features in combination with the NativeRendering render type
418 will lend poor and sometimes pixelated results.
419
420 \qmlproperty enumeration renderType
421 */
422 property alias renderType: editor.renderType
423
424 /*!
425 This read-only property provides the text currently selected in the text edit.
426
427 \qmlproperty string selectedText
428 */
429 property alias selectedText: editor.selectedText
430
431 /*!
432 The selected text color, used in selections.
433
434 \qmlproperty color selectedTextColor
435 */
436 property alias selectedTextColor: editor.selectedTextColor
437
438 /*!
439 The text highlight color, used behind selections.
440
441 \qmlproperty color selectionColor
442 */
443 property alias selectionColor: editor.selectionColor
444
445 /*!
446 The cursor position after the last character in the current selection.
447
448 This property is read-only. To change the selection, use select(start, end),
449 selectAll(), or selectWord().
450
451 See also selectionStart, cursorPosition, and selectedText.
452
453 \qmlproperty int selectionEnd
454 */
455 property alias selectionEnd: editor.selectionEnd
456
457 /*!
458 The cursor position before the first character in the current selection.
459
460 This property is read-only. To change the selection, use select(start, end),
461 selectAll(), or selectWord().
462
463 See also selectionEnd, cursorPosition, and selectedText.
464
465 \qmlproperty int selectionStart
466 */
467 property alias selectionStart: editor.selectionStart
468
469 /*!
470 The text to display. If the text format is AutoText the text edit will
471 automatically determine whether the text should be treated as rich text.
472 This determination is made using Qt::mightBeRichText().
473
474 \qmlproperty string text
475 */
476 property alias text: editor.text
477
478 /*!
479 The way the text property should be displayed.
480 \list
481 \li TextEdit.AutoText
482 \li TextEdit.PlainText
483 \li TextEdit.RichText
484 \endlist
485 The default is TextEdit.PlainText. If the text format is TextEdit.AutoText
486 the text edit will automatically determine whether the text should be treated
487 as rich text. This determination is made using Qt::mightBeRichText().
488
489 \qmlproperty enumeration textFormat
490 */
491 property alias textFormat: editor.textFormat
492
493 /*!
494 Sets the vertical alignment of the text within the TextAres item's width
495 and height. By default, the text alignment follows the natural alignment
496 of the text.
497
498 Valid values for verticalAlignment are:
499
500 \list
501 \li TextEdit.AlignTop (default)
502 \li TextEdit.AlignBottom
503 \li TextEdit.AlignVCenter
504 \endlist
505
506 \qmlproperty enumeration verticalAlignment
507 */
508 property alias verticalAlignment: editor.verticalAlignment
509
510 /*!
511 Set this property to wrap the text to the TextEdit item's width. The text
512 will only wrap if an explicit width has been set.
513 \list
514 \li TextEdit.NoWrap - no wrapping will be performed. If the text contains
515 insufficient newlines, then implicitWidth will exceed a set width.
516 \li TextEdit.WordWrap - wrapping is done on word boundaries only. If a word
517 is too long, implicitWidth will exceed a set width.
518 \li TextEdit.WrapAnywhere - wrapping is done at any point on a line, even
519 if it occurs in the middle of a word.
520 \li TextEdit.Wrap - if possible, wrapping occurs at a word boundary; otherwise
521 it will occur at the appropriate point on the line, even in the middle of a word.
522 \endlist
523 The default is TextEdit.Wrap
524
525 \qmlproperty enumeration wrapMode
526 */
527 property alias wrapMode:editor.wrapMode
528
529 // signals
530 /*!
531 This handler is called when the user clicks on a link embedded in the text.
532 The link must be in rich text or HTML format and the link string provides
533 access to the particular link.
534 */
535 signal linkActivated(string link)
536
537 // functions
538 /*!
539 Copies the currently selected text to the system clipboard.
540 */
541 function copy()
542 {
543 editor.copy();
544 }
545
546 /*!
547 Moves the currently selected text to the system clipboard.
548 */
549 function cut()
550 {
551 editor.cut();
552 }
553
554 /*!
555 Removes active text selection.
556 */
557 function deselect()
558 {
559 editor.deselect();
560 }
561
562 /*!
563 Inserts text into the TextArea at position.
564 */
565 function insert(position, text)
566 {
567 editor.insert(position, text);
568 }
569
570 /*!
571 Returns the text position closest to pixel position (x, y).
572
573 Position 0 is before the first character, position 1 is after the first
574 character but before the second, and so on until position text.length,
575 which is after all characters.
576 */
577 function positionAt(x, y)
578 {
579 return editor.positionAt(x, y);
580 }
581
582 /*!
583 Returns true if the natural reading direction of the editor text found
584 between positions start and end is right to left.
585 */
586 function isRightToLeft(start, end)
587 {
588 return editor.isRightToLeft(start, end)
589 }
590
591 /*!
592 Moves the cursor to position and updates the selection according to the
593 optional mode parameter. (To only move the cursor, set the cursorPosition
594 property.)
595
596 When this method is called it additionally sets either the selectionStart
597 or the selectionEnd (whichever was at the previous cursor position) to the
598 specified position. This allows you to easily extend and contract the selected
599 text range.
600
601 The selection mode specifies whether the selection is updated on a per character
602 or a per word basis. If not specified the selection mode will default to whatever
603 is given in the mouseSelectionMode property.
604 */
605 function moveCursorSelection(position, mode)
606 {
607 if (mode === undefined)
608 editor.moveCursorSelection(position, mouseSelectionMode);
609 else
610 editor.moveCursorSelection(position, mode);
611 }
612
613 /*!
614 Places the clipboard or the data given as parameter into the text input.
615 The selected text will be replaces with the data.
616 */
617 function paste(data) {
618 if ((data !== undefined) && (typeof data === "string") && !editor.readOnly) {
619 var selTxt = editor.selectedText;
620 var txt = editor.text;
621 var pos = (selTxt !== "") ? txt.indexOf(selTxt) : editor.cursorPosition
622 if (selTxt !== "") {
623 editor.text = txt.substring(0, pos) + data + txt.substr(pos + selTxt.length);
624 } else {
625 editor.text = txt.substring(0, pos) + data + txt.substr(pos);
626 }
627 editor.cursorPosition = pos + data.length;
628 } else
629 editor.paste();
630 }
631
632 /*!
633 Returns the rectangle at the given position in the text. The x, y, and height
634 properties correspond to the cursor that would describe that position.
635 */
636 function positionToRectangle(position)
637 {
638 return editor.positionToRectangle(position);
639 }
640
641 /*!
642 Redoes the last operation if redo is \l{canRedo}{available}.
643 */
644 function redo()
645 {
646 editor.redo();
647 }
648
649 /*!
650 Causes the text from start to end to be selected.
651
652 If either start or end is out of range, the selection is not changed.
653
654 After calling this, selectionStart will become the lesser and selectionEnd
655 will become the greater (regardless of the order passed to this method).
656
657 See also selectionStart and selectionEnd.
658 */
659 function select(start, end)
660 {
661 editor.select(start, end);
662 }
663
664 /*!
665 Causes all text to be selected.
666 */
667 function selectAll()
668 {
669 editor.selectAll();
670 }
671
672 /*!
673 Causes the word closest to the current cursor position to be selected.
674 */
675 function selectWord()
676 {
677 editor.selectWord();
678 }
679
680 /*!
681 Returns the section of text that is between the start and end positions.
682
683 The returned text will be formatted according the textFormat property.
684 */
685 function getFormattedText(start, end)
686 {
687 return editor.getFormattedText(start, end);
688 }
689
690 /*!
691 Returns the section of text that is between the start and end positions.
692
693 The returned text does not include any rich text formatting. A getText(0, length)
694 will result in the same value as displayText.
695 */
696 function getText(start, end)
697 {
698 return editor.getText(start, end);
699 }
700
701 /*!
702 Removes the section of text that is between the start and end positions
703 from the TextArea.
704 */
705 function remove(start, end)
706 {
707 return editor.remove(start, end);
708 }
709
710 /*!
711 Undoes the last operation if undo is \l{canUndo}{available}. Deselects
712 any current selection, and updates the selection start to the current
713 cursor position.
714 */
715 function undo()
716 {
717 editor.undo();
718 }
719
720 // logic
721 /*!\internal - to remove warnings */
722 Component.onCompleted: {
723 editor.linkActivated.connect(control.linkActivated);
724 }
725
726 // activation area on mouse click
727 // the editor activates automatically when pressed in the editor control,
728 // however that one can be slightly spaced to the main control area
729 MouseArea {
730 anchors.fill: parent
731 enabled: internal.frameSpacing > 0
732 acceptedButtons: Qt.LeftButton | Qt.RightButton
733 // activate input when pressed on the frame
734 preventStealing: false
735 Lomiri.Mouse.forwardTo: [inputHandler]
736 }
737
738 //internals
739
740 opacity: enabled ? 1.0 : 0.3
741
742 /*!\internal */
743 onVisibleChanged: {
744 if (!visible)
745 control.focus = false;
746 }
747
748 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
749 LayoutMirroring.childrenInherit: true
750
751 QtObject {
752 id: internal
753 // public property locals enabling aliasing
754 property string displayText: editor.getText(0, editor.length)
755 property real frameSpacing: control.__styleInstance.frameSpacing
756 property real minimumSize: units.gu(4)
757
758 function linesHeight(lines)
759 {
760 return inputHandler.lineSize * lines + 2 * frameSpacing;
761 }
762
763 function frameSize()
764 {
765 if (control.autoSize) {
766 var max = (control.maximumLineCount <= 0) ?
767 control.lineCount :
768 Math.min(control.maximumLineCount, control.lineCount);
769 control.height = linesHeight(Lomiri.MathUtils.clamp(control.lineCount, 1, max));
770 }
771 }
772 }
773
774 // grab Enter/Return keys which may be stolen from parent components of TextArea
775 // due to forwarded keys from TextEdit
776 Keys.onPressed: {
777 if (readOnly)
778 return;
779 if ((event.key === Qt.Key_Enter) || (event.key === Qt.Key_Return)) {
780 if (editor.textFormat === TextEdit.RichText) {
781 // FIXME: use control.paste("<br />") instead when paste() gets sich text support
782 editor.insert(editor.cursorPosition, "<br />");
783 } else {
784 control.paste("\n");
785 }
786 event.accepted = true;
787 } else {
788 event.accepted = false;
789 }
790 }
791 Keys.onReleased: event.accepted = (event.key === Qt.Key_Enter) || (event.key === Qt.Key_Return)
792
793 // holding default values
794 Label { id: fontHolder }
795
796 //hint
797 Label {
798 id: hint
799 anchors {
800 fill: parent
801 margins: internal.frameSpacing
802 }
803 // hint is shown till user types something in the field
804 visible: (editor.text == "") && !editor.inputMethodComposing
805 color: Theme.palette.normal.backgroundText
806 font: editor.font
807 elide: Text.ElideRight
808 wrapMode: Text.WordWrap
809 }
810
811 //scrollbars and flickable
812 Scrollbar {
813 id: rightScrollbar
814 flickableItem: flicker
815 }
816 Scrollbar {
817 id: bottomScrollbar
818 flickableItem: flicker
819 align: Qt.AlignBottom
820 }
821 Flickable {
822 id: flicker
823 objectName: "input_scroller"
824 anchors {
825 fill: parent
826 margins: internal.frameSpacing
827 }
828 clip: true
829 contentWidth: editor.paintedWidth
830 contentHeight: editor.paintedHeight
831 // do not allow rebounding
832 boundsBehavior: Flickable.StopAtBounds
833
834 // editor
835 // Images are not shown when text contains <img> tags
836 // bug to watch: https://bugreports.qt-project.org/browse/QTBUG-27071
837 TextEdit {
838 objectName: "text_input"
839 readOnly: false
840 id: editor
841 focus: true
842 width: control.contentWidth
843 height: Math.max(control.contentHeight, editor.contentHeight)
844 wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
845 mouseSelectionMode: TextEdit.SelectWords
846 selectByMouse: true
847 activeFocusOnPress: true
848 onActiveFocusChanged: if (!activeFocus && inputHandler.popover) PopupUtils.close(inputHandler.popover)
849 cursorDelegate: TextCursor {
850 handler: inputHandler
851 }
852 color: control.__styleInstance.color
853 selectedTextColor: control.__styleInstance.selectedTextColor
854 selectionColor: control.__styleInstance.selectionColor
855 font.pixelSize: FontUtils.sizeToPixels("medium")
856 // forward keys to the root element so it can be captured outside of it
857 // as well as to InputHandler to handle PageUp/PageDown keys
858 Keys.forwardTo: [control, inputHandler]
859
860 // autosize handling
861 onLineCountChanged: internal.frameSize()
862
863 // input selection and navigation handling
864 Lomiri.Mouse.forwardTo: [inputHandler]
865 InputHandler {
866 id: inputHandler
867 anchors.fill: parent
868 main: control
869 input: editor
870 flickable: flicker
871 }
872 }
873 }
874
875 style: Theme.createStyleComponent("TextAreaStyle.qml", control)
876 }