7e4bdb272726c11a4c2d3c62f0606b485cd683e4
[profile/ivi/qtdeclarative.git] / tests / testapplications / elements / content / ListViewElement.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: listviewelementtest
46     anchors.fill: parent
47     property string testtext: ""
48     property bool hivis: false
49
50     Rectangle {
51         id: listviewelementbackground
52         color: "lightgray";  border.color: "gray"; radius: 5; clip: true; opacity: .1
53         height: listviewelement.height + 10; width: listviewelement.width + 10
54         anchors.centerIn: listviewelement
55     }
56
57     ListView {
58         id: listviewelement
59         height: 250; width: parent.width *.8; clip: true
60         anchors.centerIn: parent
61         model: devices
62         highlightFollowsCurrentItem: true
63         highlight: highlightrect
64         delegate: delegaterect
65         section.property: "os"
66         section.delegate: sectiondelegaterect
67         header: headerrect
68         footer: footerrect
69         spacing: 0
70         Behavior on spacing { NumberAnimation { duration: 200 } }
71     }
72
73     Component { id: delegaterect
74         Item {
75             width: listviewelement.width - 4; height: 30
76             Rectangle { color: "blue"; anchors.fill: parent; radius: 5; border.color: "black"; opacity: .1 }
77             Text { text: model.name; anchors.centerIn: parent }
78         }
79     }
80
81     Component { id: sectiondelegaterect
82         Item {
83             width: listviewelement.width - 4; height: 30
84             Rectangle { color: "green"; anchors.fill: parent; radius: 5; border.color: "black"; opacity: .5 }
85             Text { text: section; anchors.verticalCenter: parent.verticalCenter; anchors.left: parent.left; anchors.leftMargin: 5 }
86         }
87     }
88
89     Component { id: highlightrect
90         Rectangle {
91             id: coloredbox; color: "yellow"; width: listviewelement.width - 4; height: 30; radius: 5; opacity: .5; visible: hivis
92             SequentialAnimation on color { loops: Animation.Infinite; running: coloredbox.visible
93                 ColorAnimation { to: "green"; duration: 2000 }
94                 ColorAnimation { to: "yellow"; duration: 2000 }
95             }
96         }
97     }
98
99     Component { id: headerrect
100         Rectangle { id: hdr; color: "brown"; width: listviewelement.width - 4; height: 30; radius: 5; opacity: .5
101             Text { anchors.centerIn: parent; text: "Nokia Devices" }
102         }
103     }
104
105     Component { id: footerrect
106         Rectangle { id: ftr; color: "brown"; width: listviewelement.width - 4; height: 30; radius: 5; opacity: .5
107             Text { anchors.centerIn: parent; text: "Nokia pty ltd." }
108         }
109     }
110
111     SystemTestHelp { id: helpbubble; visible: statenum != 0
112         anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
113     }
114     BugPanel { id: bugpanel }
115
116     states: [
117         State { name: "start"; when: statenum == 1
118             PropertyChanges { target: listviewelementtest
119                 testtext: "This is a ListView element. At present it should be displaying the names of a few Nokia devices, ordered by Operating System.\n"+
120                 "Next, let's view the end of the list" }
121         },
122         State { name: "end"; when: statenum == 2
123             StateChangeScript { script: listviewelement.positionViewAtEnd(); }
124             PropertyChanges { target: listviewelementtest
125                 testtext: "The end of the list should now be visible.\nNext, let's add a highlight." }
126         },
127         State { name: "highlight"; when: statenum == 3
128             PropertyChanges { target: listviewelement; currentIndex: 0 }
129             StateChangeScript { script: listviewelement.positionViewAtBeginning(); }
130             PropertyChanges { target: listviewelementtest; hivis: true }
131             PropertyChanges { target: listviewelementtest
132                 testtext: "The ListView should now be showing a highlight on the first item.\n"+
133                 "Next, let's move to an item down the list." }
134         },
135         State { name: "highlight7"; when: statenum == 4
136             PropertyChanges { target: listviewelement; currentIndex: 6 }
137             PropertyChanges { target: listviewelementtest; hivis: true }
138             PropertyChanges { target: listviewelementtest
139                 testtext: "The ListView should now be showing the highlight over item 7 - the N95\n"+
140                 "Next let's add some space between them." }
141         },
142         State { name: "sections"; when: statenum == 5
143             PropertyChanges { target: listviewelement; currentIndex: 6 }
144             PropertyChanges { target: listviewelement; spacing: 5 }
145             PropertyChanges { target: listviewelementtest; hivis: true }
146             PropertyChanges { target: listviewelementtest
147                 testtext: "The ListView should now be showing a space between each list item,\n"+
148                 "but not after the header and sections, or before the footer.\n"+
149                 "Advance to restart the test." }
150         }
151     ]
152
153     ListModel {
154         id: devices
155         ListElement { name: "N900"; os: "Maemo" }
156         ListElement { name: "N810"; os: "Maemo" }
157         ListElement { name: "N9"; os: "Meego" }
158         ListElement { name: "N-Gage QD"; os: "S60 1.2" }
159         ListElement { name: "E90"; os: "S60 2nd" }
160         ListElement { name: "E72"; os: "S60 3.2" }
161         ListElement { name: "N95"; os: "S60 5.0" }
162         ListElement { name: "X6"; os: "S60 5.0" }
163         ListElement { name: "N97"; os: "Symbian^1" }
164         ListElement { name: "5800"; os: "Symbian^1" }
165         ListElement { name: "E7"; os: "Symbian^3" }
166         ListElement { name: "N8"; os: "Symbian^3" }
167         ListElement { name: "C7"; os: "Symbian^3" }
168         ListElement { name: "X7"; os: "Symbian Anna" }
169     }
170
171 }