Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / examples / declarative / particles / itemparticle / content / ExpandingDelegate.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 examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 2.0
42 import "../../../modelviews/listview/content"
43
44 // This example illustrates expanding a list item to show a more detailed view.
45
46     // Delegate for the recipes.  This delegate has two modes:
47     // 1. List mode (default), which just shows the picture and title of the recipe.
48     // 2. Details mode, which also shows the ingredients and method.
49     Component {
50         id: recipeDelegate
51
52         Item {
53             id: recipe
54
55             // Create a property to contain the visibility of the details.
56             // We can bind multiple element's opacity to this one property,
57             // rather than having a "PropertyChanges" line for each element we
58             // want to fade.
59             property real detailsOpacity : 0
60
61             //this bit changed for aesthetics
62             width: 70
63             height: 70
64             // A simple rounded rectangle for the background
65             Rectangle {
66                 id: background
67                 x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2
68                 color: "ivory"
69                 border.color: "orange"
70                 radius: 5
71             }
72             Image {
73                 anchors.fill:parent
74                 anchors.margins: -32
75                 source: "bubble.png"
76             }
77
78
79             // This mouse region covers the entire delegate.
80             // When clicked it changes mode to 'Details'.  If we are already
81             // in Details mode, then no change will happen.
82             MouseArea {
83                 anchors.fill: parent
84                 onClicked: recipe.state = 'Details';
85             }
86
87             // Lay out the page: picture, title and ingredients at the top, and method at the
88             // bottom.  Note that elements that should not be visible in the list
89             // mode have their opacity set to recipe.detailsOpacity.
90             Row {
91                 id: topLayout
92                 x: 10; y: 10; height: recipeImage.height; width: parent.width
93                 spacing: 10
94
95                 Image {
96                     id: recipeImage
97                     width: 50; height: 50
98                     source: "../../modelviews/listview/" + picture
99                 }
100
101                 Column {
102                     width: background.width - recipeImage.width - 20; height: recipeImage.height
103                     spacing: 5
104
105                     Text { 
106                         text: title
107                         font.bold: true; font.pointSize: 16
108                     }
109
110                     Text {
111                         text: "Ingredients"
112                         font.pointSize: 12; font.bold: true
113                         opacity: recipe.detailsOpacity
114                     }
115
116                     Text {
117                         text: ingredients
118                         wrapMode: Text.WordWrap
119                         width: parent.width
120                         opacity: recipe.detailsOpacity
121                     }
122                 }
123             }
124
125             Item {
126                 id: details
127                 x: 10; width: parent.width - 20
128                 anchors { top: topLayout.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 }
129                 opacity: recipe.detailsOpacity
130
131                 Text {
132                     id: methodTitle
133                     anchors.top: parent.top
134                     text: "Method"
135                     font.pointSize: 12; font.bold: true
136                 }
137
138                 Flickable {
139                     id: flick
140                     width: parent.width
141                     anchors { top: methodTitle.bottom; bottom: parent.bottom }
142                     contentHeight: methodText.height
143                     clip: true
144
145                     Text { id: methodText; text: method; wrapMode: Text.WordWrap; width: details.width }
146                 }
147
148                 Image {
149                     anchors { right: flick.right; top: flick.top }
150                     source: "../../modelviews/listview/" + "content/pics/moreUp.png"
151                     opacity: flick.atYBeginning ? 0 : 1
152                 }
153
154                 Image {
155                     anchors { right: flick.right; bottom: flick.bottom }
156                     source: "../../modelviews/listview/" + "content/pics/moreDown.png"
157                     opacity: flick.atYEnd ? 0 : 1
158                 }
159             }
160
161             // A button to close the detailed view, i.e. set the state back to default ('').
162             TextButton {
163                 y: 10
164                 anchors { right: background.right; rightMargin: 10 }
165                 opacity: recipe.detailsOpacity
166                 text: "Close"
167
168                 onClicked: recipe.state = '';
169             }
170
171             states: State {
172                 name: "Details"
173
174                 PropertyChanges { target: background; color: "white" }
175                 PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger
176                 PropertyChanges { target: recipe; detailsOpacity: 1; x: 0; opacity: 1 } // Make details visible
177                 PropertyChanges { target: recipe; height: root.height; width: root.height; x:0; y:0; z:100} // Fill the entire list area with the detailed view
178
179                 // Move the list so that this item is at the top.
180                 //PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y }
181
182                 // Disallow flicking while we're in detailed view
183                 //PropertyChanges { target: recipe.ListView.view; interactive: false }
184             }
185
186             transitions: Transition {
187                 //The only strictly necessary particle specific lines 
188                 to: "Details"
189                 reversible: true
190                 ScriptAction {script: {
191                     if(state == "Details")
192                         mp.freeze(index);
193                     else
194                         mp.unfreeze(index);
195                     }
196                 }
197                 // Make the state changes smooth
198                 ParallelAnimation {
199                     ColorAnimation { property: "color"; duration: 500 }
200                     NumberAnimation { duration: 300; properties: "detailsOpacity,opacity,x,y,height,width" }
201                 }
202             }
203         }
204     }