f8e9e9569b2b2ae99c4c286c438ce9e5c3c7e7da
[profile/ivi/qtdeclarative.git] / tests / testapplications / elements / content / TextEditElement.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: texteditelementtest
46     anchors.fill: parent
47     property string testtext: ""
48     property string wraptext: "Set this property to wrap the text to the TextEdit item's width. The text will only wrap if an explicit width has been set."
49
50     Rectangle {
51         id: texteditelementbackground
52         color: "green"; height: 150; width: parent.width *.8; border.color: "gray"; opacity: 0.7; radius: 5; clip: true
53         anchors.centerIn: parent
54
55         TextEdit {
56             id: texteditelement
57             font.pointSize: 12; width: parent.width; text: ""; horizontalAlignment: Text.AlignLeft
58             anchors.centerIn: parent
59             Behavior on font.pointSize { NumberAnimation { duration: 1000 } }
60             Behavior on color { ColorAnimation { duration: 1000 } }
61         }
62     }
63
64     Rectangle {
65         id: secondarybackground
66         color: "lightgray"; border.color: "gray"; opacity: 0.7; radius: 5; height: 150; width: parent.width *.8
67         anchors { top: texteditelementbackground.bottom; topMargin: 50; horizontalCenter: parent.horizontalCenter }
68
69         TextEdit {
70             id: secondary
71             property string ignoretext: "Nothing to see here"
72             font.pointSize: 12; width: parent.width; text: ""; opacity: text == ignoretext ? .3 : 1; horizontalAlignment: Text.AlignLeft
73             anchors.centerIn: parent
74         }
75     }
76     Rectangle {
77         id: shadowrect
78         color: "lightgray"; height: 50; width: parent.width *.8; border.color: "gray"; opacity: 0; radius: 5
79         anchors.horizontalCenter: texteditelementbackground.horizontalCenter;
80         anchors.verticalCenter: texteditelementbackground.verticalCenter;
81
82         Text {
83             id: shadowtext
84             font.pointSize: 12; width: parent.width; text: ""; horizontalAlignment: Text.AlignLeft
85             anchors.centerIn: parent
86         }
87     }
88     transitions: Transition {
89         AnchorAnimation { targets: shadowrect; duration: 1000 }
90     }
91
92     SequentialAnimation { id: copypaste
93         ScriptAction { script: { secondary.text = ""; shadowtext.text = texteditelement.selectedText; texteditelement.copy(); } }
94         NumberAnimation { target: shadowrect; property: "opacity"; to: 0.5; duration: 100 }
95         PauseAnimation { duration: 1000 }
96         ScriptAction { script: { secondary.paste(); } }
97         NumberAnimation { target: shadowrect; property: "opacity"; to: 0; duration: 100 }
98         NumberAnimation { target: shadowrect; property: "x"; to: texteditelementbackground.x; duration: 0 }
99     }
100
101     SystemTestHelp { id: helpbubble; visible: statenum != 0
102         anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
103     }
104     BugPanel { id: bugpanel }
105
106     states: [
107         State { name: "start"; when: statenum == 1
108             StateChangeScript {
109                 script: {
110                     texteditelement.text = "Hello, my name is TextEdit"
111                     secondary.text = "Nothing to see here";
112                 }
113             }
114             PropertyChanges { target: texteditelementtest
115                 testtext: "This is a TextEdit element. At present it should be saying hello.\n"+
116                 "Next, the TextEdit portion of the displayed text will be selected" }
117         },
118         State { name: "highlight"; when: statenum == 2
119             StateChangeScript { script: texteditelement.select(18, 26); }
120             PropertyChanges { target: texteditelementtest
121                 testtext: "TextEdit should now be highlighted.\nNext, it will be copied this to the other TextEdit." }
122         },
123         State { name: "copypaste"; when: statenum == 3
124             PropertyChanges { target: copypaste; running: true }
125             AnchorChanges { target: shadowrect; anchors.verticalCenter: secondarybackground.verticalCenter }
126             PropertyChanges { target: texteditelementtest
127                 testtext: "The second TextEdit should now be showing the selected text of the top TextEdit.\n"+
128                 "Next, a larger amount of text will be entered." }
129         },
130         State { name: "largetextnowrap"; when: statenum == 4
131         PropertyChanges { target: texteditelement; text: wraptext }
132             PropertyChanges { target: texteditelementtest
133                 testtext: "The TextEdit should now be showing a line of text, chopped off by the edge of the rectangle.\n"+
134                 "Next, the TextEdit will set wrapping to fix that." }
135         },
136         State { name: "largetextwrap"; when: statenum == 5
137         PropertyChanges { target: texteditelement; text: wraptext; wrapMode: TextEdit.WordWrap }
138             PropertyChanges { target: texteditelementtest
139                 testtext: "The TextEdit should now be showing a block of text.\n"+
140                 "Advance to restart the test." }
141         }
142     ]
143
144 }