Immense Particles Refactor Part C
[profile/ivi/qtdeclarative.git] / demos / declarative / flickr / content / UnifiedDelegate.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43 import QtQuick.Particles 2.0
44
45 Package {
46     function photoClicked() {
47         imageDetails.photoTitle = title;
48         imageDetails.photoTags = tags;
49         imageDetails.photoWidth = photoWidth;
50         imageDetails.photoHeight = photoHeight;
51         imageDetails.photoType = photoType;
52         imageDetails.photoAuthor = photoAuthor;
53         imageDetails.photoDate = photoDate;
54         imageDetails.photoUrl = url;
55         imageDetails.rating = 0;
56         scaleMe.state = "Details";
57     }
58
59     Item {
60         id: gridwrapper;
61         width: GridView.view.cellWidth; height: GridView.view.cellHeight
62         Package.name: "grid"
63     }
64     Item {
65         id: streamwrapper;
66         width: 80; height: 80
67         Package.name: "stream"
68         function pleaseFreeze(){
69             ModelParticle.particle.freeze(streamwrapper);
70         }
71         function pleaseUnfreeze(){
72             ModelParticle.particle.unfreeze(streamwrapper);
73         }
74     }
75     Item {
76         //anchors.centerIn: parent//Doesn't animate :(
77         width: 80; height: 80
78         scale: 0.0
79         Behavior on scale { NumberAnimation { easing.type: Easing.InOutQuad} }
80         id: scaleMe
81
82         Item {
83             id: whiteRectContainer
84             width: 77; height: 77; anchors.centerIn: parent
85             Rectangle {
86                 id: whiteRect; width: 77; height: 77; color: "#dddddd"; smooth: true
87                 x:0; y:0
88                 Image { id: thumb; source: imagePath; x: 1; y: 1; smooth: true }
89                 Image { source: "images/gloss.png" }
90                 MouseArea { anchors.fill: parent; onClicked: photoClicked() }
91             }
92         }
93
94         Connections {
95             target: toolBar
96             onButton2Clicked: if (scaleMe.state == 'Details' ) scaleMe.state = 'Show'
97         }
98
99             state: 'inStream'
100         states: [
101             State {
102                 name: "Show"; when: thumb.status == Image.Ready
103                 PropertyChanges { target: scaleMe; scale: 1; }
104             },
105             State {
106                 name: "Details"
107                 PropertyChanges { target: scaleMe; scale: 1 }
108                 ParentChange { target: whiteRect; x: 10; y: 20; parent: imageDetails.frontContainer }
109                 PropertyChanges { target: background; state: "DetailedView" }
110             }
111         ]
112         transitions: [
113             Transition {
114                 from: "Show"; to: "Details"
115                 ScriptAction{ script: streamwrapper.pleaseFreeze(); }
116                 ParentAnimation {
117                     via: foreground
118                     NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad }
119                 }
120             },
121             Transition {
122                 from: "Details"; to: "Show"
123                 SequentialAnimation{
124                     ParentAnimation {
125                         via: foreground
126                         NumberAnimation { properties: "x,y"; duration: 500; easing.type: Easing.InOutQuad }
127                     }
128                     ScriptAction{ script: streamwrapper.pleaseUnfreeze(); }
129                 }
130             }
131         ]
132         Item{
133             id: stateContainer
134             states: [
135                 State {
136                     name: 'inStream'
137                     when: screen.inGridView == false
138                     ParentChange { 
139                         target: scaleMe; parent: streamwrapper 
140                         x: 0; y: 0; 
141                     }
142                 },
143                 State {
144                     name: 'inGrid'
145                     when: screen.inGridView == true
146                     ParentChange {
147                         target: scaleMe; parent: gridwrapper
148                         x: 0; y: 0;
149                     }
150                 }
151             ]
152
153             transitions: [
154                 Transition {
155                     ParentAnimation {
156                         NumberAnimation { target: scaleMe; properties: 'x,y,width,height'; duration: 300 }
157                     }
158                 }
159             ]
160         }
161     }
162 }