Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / testapplications / text / textinput.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
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: { textinputelement.font.pointSize = 12 } }
48
49     Item {
50         id: textpanel
51         height: 360
52         width: 440
53         MouseArea { anchors.fill: parent; onClicked: textinputelement.focus = false }
54         TextInput {
55             id: textinputelement
56             height: 50; width: parent.width - 20
57             anchors.centerIn: parent
58             focus: true
59             property int validatorval
60             validatorval: { validvalue.model.get(validvalue.currentIndex).value }
61             text: { textvalue.model.get(textvalue.currentIndex).value }
62             autoScroll: { autoscrollvalue.model.get(autoscrollvalue.currentIndex).value }
63             color: { colorvalue.model.get(colorvalue.currentIndex).value }
64             font.bold: { boldvalue.model.get(boldvalue.currentIndex).value }
65             font.italic: { italicsvalue.model.get(italicsvalue.currentIndex).value }
66             font.capitalization: { capsvalue.model.get(capsvalue.currentIndex).value }
67             font.family: { familyvalue.model.get(familyvalue.currentIndex).value }
68             font.strikeout: strikeoutvalue.currentIndex
69             font.underline: underlinevalue.currentIndex
70             font.letterSpacing: { lspacingvalue.model.get(lspacingvalue.currentIndex).value }
71             font.wordSpacing: { wspacingvalue.model.get(wspacingvalue.currentIndex).value }
72             font.weight: { weightvalue.model.get(weightvalue.currentIndex).value }
73             font.pointSize: { pointvalue.model.get(pointvalue.currentIndex).value }
74             font.pixelSize: { pixelvalue.model.get(pixelvalue.currentIndex).value }
75             horizontalAlignment: { halignvalue.model.get(halignvalue.currentIndex).value }
76             verticalAlignment: { valignvalue.model.get(valignvalue.currentIndex).value }
77             wrapMode: { wrapvalue.model.get(wrapvalue.currentIndex).value }
78             smooth: { smoothvalue.model.get(smoothvalue.currentIndex).value }
79             selectByMouse: { mousevalue.model.get(mousevalue.currentIndex).value }
80             echoMode: { echovalue.model.get(echovalue.currentIndex).value }
81             cursorVisible: { cursorvisiblevalue.model.get(cursorvisiblevalue.currentIndex).value }
82             cursorDelegate: cursordelegate
83             onValidatorvalChanged: {
84                 //console.log(validatorval);
85                 if (validatorval == 0)
86                     validator = intval;
87                 else if (validatorval == 1)
88                     validator = dubval;
89                 else if (validatorval == 2)
90                     validator = regval;
91                 else
92                     validator = noval;
93             }
94             IntValidator { id: intval; top: 30; bottom: 12 }
95             DoubleValidator { id: dubval; top: 30; bottom: 12 }
96             RegExpValidator { id: regval; regExp: /Qt/ }
97             RegExpValidator { id: noval; regExp: /.*/ }
98             Rectangle{ color: "transparent"; border.color: "green"; anchors.fill: parent }
99         }
100
101         Row {
102             id: buttonrow
103             height: 40
104             width: parent.width - 20
105             anchors.left: textinputelement.left
106             anchors.bottom: buttonrow2.top; anchors.bottomMargin: 2
107             Button { buttontext: "Select Word"; onClicked: { textinputelement.selectWord() } }
108             Button { buttontext: "Select All"; onClicked: { textinputelement.selectAll() } }
109             Button { buttontext: "Select to 5"; onClicked: { textinputelement.moveCursorSelection(5) } }
110             Button { buttontext: "Select None"; onClicked: { textinputelement.deselect() } }
111         }
112         Row {
113             id: buttonrow2
114             height: 40
115             width: parent.width - 20
116             anchors.left: textinputelement.left
117             anchors.bottom: buttonrow3.top; anchors.bottomMargin: 2
118             Button { buttontext: "Cut"; onClicked: { textinputelement.cut() } }
119             Button { buttontext: "Copy"; onClicked: { textinputelement.copy() } }
120             Button { buttontext: "Paste"; onClicked: { textinputelement.paste() } }
121         }
122         Row {
123             id: buttonrow3
124             height: 40
125             width: parent.width - 20
126             anchors.left: textinputelement.left
127             anchors.bottom: textinputelement.top; anchors.bottomMargin: 2
128             Button { buttontext: "Position 12px"; onClicked: { textinputelement.cursorPosition = textinputelement.positionAt(12) } }
129             Button { buttontext: "Select 3-6"; onClicked: { textinputelement.select(3,6) } }
130             Button { buttontext: "Position End"; onClicked: { textinputelement.cursorPosition = textinputelement.text.length } }
131         }
132         Component {
133             id: cursordelegate
134             Rectangle {
135                 id: cursordelegaterect
136                 height: 48; width: 3; color: "red"; visible: parent.cursorVisible
137                 SequentialAnimation on opacity { running: true; loops: Animation.Infinite
138                     NumberAnimation { to: 0; duration: 1000 }
139                     NumberAnimation { to: 1; duration: 1000 }
140                 }
141             }
142         }
143
144         Text {
145             id: infopanel
146             anchors { left: parent.left; leftMargin: 10; bottom: parent.bottom }
147             height: 150; color: "black"; width: 150
148             text:
149             "\nPointSize: "+textinputelement.font.pointSize+
150             "\nPixelSize: "+textinputelement.font.pixelSize+
151             "\nAcceptable Input: "+textinputelement.acceptableInput+
152             "\nCan Paste: "+textinputelement.canPaste+
153             "\nCursor Position: "+textinputelement.cursorPosition+
154             "\nRight to Left: "+textinputelement.isRightToLeft(0,textinputelement.text.length);
155         }
156     }
157
158     Item {
159         id: controlpanel
160         width: 200; height: parent.height
161         anchors.right: parent.right
162         Rectangle { anchors.fill: parent; color: "transparent"; border.color: "black" }
163         ListView { id: controls; model: controlsmodel; anchors.fill: parent; clip: true; cacheBuffer: 500 }
164         VisualItemModel {
165             id: controlsmodel
166             ControlView {
167                 id: textvalue
168                 controlname: "Text"
169                 model: textmodel
170                 ListModel { id: textmodel }
171                 Component.onCompleted: {
172                     textmodel.append({ "name": "Basic", "value": "The TextInput item displays an editable line of text."});
173                     textmodel.append({ "name": "Short", "value": "Hello World"});
174                     textmodel.append({ "name": "Long",
175                     "value": "Qt Quick is a collection of technologies that are designed to help developers create the kind of intuitive, "+
176                     "modern, fluid user interfaces that are increasingly used on mobile phones, media players, set-top boxes and other "+
177                     "portable devices. "+
178                     "Qt Quick consists of a rich set of user interface elements, a declarative language for describing user interfaces "+
179                     "and a language runtime. "+
180                     "A collection of C++ APIs is used to integrate these high level features with classic Qt applications."});
181                 }
182             }
183             ControlView {
184                 id: autoscrollvalue
185                 controlname: "AutoScroll"
186                 model: ListModel { ListElement { name: "On"; value: true } ListElement { name: "Off"; value: false } }
187             }
188             ControlView {
189                 id: colorvalue
190                 controlname: "Color"
191                 model: ListModel { ListElement { name: "Red"; value: "red" }
192                     ListElement { name: "Green"; value: "green" } ListElement { name: "Blue"; value: "blue" } }
193             }
194             ControlView {
195                 id: elidevalue
196                 controlname: "Elide"
197                 model: ListModel { ListElement { name: "None"; value: Text.ElideNone } ListElement { name: "Left"; value: Text.ElideLeft }
198                     ListElement { name: "Middle"; value: Text.ElideMiddle } ListElement { name: "Right"; value: Text.ElideRight } }
199             }
200             ControlView {
201                 id: boldvalue
202                 controlname: "Bold"
203                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
204             }
205             ControlView {
206                 id: italicsvalue
207                 controlname: "Italic"
208                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } }
209             }
210             ControlView {
211                 id: capsvalue
212                 controlname: "Cap10n"
213                 model: ListModel {
214                     ListElement { name: "Mixed"; value: Font.MixedCase } ListElement { name: "Upper"; value: Font.AllUppercase }
215                     ListElement { name: "Lower"; value: Font.AllLowercase } ListElement { name: "SmallCaps"; value: Font.SmallCaps }
216                     ListElement { name: "Capitals"; value: Font.Capitalize }
217                 }
218             }
219             ControlView {
220                 id: cursorvisiblevalue
221                 controlname: "Cursor"
222                 model: ListModel { ListElement { name: "On"; value: true } ListElement { name: "Off"; value: false } }
223             }
224             ControlView {
225                 id: echovalue
226                 controlname: "Echo"
227                 model: ListModel { ListElement { name: "Normal"; value: TextInput.Normal } ListElement { name: "Password"; value: TextInput.Password }
228                     ListElement { name: "None"; value: TextInput.NoEcho } ListElement { name: "OnEdit"; value: TextInput.PasswordEchoOnEdit } } }
229             ControlView {
230                 id: familyvalue
231                 controlname: "Font"
232                 property variant fontfamilies
233                 function setModel() {
234                     familiesmodel.clear();
235                     for (var i = 0; i < fontfamilies.length; ++i) {
236                         familiesmodel.append({ "name": fontfamilies[i], "value": fontfamilies[i] });
237                     }
238                     familyvalue.currentIndex = 0;
239                 }
240                 model: familiesmodel
241                 ListModel { id: familiesmodel }
242                 Component.onCompleted: { fontfamilies = Qt.fontFamilies(); setModel(); }
243             }
244             ControlView {
245                 id: lspacingvalue
246                 controlname: "LSpacing"
247                 model: ListModel { ListElement { name: "0"; value: 0 } ListElement { name: "1"; value: 1 } ListElement { name: "2.5"; value: 2.5 } } }
248             ControlView {
249                 id: wspacingvalue
250                 controlname: "WSpacing"
251                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
252             ControlView {
253                 id: pixelvalue
254                 controlname: "Pixel"
255                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
256             ControlView {
257                 id: pointvalue
258                 controlname: "Point"
259                 model: ListModel { ListElement { name: "-1"; value: -1 } ListElement { name: "8"; value: 8 } ListElement { name: "20"; value: 20 } } }
260             ControlView {
261                 id: strikeoutvalue
262                 controlname: "Strike"
263                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
264             ControlView {
265                 id: underlinevalue
266                 controlname: "U_line"
267                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
268             ControlView {
269                 id: weightvalue
270                 controlname: "Weight"
271                 model: ListModel { ListElement { name: "Light"; value: Font.Light } ListElement { name: "Normal"; value: Font.Normal }
272                     ListElement { name: "DemiBold"; value: Font.DemiBold } ListElement { name: "Bold"; value: Font.Bold }
273                     ListElement { name: "Black"; value: Font.Black } }
274                     Component.onCompleted: { currentIndex = 1 } // set to default
275             }
276             ControlView {
277                 id: halignvalue
278                 controlname: "HAlign"
279                 model: ListModel { ListElement { name: "Left"; value: Text.AlignLeft } ListElement { name: "Right"; value: Text.AlignRight }
280                     ListElement { name: "Center"; value: Text.AlignHCenter } ListElement { name: "Justify"; value: Text.AlignJustify } } }
281             ControlView {
282                 id: valignvalue
283                 controlname: "VAlign"
284                 model: ListModel { ListElement { name: "Top"; value: Text.AlignTop } ListElement { name: "Bottom"; value: Text.AlignBottom }
285                     ListElement { name: "Center"; value: Text.AlignVCenter } } }
286             ControlView {
287                 id: maxlinevalue
288                 controlname: "Lines"
289                 model: ListModel { ListElement { name: "Unset"; value: 1 } ListElement { name: "2"; value: 2 } ListElement { name: "10"; value: 10 }} }
290             ControlView {
291                 id: lineheightvalue
292                 controlname: "LHeight"
293                 model: ListModel { ListElement { name: "1"; value: 1.0 } ListElement { name: "2"; value: 2.0 } ListElement { name: "30"; value: 30.0 }} }
294             ControlView {
295                 id: lineheightmodevalue
296                 controlname: "LHMode"
297                 model: ListModel {
298                     ListElement { name: "Multiply"; value: Text.ProportionalHeight } ListElement { name: "Fixed"; value: Text.FixedHeight } } }
299             ControlView {
300                 id: mousevalue
301                 controlname: "Mouse"
302                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
303             ControlView {
304                 id: smoothvalue
305                 controlname: "Smooth"
306                 model: ListModel { ListElement { name: "Off"; value: false } ListElement { name: "On"; value: true } } }
307             ControlView {
308                 id: stylevalue
309                 controlname: "Style"
310                 model: ListModel { ListElement { name: "Normal"; value: Text.Normal } ListElement { name: "Outline"; value: Text.Outline }
311                     ListElement { name: "Raised"; value: Text.Raised } ListElement { name: "Sunken"; value: Text.Sunken } } }
312             ControlView {
313                 id: stylecolorvalue
314                 controlname: "SColor"
315                 model: ListModel { ListElement { name: "Green"; value: "green" } ListElement { name: "Blue"; value: "blue" } } }
316             ControlView {
317                 id: wrapvalue
318                 controlname: "Wrap"
319                 model: ListModel { ListElement { name: "None"; value: Text.NoWrap } ListElement { name: "Word"; value: Text.WordWrap }
320                     ListElement { name: "Anywhere"; value: Text.WrapAnywhere } ListElement { name: "Wrap"; value: Text.Wrap } } }
321             ControlView {
322                 id: validvalue
323                 controlname: "Valid"
324                 model: ListModel { ListElement { name: "None"; value: -1 } ListElement { name: "Int"; value: 0 }
325                     ListElement { name: "Double"; value: 1 } ListElement { name: "RegExp"; value: 2 } } }
326         }
327     }
328 }
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345