e863902ddb1a315aea85b1e26aec6fc3185186b4
[profile/ivi/qtdeclarative.git] / doc / src / snippets / qtquick1 / listview / listview.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 documentation of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **   * Redistributions of source code must retain the above copyright
16 **     notice, this list of conditions and the following disclaimer.
17 **   * Redistributions in binary form must reproduce the above copyright
18 **     notice, this list of conditions and the following disclaimer in
19 **     the documentation and/or other materials provided with the
20 **     distribution.
21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 **     the names of its contributors may be used to endorse or promote
23 **     products derived from this software without specific prior written
24 **     permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 //![import]
42 import QtQuick 1.0
43 //![import]
44
45 Item {
46
47 //![classdocs simple]
48 ListView {
49     width: 180; height: 200
50
51     model: ContactModel {}
52     delegate: Text {
53         text: name + ": " + number
54     }
55 }
56 //![classdocs simple]
57
58 //![classdocs advanced]
59 Rectangle {
60     width: 180; height: 200
61
62     Component {
63         id: contactDelegate
64         Item {
65             width: 180; height: 40
66             Column {
67                 Text { text: '<b>Name:</b> ' + name }
68                 Text { text: '<b>Number:</b> ' + number }
69             }
70         }
71     }
72
73     ListView {
74         anchors.fill: parent
75         model: ContactModel {}
76         delegate: contactDelegate
77         highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
78         focus: true
79     }
80 }
81 //![classdocs advanced]
82
83 //![delayRemove]
84 Component {
85     id: delegate
86     Item {
87         ListView.onRemove: SequentialAnimation {
88             PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true }
89             NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad }
90             PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false }
91         }
92     }
93 }
94 //![delayRemove]
95
96 //![highlightFollowsCurrentItem]
97 Component {
98     id: highlight
99     Rectangle {
100         width: 180; height: 40
101         color: "lightsteelblue"; radius: 5
102         y: list.currentItem.y
103         Behavior on y {
104             SpringAnimation {
105                 spring: 3
106                 damping: 0.2
107             }
108         }
109     }
110 }
111
112 ListView {
113     id: list
114     width: 180; height: 200
115     model: ContactModel {}
116     delegate: Text { text: name }
117
118     highlight: highlight
119     highlightFollowsCurrentItem: false
120     focus: true
121 }
122 //![highlightFollowsCurrentItem]
123
124 //![isCurrentItem]
125 ListView {
126     width: 180; height: 200
127
128     Component {
129         id: contactsDelegate
130         Rectangle {
131             id: wrapper
132             width: 180
133             height: contactInfo.height
134             color: ListView.isCurrentItem ? "black" : "red"
135             Text {
136                 id: contactInfo
137                 text: name + ": " + number
138                 color: wrapper.ListView.isCurrentItem ? "red" : "black"
139             }
140         }
141     }
142
143     model: ContactModel {}
144     delegate: contactsDelegate 
145     focus: true
146 }
147 //![isCurrentItem]
148
149 }