1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtDeclarative module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** GNU General Public License Usage
31** Alternatively, this file may be used under the terms of the GNU
32** General Public License version 3.0 as published by the Free Software
33** Foundation and appearing in the file LICENSE.GPL included in the
34** packaging of this file.  Please review the following information to
35** ensure the GNU General Public License version 3.0 requirements will be
36** met: http://www.gnu.org/copyleft/gpl.html.
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42import QtQuick 1.1
43import "script/script.js" as Script
44
45Package {
46    Item { id: stackItem; Package.name: 'stack'; width: 160; height: 153; z: stackItem.PathView.z }
47    Item { id: listItem; Package.name: 'list'; width: mainWindow.width + 40; height: 153 }
48    Item { id: gridItem; Package.name: 'grid'; width: 160; height: 153 }
49
50    Item {
51        width: 160; height: 153
52
53        Item {
54            id: photoWrapper
55
56            property double randomAngle: Math.random() * (2 * 6 + 1) - 6
57            property double randomAngle2: Math.random() * (2 * 6 + 1) - 6
58
59            x: 0; y: 0; width: 140; height: 133
60            z: stackItem.PathView.z; rotation: photoWrapper.randomAngle
61
62            BorderImage {
63                anchors {
64                    fill: originalImage.status == Image.Ready ? border : placeHolder
65                    leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8
66                }
67                source: 'images/box-shadow.png'; smooth: true
68                border.left: 10; border.top: 10; border.right: 10; border.bottom: 10
69            }
70            Rectangle {
71                id: placeHolder
72
73                property int w: Script.getWidth(content)
74                property int h: Script.getHeight(content)
75                property double s: Script.calculateScale(w, h, photoWrapper.width)
76
77                color: 'white'; anchors.centerIn: parent; smooth: true
78                width:  w * s; height: h * s; visible: originalImage.status != Image.Ready
79                Rectangle {
80                    color: "#878787"; smooth: true
81                    anchors { fill: parent; topMargin: 3; bottomMargin: 3; leftMargin: 3; rightMargin: 3 }
82                }
83            }
84            Rectangle {
85                id: border; color: 'white'; anchors.centerIn: parent; smooth: true
86                width: originalImage.paintedWidth + 6; height: originalImage.paintedHeight + 6
87                visible: !placeHolder.visible
88            }
89            BusyIndicator { anchors.centerIn: parent; on: originalImage.status != Image.Ready }
90            Image {
91                id: originalImage; smooth: true; source: "http://" + Script.getImagePath(content); cache: false
92                fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
93            }
94            Image {
95                id: hqImage; smooth: true; source: ""; visible: false; cache: false
96                fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
97            }
98            Binding {
99                target: mainWindow; property: "downloadProgress"; value: hqImage.progress
100                when: listItem.ListView.isCurrentItem
101            }
102            Binding {
103                target: mainWindow; property: "imageLoading"
104                value: (hqImage.status == Image.Loading) ? 1 : 0; when: listItem.ListView.isCurrentItem
105            }
106            MouseArea {
107                width: originalImage.paintedWidth; height: originalImage.paintedHeight; anchors.centerIn: originalImage
108                onClicked: {
109                    if (albumWrapper.state == 'inGrid') {
110                        gridItem.GridView.view.currentIndex = index;
111                        albumWrapper.state = 'fullscreen'
112                    } else {
113                        gridItem.GridView.view.currentIndex = index;
114                        albumWrapper.state = 'inGrid'
115                    }
116                }
117            }
118
119            states: [
120            State {
121                name: 'stacked'; when: albumWrapper.state == ''
122                ParentChange { target: photoWrapper; parent: stackItem; x: 10; y: 10 }
123                PropertyChanges { target: photoWrapper; opacity: stackItem.PathView.onPath ? 1.0 : 0.0 }
124            },
125            State {
126                name: 'inGrid'; when: albumWrapper.state == 'inGrid'
127                ParentChange { target: photoWrapper; parent: gridItem; x: 10; y: 10; rotation: photoWrapper.randomAngle2 }
128            },
129            State {
130                name: 'fullscreen'; when: albumWrapper.state == 'fullscreen'
131                ParentChange {
132                    target: photoWrapper; parent: listItem; x: 0; y: 0; rotation: 0
133                    width: mainWindow.width; height: mainWindow.height
134                }
135                PropertyChanges { target: border; opacity: 0 }
136                PropertyChanges { target: hqImage; source: listItem.ListView.isCurrentItem ? hq : ""; visible: true }
137            }
138            ]
139
140            transitions: [
141            Transition {
142                from: 'stacked'; to: 'inGrid'
143                SequentialAnimation {
144                    PauseAnimation { duration: 10 * index }
145                    ParentAnimation {
146                        target: photoWrapper; via: foreground
147                        NumberAnimation {
148                            target: photoWrapper; properties: 'x,y,rotation,opacity'; duration: 600; easing.type: 'OutQuart'
149                        }
150                    }
151                }
152            },
153            Transition {
154                from: 'inGrid'; to: 'stacked'
155                ParentAnimation {
156                    target: photoWrapper; via: foreground
157                    NumberAnimation { properties: 'x,y,rotation,opacity'; duration: 600; easing.type: 'OutQuart' }
158                }
159            },
160            Transition {
161                from: 'inGrid'; to: 'fullscreen'
162                SequentialAnimation {
163                    PauseAnimation { duration: gridItem.GridView.isCurrentItem ? 0 : 600 }
164                    ParentAnimation {
165                        target: photoWrapper; via: foreground
166                        NumberAnimation {
167                            targets: [ photoWrapper, border ]
168                            properties: 'x,y,width,height,opacity,rotation'
169                            duration: gridItem.GridView.isCurrentItem ? 600 : 1; easing.type: 'OutQuart'
170                        }
171                    }
172                }
173            },
174            Transition {
175                from: 'fullscreen'; to: 'inGrid'
176                ParentAnimation {
177                    target: photoWrapper; via: foreground
178                    NumberAnimation {
179                        targets: [ photoWrapper, border ]
180                        properties: 'x,y,width,height,rotation,opacity'
181                        duration: gridItem.GridView.isCurrentItem ? 600 : 1; easing.type: 'OutQuart'
182                    }
183                }
184            }
185            ]
186        }
187    }
188}
189