25a02ad9a20b42f7fd4e399a6640e6c23eb6e82f
[profile/ivi/qtdeclarative.git] / tests / testapplications / text / textedit.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     property int intmax: 2147483647
47
48     Connections { target: pointvalue; onReset: { texteditelement.font.pointSize = 12 } }
49
50     Item {
51         id: textpanel
52         height: 360
53         width: 440
54         TextEdit {
55             id: texteditelement
56             height: parent.height - 20; width: parent.width - 20
57             anchors.centerIn: parent
58
59             text: { textvalue.model.get(textvalue.currentIndex).value }
60             textFormat: { formatvalue.model.get(formatvalue.currentIndex).value }
61             color: { colorvalue.model.get(colorvalue.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             smooth: { smoothvalue.model.get(smoothvalue.currentIndex).value }
77             selectByMouse: { mousevalue.model.get(mousevalue.currentIndex).value }
78             onLinkActivated: { bordercolor.border.color = "red" }
79             Rectangle { id: bordercolor; color: "transparent"; border.color: "green"; anchors.fill: parent }
80         }
81
82         Text {
83             id: infopanel
84             anchors { left: parent.left; leftMargin: 10; bottom: parent.bottom }
85             height: 150; color: "black"; width: 150
86             text:
87             "LineCount: "+texteditelement.lineCount+
88             "\nPaintedHeight/Width: "+texteditelement.paintedHeight+"/"+texteditelement.paintedWidth+
89             "\nPointSize: "+texteditelement.font.pointSize+"\nPixelSize: "+texteditelement.font.pixelSize+
90             "\nCan Paste: "+texteditelement.canPaste
91         }
92         Row {
93             id: selectionbuttons
94             height:40
95             width: 300
96             anchors.right: texteditelement.right; anchors.bottom: texteditelement.bottom
97             Button { buttontext: "Select Word"; width: parent.width/3; onClicked: { texteditelement.selectWord() } }
98             Button { buttontext: "Select All"; width: parent.width/3; onClicked: { texteditelement.selectAll() } }
99             Button { buttontext: "Select None"; width: parent.width/3; onClicked: { texteditelement.deselect() } }
100         }
101         Row {
102             height:40
103             width: 300
104             anchors.right: texteditelement.right; anchors.bottom: selectionbuttons.top
105             Button { buttontext: "Cut"; width: parent.width/3; onClicked: { texteditelement.cut() } }
106             Button { buttontext: "Copy"; width: parent.width/3; onClicked: { texteditelement.copy() } }
107             Button { buttontext: "Paste"; width: parent.width/3; onClicked: { texteditelement.paste() } }
108         }
109     }
110
111     Item {
112         id: controlpanel
113         width: 200; height: parent.height
114         anchors.right: parent.right
115         Rectangle { anchors.fill: parent; color: "transparent"; border.color: "black" }
116         ListView { id: controls; model: controlsmodel; anchors.fill: parent; clip: true; cacheBuffer: 500 }
117         VisualItemModel {
118             id: controlsmodel
119             ControlView {
120                 id: textvalue
121                 controlname: "Text"
122                 model: textmodel
123                 ListModel { id: textmodel }
124                 Component.onCompleted: {
125                     textmodel.append({ "name": "Basic",
126                     "value": "Qt Quick is a collection of technologies that are designed to help developers create the kind of intuitive, "+
127                     "modern, fluid user interfaces that are increasingly used on mobile phones, media players, set-top boxes and other "+
128                     "portable devices."+texteditelement.newline+
129                     "Qt Quick consists of a rich set of user interface elements, a declarative language for describing user interfaces "+
130                     "and a language runtime.\n"+
131                     "A collection of C++ APIs is used to integrate these high level features with classic Qt applications."});
132                     textmodel.append({ "name": "Short",
133                     "value": "Hello World"});
134                     textmodel.append({ "name": "Long",
135                     "value": "QtQuickisacollectionoftechnologiesthataredesignedtohelpdeveloperscreatethekindofintuitive,"+
136                     "modern,fluiduserinterfacesthatareincreasinglyusedonmobilephones,mediaplayers,set-topboxesandother"+
137                     "portabledevices."});
138                     textmodel.append({ "name": "Rich",
139                     "value": "<b>Qt Quick</b> is a collection of technologies that are designed to help developers create the kind of <i>intuitive, "+
140                     "modern, fluid</i> user interfaces that are increasingly used on mobile phones, media players, set-top boxes and other "+
141                     "portable devices.<br>"+
142                     "Qt Quick consists of a rich set of user interface elements, a declarative language for describing user interfaces "+
143                     "and a language runtime. "+
144                     "A collection of C++ APIs is used to integrate these high level features with classic Qt applications."});
145                     textmodel.append({ "name": "Links",
146                     "value": "This is a link - <a href=\"http://doc.qt.nokia.com\">Qt Docs</a>"});
147                 }
148             }
149             ControlView {
150                 id: formatvalue
151                 controlname: "Format"
152                 model: ListModel { ListElement { name: "Auto"; value: Text.AutoText } ListElement { name: "Plain"; value: Text.PlainText }
153                     ListElement { name: "Rich"; value: Text.RichText } ListElement { name: "Styled"; value: Text.StyledText } } }
154             ControlView {
155                 id: colorvalue
156                 controlname: "Color"
157                 model: ListModel { ListElement { name: "Red"; value: "red" }
158                     ListElement { name: "Green"; value: "green" } ListElement { name: "Blue"; value: "blue" } }
159             }
160             ControlView {
161                 id: boldvalue
162                 controlname: "Bold"
163                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
164             }
165             ControlView {
166                 id: italicsvalue
167                 controlname: "Italic"
168                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
169             }
170             ControlView {
171                 id: capsvalue
172                 controlname: "Cap10n"
173                 model: ListModel {
174                     ListElement { name: "Mixed"; value: Font.MixedCase } ListElement { name: "Upper"; value: Font.AllUppercase }
175                     ListElement { name: "Lower"; value: Font.AllLowercase } ListElement { name: "SmallCaps"; value: Font.SmallCaps }
176                     ListElement { name: "Capitals"; value: Font.Capitalize }
177                 }
178             }
179             ControlView {
180                 id: familyvalue
181                 controlname: "Font"
182                 property variant fontfamilies
183                 function setModel() {
184                     familiesmodel.clear();
185                     for (var i = 0; i < fontfamilies.length; ++i) {
186                         familiesmodel.append({ "name": fontfamilies[i], "value": fontfamilies[i] });
187                     }
188                     familyvalue.currentIndex = 0;
189                 }
190                 model: familiesmodel
191                 ListModel { id: familiesmodel }
192                 Component.onCompleted: { fontfamilies = Qt.fontFamilies(); setModel(); }
193             }
194             ControlView {
195                 id: lspacingvalue
196                 controlname: "LSpacing"
197                 model: ListModel { ListElement { name: "0"; value: 0 } ListElement { name: "1"; value: 1 } ListElement { name: "2.5"; value: 2.5 } } }
198             ControlView {
199                 id: wspacingvalue
200                 controlname: "WSpacing"
201                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
202             ControlView {
203                 id: pixelvalue
204                 controlname: "Pixel"
205                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
206             ControlView {
207                 id: pointvalue
208                 controlname: "Point"
209                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
210             ControlView {
211                 id: strikeoutvalue
212                 controlname: "Strike"
213                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
214             ControlView {
215                 id: underlinevalue
216                 controlname: "U_line"
217                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
218             ControlView {
219                 id: weightvalue
220                 controlname: "Weight"
221                 model: ListModel { ListElement { name: "Light"; value: Font.Light } ListElement { name: "Normal"; value: Font.Normal }
222                     ListElement { name: "DemiBold"; value: Font.DemiBold } ListElement { name: "Bold"; value: Font.Bold }
223                     ListElement { name: "Black"; value: Font.Black } }
224                     Component.onCompleted: { currentIndex = 1 } // set to default
225             }
226             ControlView {
227                 id: mousevalue
228                 controlname: "Mouse"
229                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
230             ControlView {
231                 id: halignvalue
232                 controlname: "HAlign"
233                 model: ListModel { ListElement { name: "Left"; value: Text.AlignLeft } ListElement { name: "Right"; value: Text.AlignRight }
234                     ListElement { name: "Center"; value: Text.AlignHCenter } ListElement { name: "Justify"; value: Text.AlignJustify } } }
235             ControlView {
236                 id: valignvalue
237                 controlname: "VAlign"
238                 model: ListModel { ListElement { name: "Top"; value: Text.AlignTop } ListElement { name: "Bottom"; value: Text.AlignBottom }
239                     ListElement { name: "Center"; value: Text.AlignVCenter } } }
240             ControlView {
241                 id: smoothvalue
242                 controlname: "Smooth"
243                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
244             ControlView {
245                 id: wrapvalue
246                 controlname: "Wrap"
247                 model: ListModel { ListElement { name: "None"; value: Text.NoWrap } ListElement { name: "Word"; value: Text.WordWrap }
248                     ListElement { name: "Anywhere"; value: Text.WrapAnywhere } ListElement { name: "Wrap"; value: Text.Wrap } } }
249         }
250     }
251 }
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268