summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/flickr.qml
blob: d8a27d535d4d70b96dec64e4cb4db84607d82b9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import Qt 4.6

import "content"

Item {
    id: MainWindow; width: 800; height: 450

    property bool showPathView : false

    resources: [
        XmlListModel {
            id: FeedModel
            property string tags : TagsEdit.text
            source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2"
            query: "/rss/channel/item"
            namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";"

            XmlRole { name: "title"; query: "title/string()" }
            XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" }
            XmlRole { name: "url"; query: "media:content/@url/string()" }
            XmlRole { name: "description"; query: "description/string()" }
            XmlRole { name: "tags"; query: "media:category/string()" }
            XmlRole { name: "photoWidth"; query: "media:content/@width/string()" }
            XmlRole { name: "photoHeight"; query: "media:content/@height/string()" }
            XmlRole { name: "photoType"; query: "media:content/@type/string()" }
            XmlRole { name: "photoAuthor"; query: "author/string()" }
            XmlRole { name: "photoDate"; query: "pubDate/string()" }
        },

        Component {
        id: PhotoDelegate
        Item {
            id: Wrapper; width: 85; height: 85
            scale: Wrapper.PathView.scale; z: Wrapper.PathView.z

            transform: Rotation {
                id: Rotation; origin.x: Wrapper.width/2; origin.y: Wrapper.height/2
                axis.y: 1; axis.z: 0; angle: Wrapper.PathView.angle
            }

            Connection {
                sender: ImageDetails; signal: "closed()"
                script: {
                    if (Wrapper.state == 'Details') {
                        Wrapper.state = '';
                        ImageDetails.photoUrl = "";
                    }
                }
            }

            Script {
               function photoClicked() {
                   ImageDetails.photoTitle = title;
                   ImageDetails.photoDescription = description;
                   ImageDetails.photoTags = tags;
                   ImageDetails.photoWidth = photoWidth;
                   ImageDetails.photoHeight = photoHeight;
                   ImageDetails.photoType = photoType;
                   ImageDetails.photoAuthor = photoAuthor;
                   ImageDetails.photoDate = photoDate;
                   ImageDetails.photoUrl = url;
                   ImageDetails.rating = 0;
                   Wrapper.state = "Details";
               }
            }

            Rectangle {
                id: WhiteRect; anchors.fill: parent; color: "white"; radius: 5

                Loading { x: 26; y: 26; visible: Thumb.status!=1 }
                Image { id: Thumb; source: imagePath; x: 5; y: 5 }

                Item {
                    id: Shadows
                    Image { source: "content/pics/shadow-right.png"; x: WhiteRect.width; height: WhiteRect.height }
                    Image { source: "content/pics/shadow-bottom.png"; y: WhiteRect.height; width: WhiteRect.width }
                    Image { id: Corner; source: "content/pics/shadow-corner.png"; x: WhiteRect.width; y: WhiteRect.height }
                }
            }

            MouseRegion { anchors.fill: Wrapper; onClicked: { photoClicked() } }

            states: [
                State {
                    name: "Details"
                    PropertyChanges { target: ImageDetails; z: 2 }
                    ParentChange { target: Wrapper; parent: ImageDetails.frontContainer }
                    PropertyChanges { target: Wrapper; x: 45; y: 35; scale: 1; z: 1000 }
                    PropertyChanges { target: Rotation; angle: 0 }
                    PropertyChanges { target: Shadows; opacity: 0 }
                    PropertyChanges { target: ImageDetails; y: 20 }
                    PropertyChanges { target: PhotoGridView; y: "-480" }
                    PropertyChanges { target: PhotoPathView; y: "-480" }
                    PropertyChanges { target: ViewModeButton; opacity: 0 }
                    PropertyChanges { target: TagsEdit; opacity: 0 }
                    PropertyChanges { target: FetchButton; opacity: 0 }
                    PropertyChanges { target: CategoryText; y: "-50" }
                }
            ]

            transitions: [
                Transition {
                    from: "*"; to: "Details"
                    ParentAction { }
                    NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" }
                },
                Transition {
                    from: "Details"; to: "*"
                    SequentialAnimation {
                        ParentAction { }
                        NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" }
                        PropertyAction { target: Wrapper; properties: "z" }
                    }
                }
            ]

        }
        }
    ]

    Item {
        id: Background

        anchors.fill: parent

        Image { source: "content/pics/background.png"; anchors.fill: parent }

        Loading { anchors.centerIn: parent; visible: FeedModel.status }

        GridView {
            id: PhotoGridView; model: FeedModel; delegate: PhotoDelegate; cacheBuffer: 100
            cellWidth: 105; cellHeight: 105; x:32; y: 80; width: 800; height: 330; z: 1
        }

        PathView {
            id: PhotoPathView; model: FeedModel; delegate: PhotoDelegate
            y: -380; width: 800; height: 330; pathItemCount: 10; z: 1
            path: Path {
                startX: -50; startY: 40;

                PathAttribute { name: "scale"; value: 1 }
                PathAttribute { name: "angle"; value: -45 }

                PathCubic {
                    x: 400; y: 220
                    control1X: 140; control1Y: 40
                    control2X: 210; control2Y: 220
                }

                PathAttribute { name: "scale"; value: 1.2  }
                PathAttribute { name: "z"; value: 1 }
                PathAttribute { name: "angle"; value: 0 }

                PathCubic {
                    x: 850; y: 40
                    control2X: 660; control2Y: 40
                    control1X: 590; control1Y: 220
                }

                PathAttribute { name: "scale"; value: 1 }
                PathAttribute { name: "angle"; value: 45 }
            }

        }

        ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 }

        MediaButton {
            id: ViewModeButton; x: 680; y: 410; text: "View Mode"
            onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true }
        }

        MediaButton {
            id: FetchButton
            text: "Update"
            anchors.right: ViewModeButton.left; anchors.rightMargin: 5
            anchors.top: ViewModeButton.top
            onClicked: { FeedModel.reload(); }
        }

        MediaLineEdit {
            id: TagsEdit;
            label: "Tags"
            anchors.right: FetchButton.left; anchors.rightMargin: 5
            anchors.top: ViewModeButton.top
        }

        states: [
            State {
                name: "PathView"
                when: MainWindow.showPathView == true
                PropertyChanges { target: PhotoPathView; y: 80 }
                PropertyChanges { target: PhotoGridView; y: -380 }
            }
        ]

        transitions: [
            Transition {
                from: "*"; to: "*"
                NumberAnimation { properties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" }
            }
        ]
    }

    Text {
        id: CategoryText;  anchors.horizontalCenter: parent.horizontalCenter; y: 15;
        text: "Flickr - " +
            (FeedModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + FeedModel.tags)
        font.pointSize: 20; font.bold: true; color: "white"; style: "Raised"; styleColor: "black"
    }
}