d02e6a027ea1f4b6612674b79676e6a0201075f0
[profile/ivi/qtdeclarative.git] / tests / testapplications / text / text.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43
44 Rectangle {
45     height: 360; width: 640
46
47     Connections { target: pointvalue; onReset: { textelement.font.pointSize = 12 } }
48
49     Item {
50         id: textpanel
51         height: 360
52         width: 440
53         Text {
54             id: textelement
55             height: parent.height - 20; width: parent.width - 20
56             anchors.centerIn: parent
57
58             text: { textvalue.model.get(textvalue.currentIndex).value }
59             textFormat: { formatvalue.model.get(formatvalue.currentIndex).value }
60             color: { colorvalue.model.get(colorvalue.currentIndex).value }
61             elide: { elidevalue.model.get(elidevalue.currentIndex).value }
62             font.bold: { boldvalue.model.get(boldvalue.currentIndex).value }
63             font.italic: { italicsvalue.model.get(italicsvalue.currentIndex).value }
64             font.capitalization: { capsvalue.model.get(capsvalue.currentIndex).value }
65             font.family: { familyvalue.model.get(familyvalue.currentIndex).value }
66             font.strikeout: strikeoutvalue.currentIndex
67             font.underline: underlinevalue.currentIndex
68             font.letterSpacing: { lspacingvalue.model.get(lspacingvalue.currentIndex).value }
69             font.wordSpacing: { wspacingvalue.model.get(wspacingvalue.currentIndex).value }
70             font.weight: { weightvalue.model.get(weightvalue.currentIndex).value }
71             font.pointSize: { pointvalue.model.get(pointvalue.currentIndex).value }
72             font.pixelSize: { pixelvalue.model.get(pixelvalue.currentIndex).value }
73             horizontalAlignment: { halignvalue.model.get(halignvalue.currentIndex).value }
74             verticalAlignment: { valignvalue.model.get(valignvalue.currentIndex).value }
75             wrapMode: { wrapvalue.model.get(wrapvalue.currentIndex).value }
76             maximumLineCount: { maxlinevalue.model.get(maxlinevalue.currentIndex).value }
77             lineHeight: { lineheightvalue.model.get(lineheightvalue.currentIndex).value }
78             lineHeightMode: { lineheightmodevalue.model.get(lineheightmodevalue.currentIndex).value }
79             smooth: { smoothvalue.model.get(smoothvalue.currentIndex).value }
80             style: { stylevalue.model.get(stylevalue.currentIndex).value }
81             styleColor: { stylecolorvalue.model.get(stylecolorvalue.currentIndex).value }
82
83             Rectangle{ color: "transparent"; border.color: "green"; anchors.fill: parent }
84         }
85
86         Text {
87             id: infopanel
88             anchors { left: parent.left; leftMargin: 10; bottom: parent.bottom }
89             height: 150; color: "black"; width: 150
90             function elidename() {
91                 switch (textelement.elide) {
92                     case Text.ElideNone: return "None";
93                     case Text.ElideLeft: return "Left";
94                     case Text.ElideMiddle: return "Middle";
95                     case Text.ElideRight: return "Right";
96                 }
97             }
98             text:
99             "LineCount: "+textelement.lineCount+" of "+textelement.maximumLineCount+
100             "\nPaintedHeight/Width: "+textelement.paintedHeight+"/"+textelement.paintedWidth+
101             "\nPointSize: "+textelement.font.pointSize+
102             "\nPixelSize: "+textelement.font.pixelSize+
103             "\nTruncated: "+textelement.truncated+
104             "\nElide: "+ elidename()
105
106         }
107     }
108
109     Item {
110         id: controlpanel
111         width: 200; height: parent.height
112         anchors.right: parent.right
113         Rectangle { anchors.fill: parent; color: "transparent"; border.color: "black" }
114         ListView { id: controls; model: controlsmodel; anchors.fill: parent; clip: true; cacheBuffer: 500 }
115         VisualItemModel {
116             id: controlsmodel
117             ControlView {
118                 id: textvalue
119                 controlname: "Text"
120                 model: textmodel
121                 ListModel { id: textmodel }
122                 Component.onCompleted: {
123                     textmodel.append({ "name": "Basic",
124                     "value": "Qt Quick is a collection of technologies that are designed to help developers create the kind of intuitive, "+
125                     "modern, fluid user interfaces that are increasingly used on mobile phones, media players, set-top boxes and other "+
126                     "portable devices.\n"+
127                     "Qt Quick consists of a rich set of user interface elements, a declarative language for describing user interfaces "+
128                     "and a language runtime. "+
129                     "A collection of C++ APIs is used to integrate these high level features with classic Qt applications."});
130                     textmodel.append({ "name": "Short",
131                     "value": "Button Text."});
132                     textmodel.append({ "name": "Long",
133                     "value": "QtQuickisacollectionoftechnologiesthataredesignedtohelpdeveloperscreatethekindofintuitive,"+
134                     "modern,fluiduserinterfacesthatareincreasinglyusedonmobilephones,mediaplayers,set-topboxesandother"+
135                     "portabledevices."});
136                     textmodel.append({ "name": "Rich",
137                     "value": "<b>Qt Quick</b> is a collection of technologies that are designed to help developers create the kind of <i>intuitive, "+
138                     "modern, fluid</i> user interfaces that are increasingly used on mobile phones, media players, set-top boxes and other "+
139                     "portable devices.<br>"+
140                     "Qt Quick consists of a rich set of user interface elements, a declarative language for describing user interfaces "+
141                     "and a language runtime. "+
142                     "A collection of C++ APIs is used to integrate these high level features with classic Qt applications."});
143                 }
144             }
145             ControlView {
146                 id: formatvalue
147                 controlname: "Format"
148                 model: ListModel { ListElement { name: "Auto"; value: Text.AutoText } ListElement { name: "Plain"; value: Text.PlainText }
149                     ListElement { name: "Rich"; value: Text.RichText } ListElement { name: "Styled"; value: Text.StyledText } } }
150             ControlView {
151                 id: colorvalue
152                 controlname: "Color"
153                 model: ListModel { ListElement { name: "Red"; value: "red" }
154                     ListElement { name: "Green"; value: "green" } ListElement { name: "Blue"; value: "blue" } }
155             }
156             ControlView {
157                 id: elidevalue
158                 controlname: "Elide"
159                 model: ListModel { ListElement { name: "None"; value: Text.ElideNone } ListElement { name: "Left"; value: Text.ElideLeft }
160                     ListElement { name: "Middle"; value: Text.ElideMiddle } ListElement { name: "Right"; value: Text.ElideRight } }
161             }
162             ControlView {
163                 id: boldvalue
164                 controlname: "Bold"
165                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
166             }
167             ControlView {
168                 id: italicsvalue
169                 controlname: "Italic"
170                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
171             }
172             ControlView {
173                 id: capsvalue
174                 controlname: "Cap10n"
175                 model: ListModel {
176                     ListElement { name: "Mixed"; value: Font.MixedCase } ListElement { name: "Upper"; value: Font.AllUppercase }
177                     ListElement { name: "Lower"; value: Font.AllLowercase } ListElement { name: "SmallCaps"; value: Font.SmallCaps }
178                     ListElement { name: "Capitals"; value: Font.Capitalize }
179                 }
180             }
181             ControlView {
182                 id: familyvalue
183                 controlname: "Font"
184                 property variant fontfamilies
185                 function setModel() {
186                     familiesmodel.clear();
187                     for (var i = 0; i < fontfamilies.length; ++i) {
188                         familiesmodel.append({ "name": fontfamilies[i], "value": fontfamilies[i] });
189                     }
190                     familyvalue.currentIndex = 0;
191                 }
192                 model: familiesmodel
193                 ListModel { id: familiesmodel }
194                 Component.onCompleted: { fontfamilies = Qt.fontFamilies(); setModel(); }
195             }
196             ControlView {
197                 id: lspacingvalue
198                 controlname: "LSpacing"
199                 model: ListModel { ListElement { name: "0"; value: 0 } ListElement { name: "1"; value: 1 } ListElement { name: "2.5"; value: 2.5 } } }
200             ControlView {
201                 id: wspacingvalue
202                 controlname: "WSpacing"
203                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
204             ControlView {
205                 id: pixelvalue
206                 controlname: "Pixel"
207                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
208             ControlView {
209                 id: pointvalue
210                 controlname: "Point"
211                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
212             ControlView {
213                 id: strikeoutvalue
214                 controlname: "Strike"
215                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
216             ControlView {
217                 id: underlinevalue
218                 controlname: "U_line"
219                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
220             ControlView {
221                 id: weightvalue
222                 controlname: "Weight"
223                 model: ListModel { ListElement { name: "Light"; value: Font.Light } ListElement { name: "Normal"; value: Font.Normal }
224                     ListElement { name: "DemiBold"; value: Font.DemiBold } ListElement { name: "Bold"; value: Font.Bold }
225                     ListElement { name: "Black"; value: Font.Black } }
226                     Component.onCompleted: { currentIndex = 1 } // set to default
227             }
228             ControlView {
229                 id: halignvalue
230                 controlname: "HAlign"
231                 model: ListModel { ListElement { name: "Left"; value: Text.AlignLeft } ListElement { name: "Right"; value: Text.AlignRight }
232                     ListElement { name: "Center"; value: Text.AlignHCenter } ListElement { name: "Justify"; value: Text.AlignJustify } } }
233             ControlView {
234                 id: valignvalue
235                 controlname: "VAlign"
236                 model: ListModel { ListElement { name: "Top"; value: Text.AlignTop } ListElement { name: "Bottom"; value: Text.AlignBottom }
237                     ListElement { name: "Center"; value: Text.AlignVCenter } } }
238             ControlView {
239                 id: maxlinevalue
240                 controlname: "Lines"
241                 model: ListModel { ListElement { name: "Max"; value: 2147483647 } ListElement { name: "1"; value: 1 }
242                     ListElement { name: "2"; value: 2 } ListElement { name: "10"; value: 10 }} }
243             ControlView {
244                 id: lineheightvalue
245                 controlname: "LHeight"
246                 model: ListModel { ListElement { name: "1"; value: 1.0 } ListElement { name: "2"; value: 2.0 } ListElement { name: "30"; value: 30.0 }} }
247             ControlView {
248                 id: lineheightmodevalue
249                 controlname: "LHMode"
250                 model: ListModel {
251                     ListElement { name: "Multiply"; value: Text.ProportionalHeight } ListElement { name: "Fixed"; value: Text.FixedHeight } } }
252             ControlView {
253                 id: smoothvalue
254                 controlname: "Smooth"
255                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
256             ControlView {
257                 id: stylevalue
258                 controlname: "Style"
259                 model: ListModel { ListElement { name: "Normal"; value: Text.Normal } ListElement { name: "Outline"; value: Text.Outline }
260                     ListElement { name: "Raised"; value: Text.Raised } ListElement { name: "Sunken"; value: Text.Sunken } } }
261             ControlView {
262                 id: stylecolorvalue
263                 controlname: "SColor"
264                 model: ListModel { ListElement { name: "Green"; value: "green" } ListElement { name: "Blue"; value: "blue" } } }
265             ControlView {
266                 id: wrapvalue
267                 controlname: "Wrap"
268                 model: ListModel { ListElement { name: "None"; value: Text.NoWrap } ListElement { name: "Word"; value: Text.WordWrap }
269                     ListElement { name: "Anywhere"; value: Text.WrapAnywhere } ListElement { name: "Wrap"; value: Text.Wrap } } }
270         }
271     }
272 }
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289