1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the examples of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 //width: containerColumn.width
47 //height: containerColumn.height + containerColumn.anchors.topMargin
51 property bool mirror: false
53 property variant horizontalAlignment: undefined
55 property variant editorType: ["Plain Text", "Styled Text", "Plain Rich Text", "Italic Rich Text", "Plain TextEdit", "Italic TextEdit", "TextInput"]
56 property variant text: ["", " ", "Hello world!", "مرحبا العالم!", "Hello world! Hello!\nHello world! Hello!", "مرحبا العالم! مرحبا! مرحبا العالم! مرحبا!" ,"مرحبا العالم! مرحبا! مرحبا Hello world!\nالعالم! مرحبا!"]
57 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"]
58 property variant textComponents: [plainTextComponent, styledTextComponent, richTextComponent, italicRichTextComponent, plainTextEdit, italicTextEdit, textInput]
60 function shortText(horizontalAlignment) {
62 // all the different QML editors have
63 // the same alignment values
64 switch (horizontalAlignment) {
69 case Text.AlignHCenter:
71 case Text.AlignJustify:
80 width: editorTypeRow.width
81 anchors { top: parent.top; topMargin: 5 }
86 model: editorType.length
87 orientation: ListView.Horizontal
88 cacheBuffer: 1000//Load the really expensive ones async if possible
90 width: editorColumn.width
91 height: editorColumn.height
95 width: textColumn.width+10
97 text: root.editorType[index]
99 anchors.horizontalCenter: parent.horizontalCenter
104 anchors.horizontalCenter: parent.horizontalCenter
106 model: textComponents.length
107 delegate: textComponents[index]
118 height: 50; width: parent.width
119 color: mouseArea.pressed ? "black" : "lightgray"
121 anchors.centerIn: parent
123 text: root.mirror ? "Mirrored" : "Not mirrored"
126 anchors.horizontalCenter: parent.horizontalCenter
129 text: "(click here to toggle)"
133 anchors.horizontalCenter: parent.horizontalCenter
138 property int index: 0
140 onClicked: root.mirror = !root.mirror
145 height: 50; width: parent.width
146 color: mouseArea2.pressed ? "black" : "gray"
148 anchors.centerIn: parent
151 if (root.horizontalAlignment == undefined)
152 return "Implict alignment";
153 switch (root.horizontalAlignment) {
155 return "Left alignment";
156 case Text.AlignRight:
157 return "Right alignment";
158 case Text.AlignHCenter:
159 return "Center alignment";
160 case Text.AlignJustify:
161 return "Justify alignment";
166 anchors.horizontalCenter: parent.horizontalCenter
169 text: "(click here to toggle)"
173 anchors.horizontalCenter: parent.horizontalCenter
178 property int index: 0
182 root.horizontalAlignment = undefined;
184 root.horizontalAlignment = Math.pow(2, index);
186 index = (index + 2) % 5 - 1;
194 id: plainTextComponent
197 text: root.text[index]
199 wrapMode: Text.WordWrap
200 horizontalAlignment: root.horizontalAlignment
201 LayoutMirroring.enabled: root.mirror
202 textFormat: Text.RichText
205 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
209 text: root.description[index]
210 color: Qt.rgba(1,1,1,1.0)
211 anchors.centerIn: parent
212 font.pixelSize: pxSz - 2
215 color: Qt.rgba(0.3, 0, 0, 0.3)
216 anchors { fill: parent; margins: -3 }
221 text: shortText(parent.horizontalAlignment)
222 anchors { top: parent.top; right: parent.right; margins: 2 }
228 id: styledTextComponent
231 text: root.text[index]
233 wrapMode: Text.WordWrap
234 horizontalAlignment: root.horizontalAlignment
235 LayoutMirroring.enabled: root.mirror
236 textFormat: Text.RichText
241 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
245 text: root.description[index]
246 color: Qt.rgba(1,1,1,1.0)
247 anchors.centerIn: parent
248 font.pixelSize: pxSz - 2
251 color: Qt.rgba(0.3, 0, 0, 0.3)
252 anchors { fill: parent; margins: -3 }
257 text: shortText(parent.horizontalAlignment)
258 anchors { top: parent.top; right: parent.right; margins: 2 }
264 id: richTextComponent
267 text: root.text[index]
269 wrapMode: Text.WordWrap
270 horizontalAlignment: root.horizontalAlignment
271 LayoutMirroring.enabled: root.mirror
272 textFormat: Text.RichText
275 color: Qt.rgba(0.8, 0.2, 0.2, 0.3)
279 text: root.description[index]
280 color: Qt.rgba(1,1,1,1.0)
281 anchors.centerIn: parent
282 font.pixelSize: pxSz - 2
285 color: Qt.rgba(0.3, 0, 0, 0.3)
286 anchors { fill: parent; margins: -3 }
291 text: shortText(parent.horizontalAlignment)
292 anchors { top: parent.top; right: parent.right; margins: 2 }
298 id: italicRichTextComponent
301 text: "<i>" + root.text[index] + "</i>"
303 wrapMode: Text.WordWrap
304 horizontalAlignment: root.horizontalAlignment
305 LayoutMirroring.enabled: root.mirror
306 textFormat: Text.RichText
307 property variant backgroundColor: Qt.rgba(0.8, 0.2, 0.2, 0.3)
310 color: parent.backgroundColor
314 text: root.description[index]
315 color: Qt.rgba(1,1,1,1.0)
316 anchors.centerIn: parent
317 font.pixelSize: pxSz - 2
320 color: Qt.rgba(0.3, 0, 0, 0.3)
321 anchors { fill: parent; margins: -3 }
326 text: shortText(parent.horizontalAlignment)
327 anchors { top: parent.top; right: parent.right; margins: 2 }
336 text: root.text[index]
339 wrapMode: TextEdit.WordWrap
340 horizontalAlignment: root.horizontalAlignment
341 LayoutMirroring.enabled: root.mirror
344 color: Qt.rgba(0.5, 0.5, 0.2, 0.3)
348 text: root.description[index]
349 color: Qt.rgba(1,1,1,1.0)
350 anchors.centerIn: parent
351 font.pixelSize: pxSz - 2
354 color: Qt.rgba(0.3, 0, 0, 0.3)
355 anchors { fill: parent; margins: -3 }
360 text: shortText(parent.horizontalAlignment)
361 anchors { top: parent.top; right: parent.right; margins: 2 }
370 text: "<i>" + root.text[index] + "<i>"
373 wrapMode: TextEdit.WordWrap
374 textFormat: TextEdit.RichText
375 horizontalAlignment: root.horizontalAlignment
376 LayoutMirroring.enabled: root.mirror
379 color: Qt.rgba(0.5, 0.5, 0.2, 0.3)
383 text: root.description[index]
384 color: Qt.rgba(1,1,1,1.0)
385 anchors.centerIn: parent
386 font.pixelSize: pxSz - 2
389 color: Qt.rgba(0.3, 0, 0, 0.3)
390 anchors { fill: parent; margins: -3 }
395 text: shortText(parent.horizontalAlignment)
396 anchors { top: parent.top; right: parent.right; margins: 2 }
405 height: textInput.text.length > 20 ? 3*textInput.height : textInput.height
409 text: root.text[index]
412 horizontalAlignment: root.horizontalAlignment
413 LayoutMirroring.enabled: root.mirror
416 color: Qt.rgba(0.6, 0.4, 0.2, 0.3)
420 text: root.description[index]
421 color: Qt.rgba(1,1,1,1.0)
422 anchors.centerIn: parent
423 font.pixelSize: pxSz - 2
426 color: Qt.rgba(0.3, 0, 0, 0.3)
427 anchors { fill: parent; margins: -3 }
432 text: shortText(parent.horizontalAlignment)
433 anchors { top: parent.top; right: parent.right; margins: 2 }