d71d8ffe9671ef76c0bc1eed4ae0fd536da45e9b
[profile/ivi/qtdeclarative.git] / tests / testapplications / elements / content / TextInputElement.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 Item {
45     id: textinputelementtest
46     anchors.fill: parent
47     property string testtext: ""
48
49     Rectangle {
50         id: textinputelementbackground
51         color: "green"; height: 50; width: parent.width *.8; border.color: "gray"; opacity: 0.7; radius: 5
52         anchors.centerIn: parent
53         TextInput {
54             id: textinputelement
55             font.pointSize: 12; width: parent.width; text: ""; horizontalAlignment: Text.AlignHCenter
56             anchors.centerIn: parent
57             Behavior on font.pointSize { NumberAnimation { duration: 1000 } }
58             Behavior on color { ColorAnimation { duration: 1000 } }
59         }
60     }
61
62     Rectangle {
63         id: secondarybackground
64         color: "lightgray"; border.color: "gray"; opacity: 0.7; radius: 5; height: 50; width: parent.width *.8
65         anchors { top: textinputelementbackground.bottom; topMargin: 100; horizontalCenter: parent.horizontalCenter }
66
67         TextInput {
68             id: secondary
69             property string ignoretext: "Nothing to see here"
70             font.pointSize: 12; text: ""; opacity: text == ignoretext ? .3 : 1; horizontalAlignment: Text.AlignHCenter
71             anchors.centerIn: parent; width: parent.width
72         }
73     }
74     Rectangle {
75         id: shadowrect
76         color: "lightgray"; height: 50; width: parent.width *.8; border.color: "gray"; opacity: 0; radius: 5
77         anchors.horizontalCenter: textinputelementbackground.horizontalCenter;
78         anchors.verticalCenter: textinputelementbackground.verticalCenter;
79         Text {
80             id: shadowtext
81             font.pointSize: 12; width: parent.width; text: ""; horizontalAlignment: Text.AlignHCenter
82             anchors.centerIn: parent
83         }
84     }
85     transitions: Transition {
86         AnchorAnimation { targets: shadowrect; duration: 1000 }
87     }
88
89     SequentialAnimation { id: copypaste
90         ScriptAction { script: { secondary.text = ""; shadowtext.text = textinputelement.selectedText; textinputelement.copy(); } }
91         NumberAnimation { target: shadowrect; property: "opacity"; to: 0.5; duration: 100 }
92         PauseAnimation { duration: 1000 }
93         ScriptAction { script: { secondary.paste(); } }
94         NumberAnimation { target: shadowrect; property: "opacity"; to: 0; duration: 100 }
95         NumberAnimation { target: shadowrect; property: "x"; to: textinputelementbackground.x; duration: 0 }
96     }
97
98     BugPanel { id: bugpanel }
99
100     SystemTestHelp { id: helpbubble; visible: statenum != 0
101         anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
102     }
103
104     states: [
105         State { name: "start"; when: statenum == 1
106             StateChangeScript {
107                 script: {
108                     textinputelement.text = "Hello, my name is TextInput"
109                     secondary.text = "Nothing to see here";
110                 }
111             }
112             PropertyChanges { target: textinputelementtest
113                 testtext: "This is a TextInput element. At present it should be saying hello.\n"+
114                 "Next, it will select the TextInput portion of the displayed text" }
115         },
116         State { name: "highlight"; when: statenum == 2
117             StateChangeScript { script: textinputelement.select(18, 27); }
118             PropertyChanges { target: textinputelementtest
119                 testtext: "TextInput should now be highlighted.\nNext, copy this to the other TextInput." }
120         },
121         State { name: "copypaste"; when: statenum == 3
122             PropertyChanges { target: copypaste; running: true }
123             AnchorChanges { target: shadowrect; anchors.verticalCenter: secondarybackground.verticalCenter }
124             PropertyChanges { target: textinputelementtest
125                 testtext: "The second TextInput should now be showing the selected text of the top TextInput.\n"+
126                 "Next, let's change the way the entered text is displayed." }
127         },
128         State { name: "passwordmode"; when: statenum == 4
129             StateChangeScript { script: textinputelement.deselect(); }
130             PropertyChanges { target: textinputelement; echoMode: TextInput.Password }
131             PropertyChanges { target: textinputelementtest
132                 testtext: "The TextInput should now be showing asterisks (*) for every character in the top TextInput - all "+
133                 textinputelement.text.length+" of them.\n"+
134                 "Next, let's return to the start." }
135         }
136     ]
137
138
139 }