-
Notifications
You must be signed in to change notification settings - Fork 2
/
mustr.qml
347 lines (286 loc) · 10.1 KB
/
mustr.qml
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/**
* Mustr: Pattern downloader from COLOURlovers.com for MeeGo Harmattan
* Copyright (C) 2012 Thomas Perl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
import QtQuick 1.1
import com.nokia.meego 1.0
import com.nokia.extras 1.0
PageStackWindow {
initialPage: Page {
orientationLock: PageOrientation.LockPortrait
tools: ToolBarLayout {
ButtonRow {
anchors.left: parent.left
style: TabButtonStyle { }
TabButton {
text: 'Top'
tab: tab1
onClicked: {
listModel.category = '';
listModel.page = 0;
}
}
TabButton {
text: 'New'
tab: tab2
onClicked: {
listModel.category = '/new';
listModel.page = 0;
}
}
}
ToolIcon {
anchors.right: parent.right
iconId: 'toolbar-view-menu'
onClicked: contextMenu.open()
}
}
ContextMenu {
id: contextMenu
MenuLayout {
MenuItem {
text: 'Get more apps'
onClicked: {
Qt.openUrlExternally('http://store.ovi.com/publisher/Thomas+Perl/');
contextMenu.close();
}
}
MenuItem {
text: 'About Mustr'
onClicked: pageStack.push(aboutPage)
}
}
}
BusyIndicator {
anchors.centerIn: parent
running: visible
visible: listModel.status === XmlListModel.Loading
}
ListView {
id: listView
property int imageItemHeight: 150
header: Item {
height: listModel.page == 0?0:listView.imageItemHeight
width: parent.width
Button {
id: lastPage
anchors.centerIn: parent
text: 'Previous page'
onClicked: listModel.page -= 1
visible: listModel.page > 0 && listModel.count > 0
width: parent.width * .5
}
}
footer: Item {
height: listView.imageItemHeight
width: parent.width
Button {
id: nextPage
anchors.centerIn: parent
text: 'Next page'
onClicked: listModel.page += 1
width: parent.width * .5
visible: listModel.count > 0
}
}
anchors.fill: parent
model: XmlListModel {
id: listModel
property int perPage: 20
property int page: 0
property string category: ''
source: 'http://www.colourlovers.com/api/patterns' + category +'?numResults=' + perPage + '&resultOffset=' + (perPage * page)
onSourceChanged: console.log('src: ' + source)
query: '/patterns/pattern'
XmlRole { name: 'title'; query: 'title/string()' }
XmlRole { name: 'url'; query: 'imageUrl/string()' }
XmlRole { name: 'username'; query: 'userName/string()' }
XmlRole { name: 'website'; query: 'url/string()' }
}
delegate: Item {
width: parent.width
height: listView.imageItemHeight
Image {
clip: true
anchors.fill: parent
anchors.margins: mouseArea.pressed?10:0
fillMode: Image.Tile
Behavior on anchors.margins {
PropertyAnimation {
duration: 100
}
}
source: url
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
previewPage.title = title;
previewPage.username = username;
previewPage.website = website;
previewPage.url = url;
pageStack.push(previewPage);
}
}
Rectangle {
anchors {
right: parent.right
bottom: parent.bottom
margins: -10
}
width: credits.width + 20
height: credits.height + 20
color: '#80000000'
radius: 10
Label {
id: credits
anchors {
right: parent.right
bottom: parent.bottom
margins: 15
}
text: ' ' + title + ' by ' + username
}
}
BusyIndicator {
anchors.centerIn: parent
visible: parent.status === Image.Loading
running: visible
}
}
}
}
ScrollDecorator {
flickableItem: listView
}
}
Page {
id: previewPage
orientationLock: PageOrientation.LockPortrait
tools: ToolBarLayout {
ToolIcon {
iconId: 'toolbar-back'
onClicked: pageStack.pop()
}
}
property string title: ''
property string username: ''
property string website: ''
property string url: ''
Image {
anchors.fill: parent
fillMode: Image.Tile
source: previewPage.url
}
Rectangle {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
color: '#80000000'
height: previewColumn.height + 2*previewColumn.anchors.margins
Column {
id: previewColumn
anchors {
margins: 20
top: parent.top
left: parent.left
}
width: parent.width
Label {
text: previewPage.title
font.bold: true
font.pixelSize: 30
}
Label {
text: 'by ' + previewPage.username
}
}
MouseArea {
anchors.fill: parent
onClicked: Qt.openUrlExternally(previewPage.website)
}
}
Button {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
margins: 20
}
text: 'Use as wallpaper'
width: parent.width * .7
onClicked: wallpaper.setPattern(previewPage.url)
}
InfoBanner {
id: infoBanner
text: 'Wallpaper was successfully set.'
}
Connections {
target: wallpaper
onDone: infoBanner.show()
}
}
Page {
id: aboutPage
tools: ToolBarLayout {
ToolIcon {
iconId: 'toolbar-back'
onClicked: pageStack.pop()
}
}
Flickable {
anchors.fill: parent
contentHeight: aboutContainer.height
contentWidth: aboutContainer.width
Item {
id: aboutContainer
width: aboutPage.width
height: aboutColumn.height
Column {
id: aboutColumn
anchors {
left: parent.left
top: parent.top
right: parent.right
margins: 10
}
spacing: 10
Image {
source: 'file:///opt/mustr/mustr.png'
anchors.horizontalCenter: parent.horizontalCenter
}
Label {
text: 'Mustr 1.0.2'
font.pixelSize: 40
font.bold: true
anchors.horizontalCenter: parent.horizontalCenter
}
Label {
text: 'Patterns everywhere!'
anchors.horizontalCenter: parent.horizontalCenter
}
Item {
width: 1
height: 50
}
Label {
text: 'Author: Thomas Perl\nLicense: GNU GPL v3 or later\nPatterns by COLOURlovers.com\nLicense of patterns: CC-BY-NC-SA\nhttp://thp.io/2012/mustr/\n\nInspired by Lucas Rocha\'s "Pattrn" app\nIcon by The Best Isaac\nTab support by Seppo Tomperi\n\nPatches by:\nAndrew Olmsted'
}
}
}
}
}
Component.onCompleted: theme.inverted = true
}