1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the examples of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 width: containerColumn.width
47 height: containerColumn.height + containerColumn.anchors.topMargin
49 property bool mirror: false
50 property variant horizontalAlignment: undefined
52 property variant editorType: ["Plain Text", "Styled Text", "Plain Rich Text", "Italic Rich Text", "Plain TextEdit", "Italic TextEdit", "TextInput"]
53 property variant text: ["", " ", "Hello world!", "مرحبا العالم!", "Hello world! Hello!\nHello world! Hello!", "مرحبا العالم! مرحبا! مرحبا العالم! مرحبا!" ,"مرحبا العالم! مرحبا! مرحبا Hello world!\nالعالم! مرحبا!"]
54 property variant description: ["empty text", "white-space-only text", "left-to-right text", "right-to-left text", "multi-line left-to-right text", "multi-line right-to-left text", "multi-line bidi text"]
55 property variant textComponents: [plainTextComponent, styledTextComponent, richTextComponent, italicRichTextComponent, plainTextEdit, italicTextEdit, textInput]
57 function shortText(horizontalAlignment) {
59 // all the different QML editors have
60 // the same alignment values
61 switch (horizontalAlignment) {
66 case Text.AlignHCenter:
68 case Text.AlignJustify:
77 width: editorTypeRow.width
78 anchors { top: parent.top; topMargin: 5 }
82 model: editorType.length
84 width: editorColumn.width
85 height: editorColumn.height
89 width: textColumn.width+10
91 text: root.editorType[index]
93 anchors.horizontalCenter: parent.horizontalCenter
98 anchors.horizontalCenter: parent.horizontalCenter
100 model: textComponents.length
101 delegate: textComponents[index]
113 height: 50; width: parent.width
114 color: mouseArea.pressed ? "black" : "lightgray"
116 anchors.centerIn: parent
118 text: root.mirror ? "Mirrored" : "Not mirrored"
121 anchors.horizontalCenter: parent.horizontalCenter
124 text: "(click here to toggle)"
128 anchors.horizontalCenter: parent.horizontalCenter
133 property int index: 0
135 onClicked: root.mirror = !root.mirror
140 height: 50; width: parent.width
141 color: mouseArea2.pressed ? "black" : "gray"
143 anchors.centerIn: parent
146 if (root.horizontalAlignment == undefined)
147 return "Implict alignment";
148 switch (root.horizontalAlignment) {
150 return "Left alignment";
151 case Text.AlignRight:
152 return "Right alignment";
153 case Text.AlignHCenter:
154 return "Center alignment";
155 case Text.AlignJustify:
156 return "Justify alignment";
161 anchors.horizontalCenter: parent.horizontalCenter
164 text: "(click here to toggle)"
168 anchors.horizontalCenter: parent.horizontalCenter
173 property int index: 0
177 root.horizontalAlignment = undefined;
179 root.horizontalAlignment = Math.pow(2, index);
181 index = (index + 2) % 5 - 1;
189 id: plainTextComponent
192 text: root.text[index]
194 wrapMode: Text.WordWrap
195 horizontalAlignment: root.horizontalAlignment
196 LayoutMirroring.enabled: root.mirror
197 textFormat: Text.RichText
200 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
204 text: root.description[index]
205 color: Qt.rgba(1,1,1,1.0)
206 anchors.centerIn: parent
209 color: Qt.rgba(0.3, 0, 0, 0.3)
210 anchors { fill: parent; margins: -3 }
215 text: shortText(parent.horizontalAlignment)
216 anchors { top: parent.top; right: parent.right; margins: 2 }
222 id: styledTextComponent
225 text: root.text[index]
227 wrapMode: Text.WordWrap
228 horizontalAlignment: root.horizontalAlignment
229 LayoutMirroring.enabled: root.mirror
230 textFormat: Text.RichText
235 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
239 text: root.description[index]
240 color: Qt.rgba(1,1,1,1.0)
241 anchors.centerIn: parent
244 color: Qt.rgba(0.3, 0, 0, 0.3)
245 anchors { fill: parent; margins: -3 }
250 text: shortText(parent.horizontalAlignment)
251 anchors { top: parent.top; right: parent.right; margins: 2 }
257 id: richTextComponent
260 text: root.text[index]
262 wrapMode: Text.WordWrap
263 horizontalAlignment: root.horizontalAlignment
264 LayoutMirroring.enabled: root.mirror
265 textFormat: Text.RichText
268 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
272 text: root.description[index]
273 color: Qt.rgba(1,1,1,1.0)
274 anchors.centerIn: parent
277 color: Qt.rgba(0.3, 0, 0, 0.3)
278 anchors { fill: parent; margins: -3 }
283 text: shortText(parent.horizontalAlignment)
284 anchors { top: parent.top; right: parent.right; margins: 2 }
290 id: italicRichTextComponent
293 text: "<i>" + root.text[index] + "</i>"
295 wrapMode: Text.WordWrap
296 horizontalAlignment: root.horizontalAlignment
297 LayoutMirroring.enabled: root.mirror
298 textFormat: Text.RichText
299 property variant backgroundColor: Qt.rgba(0.8, 0.2, 0.2, 0.3)
302 color: parent.backgroundColor
306 text: root.description[index]
307 color: Qt.rgba(1,1,1,1.0)
308 anchors.centerIn: parent
311 color: Qt.rgba(0.3, 0, 0, 0.3)
312 anchors { fill: parent; margins: -3 }
317 text: shortText(parent.horizontalAlignment)
318 anchors { top: parent.top; right: parent.right; margins: 2 }
327 text: root.text[index]
330 wrapMode: TextEdit.WordWrap
331 horizontalAlignment: root.horizontalAlignment
332 LayoutMirroring.enabled: root.mirror
335 color: Qt.rgba(0.5, 0.5, 0.2, 0.3)
339 text: root.description[index]
340 color: Qt.rgba(1,1,1,1.0)
341 anchors.centerIn: parent
344 color: Qt.rgba(0.3, 0, 0, 0.3)
345 anchors { fill: parent; margins: -3 }
350 text: shortText(parent.horizontalAlignment)
351 anchors { top: parent.top; right: parent.right; margins: 2 }
360 text: "<i>" + root.text[index] + "<i>"
363 wrapMode: TextEdit.WordWrap
364 textFormat: TextEdit.RichText
365 horizontalAlignment: root.horizontalAlignment
366 LayoutMirroring.enabled: root.mirror
369 color: Qt.rgba(0.5, 0.5, 0.2, 0.3)
373 text: root.description[index]
374 color: Qt.rgba(1,1,1,1.0)
375 anchors.centerIn: parent
378 color: Qt.rgba(0.3, 0, 0, 0.3)
379 anchors { fill: parent; margins: -3 }
384 text: shortText(parent.horizontalAlignment)
385 anchors { top: parent.top; right: parent.right; margins: 2 }
394 height: textInput.text.length > 20 ? 3*textInput.height : textInput.height
398 text: root.text[index]
401 horizontalAlignment: root.horizontalAlignment
402 LayoutMirroring.enabled: root.mirror
405 color: Qt.rgba(0.6, 0.4, 0.2, 0.3)
409 text: root.description[index]
410 color: Qt.rgba(1,1,1,1.0)
411 anchors.centerIn: parent
414 color: Qt.rgba(0.3, 0, 0, 0.3)
415 anchors { fill: parent; margins: -3 }
420 text: shortText(parent.horizontalAlignment)
421 anchors { top: parent.top; right: parent.right; margins: 2 }