forked from blackberry/Cascades-Community-Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Filtering.qml
382 lines (311 loc) · 11.9 KB
/
Filtering.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* Copyright (c) 2013 Chad Tetreault
* http://palebanana.com - @chadtatro
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import bb.cascades 1.0
import bb.data 1.0
BasePage {
id: filterPage
property variant shareOrSave
property variant activeThumb: ""
onCreationCompleted: {
// you can change the head image to whatever you like for each page
headerimage.imageSource = "asset:///images/header-filtermama.png";
}
Container {
id: rootContainer
background: back.imagePaint
verticalAlignment: VerticalAlignment.Fill
horizontalAlignment: HorizontalAlignment.Fill
layout: DockLayout {
}
/* ==================================================
* scrollview
* ==================================================
*/
ScrollView {
scrollViewProperties.scrollMode: ScrollMode.None
scrollViewProperties.pinchToZoomEnabled: false
scrollViewProperties.minContentScale: 1.0
scrollViewProperties.overScrollEffectMode: OverScrollEffectMode.None
preferredHeight: Infinity
preferredWidth: Infinity
verticalAlignment: VerticalAlignment.Fill
horizontalAlignment: HorizontalAlignment.Center
/* ==================================================
* webview
* ==================================================
*/
WebView {
id: webview
preferredHeight: Infinity
preferredWidth: Infinity
url: 'local:///assets/htdocs/index.html'
// make sure to comment out webinspector before releasing
settings.webInspectorEnabled: true
settings.background: Color.Black
// viewport setup
settings.viewport: {
'width': 'device-width',
'height': 'device-height',
'initial-scale': 1.0
}
// message received from webview
onMessageReceived: {
var data = message.data;
// filtering completed
if (data === 'filter-done') {
resetMama();
// is this a base64 encoded image sent to us from the webview for saving/sharing?
} else if (data.indexOf('data:image/png;base64,') > -1) {
// save the photo
data = data.replace('data:image/png;base64,', '');
filePath = app.savePhoto(data);
if (filePath) {
fileSaved = true;
}
// share file
if (shareOrSave === "share") {
app.shareFile(filePath);
} else {
toast.body = "Photo saved!";
toast.show();
}
}
spinnerOff();
}
} // end webview
} // end scrollview
// background image for filter thumbnails
ImageView {
id: backgroundFiltersImg
imageSource: "asset:///images/background-filters.png"
preferredHeight: 214
preferredWidth: 768
verticalAlignment: VerticalAlignment.Bottom
horizontalAlignment: HorizontalAlignment.Center
}
/* ==================================================
* listview - thumbnails
* ==================================================
*/
ListView {
verticalAlignment: VerticalAlignment.Bottom
horizontalAlignment: HorizontalAlignment.Center
scrollIndicatorMode: ScrollIndicatorMode.None
snapMode: SnapMode.LeadingEdge
flickMode: FlickMode.Momentum
preferredHeight: 180
leftPadding: 14
layout: StackListLayout {
orientation: LayoutOrientation.LeftToRight
headerMode: ListHeaderMode.None
}
function itemType(data, indexPath) {
return "item"
}
dataModel: ArrayDataModel {
id: theDataModel
}
// set image source of the listItem
function setImageSource(filter) {
if (filter.type == "default") {
return filter.thumbnail;
}
}
function handleFilterClick(filterData, filterItem) {
spinnerOn();
if (activeThumb !== "") {
activeThumb.opacity = 1;
}
activeThumb = filterItem;
filterItem.opacity = 0.2;
var msg = {
'cmd': 'filter',
'data': filterData
};
var message = JSON.stringify(msg);
webview.postMessage(message);
}
listItemComponents: [
ListItemComponent {
type: "item"
Container {
rightPadding: 18
id: filterItem
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Container {
verticalAlignment: VerticalAlignment.Bottom
horizontalAlignment: HorizontalAlignment.Center
layout: DockLayout {
}
ImageButton {
id: filterImageButton
preferredHeight: 160
preferredWidth: 160
defaultImageSource: filterItem.ListItem.view.setImageSource(ListItemData)
pressedImageSource: filterItem.ListItem.view.setImageSource(ListItemData)
leftMargin: 50.0
onClicked: {
filterItem.ListItem.view.handleFilterClick(ListItemData, filterItem);
}
}
Label {
text: ListItemData.title
verticalAlignment: VerticalAlignment.Bottom
horizontalAlignment: HorizontalAlignment.Center
textStyle.color: Color.create("#f1f1f1")
textStyle.fontWeight: FontWeight.W500
textStyle.textAlign: TextAlign.Center
textStyle.fontSizeValue: 0.75
}
}
} // container
} // listitemcomponent
]
} // listview
/* ==================================================
* covers screen to prevent touching while filtering
* ==================================================
*/
Container {
id: pageCover
visible: false
verticalAlignment: VerticalAlignment.Fill
horizontalAlignment: HorizontalAlignment.Fill
}
/* ==================================================
* attached objects
* ==================================================
*/
attachedObjects: [
DataSource {
id: dataSource
source: "asset:///filters/filters.json"
onDataLoaded: {
for (var i = 0; i < data.length; i ++) {
theDataModel.append(data[i])
}
}
},
// background image
ImagePaintDefinition {
id: back
repeatPattern: RepeatPattern.XY
imageSource: "asset:///images/background-body-fullsize.png"
}
]
}
/* ==================================================
* spinner helpers
* ==================================================
*/
function spinnerOn() {
spinner.visible = true;
pageCover.visible = true;
}
function spinnerOff() {
spinner.visible = false;
pageCover.visible = false;
}
/* ==================================================
* update webview when new file is picked
* ==================================================
*/
function updateWebview(imgData) {
toastProgress.show();
resetMama();
if (activeThumb !== "") {
activeThumb.opacity = 1;
activeThumb = "";
}
var msg = {
'cmd': 'loadPhoto',
'data': imgData
};
var message = JSON.stringify(msg);
webview.postMessage(message);
if (! thumbnailsLoaded) {
// load default filters
dataSource.load();
thumbnailsLoaded = true;
}
tabs.activeTab = tabProcess;
}
/* ==================================================
* reset our globals
* ==================================================
*/
function resetMama() {
filePicked = true;
fileSaved = false;
filePath = false;
}
/* ==================================================
* actions
* ==================================================
*/
actions: [
ActionItem {
title: qsTr("Capture") + Retranslate.onLanguageChanged
imageSource: "asset:///images/camera.png"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
filepicker.open();
}
},
ActionItem {
title: qsTr("Save") + Retranslate.onLanguageChanged
imageSource: "asset:///images/save.png"
onTriggered: {
shareOrSave = "save";
if (fileSaved) {
toast.body = qsTr("Photo saved!") + Retranslate.onLanguageChanged;
toast.show();
// not saved yet, let's do it now!!
} else {
spinnerOn();
var msg = {
'cmd': 'savePhoto',
'data': null
};
var message = JSON.stringify(msg);
webview.postMessage(message);
}
}
},
ActionItem {
title: qsTr("Share") + Retranslate.onLanguageChanged
imageSource: "asset:///images/share.png"
onTriggered: {
shareOrSave = "share";
// if already saved, don't save, just share
if (fileSaved) {
app.shareFile(filePath);
// not saved yet, let's do it now!!
} else {
spinnerOn();
var msg = {
'cmd': 'savePhoto',
'data': null
};
var message = JSON.stringify(msg);
webview.postMessage(message);
}
}
}
]
}