1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the examples of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
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
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
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."
39 ****************************************************************************/
44 // This example illustrates expanding a list item to show a more detailed view.
48 width: 400; height: 240
51 // Delegate for the recipes. This delegate has two modes:
52 // 1. List mode (default), which just shows the picture and title of the recipe.
53 // 2. Details mode, which also shows the ingredients and method.
60 // Create a property to contain the visibility of the details.
61 // We can bind multiple element's opacity to this one property,
62 // rather than having a "PropertyChanges" line for each element we
64 property real detailsOpacity : 0
69 // A simple rounded rectangle for the background
72 x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2
74 border.color: "orange"
78 // This mouse region covers the entire delegate.
79 // When clicked it changes mode to 'Details'. If we are already
80 // in Details mode, then no change will happen.
83 onClicked: recipe.state = 'Details';
86 // Lay out the page: picture, title and ingredients at the top, and method at the
87 // bottom. Note that elements that should not be visible in the list
88 // mode have their opacity set to recipe.detailsOpacity.
91 x: 10; y: 10; height: recipeImage.height; width: parent.width
101 width: background.width - recipeImage.width - 20; height: recipeImage.height
106 font.bold: true; font.pointSize: 16
111 font.pointSize: 12; font.bold: true
112 opacity: recipe.detailsOpacity
117 wrapMode: Text.WordWrap
119 opacity: recipe.detailsOpacity
126 x: 10; width: parent.width - 20
127 anchors { top: topLayout.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 }
128 opacity: recipe.detailsOpacity
132 anchors.top: parent.top
134 font.pointSize: 12; font.bold: true
140 anchors { top: methodTitle.bottom; bottom: parent.bottom }
141 contentHeight: methodText.height
144 Text { id: methodText; text: method; wrapMode: Text.WordWrap; width: details.width }
148 anchors { right: flick.right; top: flick.top }
149 source: "content/pics/moreUp.png"
150 opacity: flick.atYBeginning ? 0 : 1
154 anchors { right: flick.right; bottom: flick.bottom }
155 source: "content/pics/moreDown.png"
156 opacity: flick.atYEnd ? 0 : 1
160 // A button to close the detailed view, i.e. set the state back to default ('').
163 anchors { right: background.right; rightMargin: 10 }
164 opacity: recipe.detailsOpacity
167 onClicked: recipe.state = '';
173 PropertyChanges { target: background; color: "white" }
174 PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger
175 PropertyChanges { target: recipe; detailsOpacity: 1; x: 0 } // Make details visible
176 PropertyChanges { target: recipe; height: listView.height } // Fill the entire list area with the detailed view
178 // Move the list so that this item is at the top.
179 PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y }
181 // Disallow flicking while we're in detailed view
182 PropertyChanges { target: recipe.ListView.view; interactive: false }
185 transitions: Transition {
186 // Make the state changes smooth
188 ColorAnimation { property: "color"; duration: 500 }
189 NumberAnimation { duration: 300; properties: "detailsOpacity,x,contentY,height,width" }
199 model: RecipesModel {}
200 delegate: recipeDelegate