~nik90/unav/marcos-menu-structure

« back to all changes in this revision

Viewing changes to qml/Location.qml

  • Committer: Nekhelesh Ramananthan
  • Date: 2016-04-17 16:42:49 UTC
  • Revision ID: krnekhelesh@gmail.com-20160417164249-fa49ookn58d9py72
Page headers now hide while scrolling search results and favorites

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
    signal favorited(string lat, string lng, string name)
30
30
 
31
 
    TextField {
32
 
        id: searchField
33
 
 
34
 
        primaryItem: Icon {
35
 
            height: units.gu(2)
36
 
            name: "find"
37
 
        }
38
 
 
39
 
        width: parent.width
40
 
        anchors.top: parent.top
41
 
        hasClearButton: true
42
 
        inputMethodHints: Qt.ImhNoPredictiveText
43
 
        placeholderText: i18n.tr("Search location")
44
 
 
45
 
        onTriggered: {
46
 
            if (text.trim()) {
47
 
                statusLabel.visible = true
48
 
                statusLabel.text = i18n.tr("Searching…");
49
 
                xmlSearchModel.searchString = text;
50
 
                xmlSearchModel.search();
51
 
            } else {
52
 
                searchField.text = "";
53
 
            }
54
 
        }
55
 
 
56
 
        onTextChanged: {
57
 
            if (!text.trim()) {
58
 
                xmlSearchModel.clear()
59
 
                sortedSearchModel.clear()
60
 
            }
61
 
        }
62
 
    }
 
31
    property ListView flickable: listView
63
32
 
64
33
    //OSMTouch Model:
65
34
    XmlListModel {
217
186
        running: xmlSearchModel.status === XmlListModel.Loading
218
187
    }
219
188
 
220
 
    Loader {
221
 
        id: listViewLoader
222
 
        anchors { top: searchField.bottom; topMargin: units.gu(0); bottom: parent.bottom; left: parent.left; right: parent.right; leftMargin: units.gu(-2); rightMargin: units.gu(-2) }
223
 
        sourceComponent: xmlSearchModel.status !== XmlListModel.Loading && sortedSearchModel.count === 0 ? historyListViewComponent : resultsListViewComponent
224
 
    }
225
 
 
226
 
    Component {
227
 
        id: resultsListViewComponent
228
 
        ListView {
229
 
            id: resultsListView
230
 
 
231
 
            clip: true
232
 
            model: sortedSearchModel
233
 
 
234
 
            delegate: ListItem {
235
 
                height: resultsDelegateLayout.height + divider.height
236
 
                trailingActions:  ListItemActions {
237
 
                    actions: [
238
 
                        Action {
239
 
                            iconName: "send"
240
 
                            onTriggered: {
241
 
                                if (navApp.settings.saveHistory) {
242
 
                                    UnavDB.saveToSearchHistory(model.name, model.lat, model.lng)
243
 
                                }
244
 
                                mainPageStack.clear();
245
 
                                mainPageStack.center_onpos = 2;
246
 
                                mainPageStack.routeState = 'yes'
247
 
                                mainPageStack.executeJavaScript("calc2coord(" + model.lat + "," + model.lng + ");")
248
 
                            }
249
 
                        },
250
 
                        Action {
251
 
                            iconName: "share"
252
 
                            onTriggered: {
253
 
                                mainPageStack.push(Qt.resolvedUrl("Share.qml"), {"lat": model.lat, "lon": model.lng})
254
 
                            }
255
 
                        },
256
 
                        Action {
257
 
                            iconName: "non-starred"
258
 
                            onTriggered: {
259
 
                                container.favorited(model.lat, model.lng, model.name)
260
 
                            }
261
 
                        }
262
 
                    ]
263
 
                }
264
 
 
265
 
                onClicked: {
266
 
                    if (navApp.settings.saveHistory) {
267
 
                        UnavDB.saveToSearchHistory(model.name, model.lat, model.lng);
268
 
                    }
 
189
    ListView {
 
190
        id: listView
 
191
 
 
192
        clip: true
 
193
        anchors { fill: parent; topMargin: units.gu(2) }
 
194
        model: xmlSearchModel.status !== XmlListModel.Loading && sortedSearchModel.count === 0 ? historyModel : sortedSearchModel
 
195
        delegate: xmlSearchModel.status !== XmlListModel.Loading && sortedSearchModel.count === 0 ? historyDelegateComponent : searchDelegateComponent
 
196
 
 
197
        section.property: "title"
 
198
        section.criteria: ViewSection.FullString
 
199
        section.delegate: ListItemHeader {
 
200
            title: section
 
201
        }
 
202
 
 
203
        header: TextField {
 
204
            id: searchField
 
205
 
 
206
            primaryItem: Icon {
 
207
                height: units.gu(2)
 
208
                name: "find"
 
209
            }
 
210
 
 
211
            anchors { top: parent.top; left: parent.left; right: parent.right; margins: units.gu(2) }
 
212
            hasClearButton: true
 
213
            inputMethodHints: Qt.ImhNoPredictiveText
 
214
            placeholderText: i18n.tr("Search location")
 
215
 
 
216
            onTriggered: {
 
217
                if (text.trim()) {
 
218
                    statusLabel.visible = true
 
219
                    statusLabel.text = i18n.tr("Searching…");
 
220
                    xmlSearchModel.searchString = text;
 
221
                    xmlSearchModel.search();
 
222
                } else {
 
223
                    searchField.text = "";
 
224
                }
 
225
            }
 
226
 
 
227
            onTextChanged: {
 
228
                if (!text.trim()) {
 
229
                    xmlSearchModel.clear()
 
230
                    sortedSearchModel.clear()
 
231
                }
 
232
            }
 
233
        }
 
234
    }
 
235
 
 
236
    Component {
 
237
        id: searchDelegateComponent
 
238
        ListItem {
 
239
            height: resultsDelegateLayout.height + divider.height
 
240
            trailingActions: ListItemActions {
 
241
                actions: [
 
242
                    Action {
 
243
                        iconName: "send"
 
244
                        onTriggered: {
 
245
                            if (navApp.settings.saveHistory) {
 
246
                                UnavDB.saveToSearchHistory(model.name, model.lat, model.lng)
 
247
                            }
 
248
                            mainPageStack.clear();
 
249
                            mainPageStack.center_onpos = 2;
 
250
                            mainPageStack.routeState = 'yes'
 
251
                            mainPageStack.executeJavaScript("calc2coord(" + model.lat + "," + model.lng + ");")
 
252
                        }
 
253
                    },
 
254
                    Action {
 
255
                        iconName: "share"
 
256
                        onTriggered: {
 
257
                            mainPageStack.push(Qt.resolvedUrl("Share.qml"), {"lat": model.lat, "lon": model.lng})
 
258
                        }
 
259
                    },
 
260
                    Action {
 
261
                        iconName: "non-starred"
 
262
                        onTriggered: {
 
263
                            container.favorited(model.lat, model.lng, model.name)
 
264
                        }
 
265
                    }
 
266
                ]
 
267
            }
 
268
 
 
269
            onClicked: {
 
270
                if (navApp.settings.saveHistory) {
 
271
                    UnavDB.saveToSearchHistory(model.name, model.lat, model.lng);
 
272
                }
 
273
                mainPageStack.clear();
 
274
                mainPageStack.executeJavaScript("ui.markers_POI_set([{title: \"" + model.name + "\", lat: " + model.lat + ", lng: " + model.lng + "}]);");
 
275
            }
 
276
 
 
277
            ListItemLayout {
 
278
                id: resultsDelegateLayout
 
279
 
 
280
                title.text: model.name
 
281
                title.maximumLineCount: 2
 
282
                title.wrapMode: Text.WordWrap
 
283
                subtitle.text: QmlJs.formatDistance(model.distance, navApp.settings.unit)
 
284
                subtitle.visible: mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null"
 
285
 
 
286
                Icon {
 
287
                    id: resIcon
 
288
                    height: units.gu(2.5)
 
289
                    width: height
 
290
                    visible: model.icon !== ""
 
291
                    source: model.icon
 
292
                    SlotsLayout.position: SlotsLayout.Last
 
293
                }
 
294
            }
 
295
        }
 
296
    }
 
297
 
 
298
    Component {
 
299
        id: historyDelegateComponent
 
300
        ListItem {
 
301
            height: historyDelegateLayout.height + divider.height
 
302
            leadingActions:  ListItemActions {
 
303
                actions: [
 
304
                    Action {
 
305
                        iconName: "delete"
 
306
                        onTriggered: {
 
307
                            switch (model.title) {
 
308
                            case i18n.tr("Search history"):
 
309
                                UnavDB.removeHistorySearch(model.name);
 
310
                                break;
 
311
                            case i18n.tr("Nearby history"):
 
312
                                UnavDB.removeHistoryNearby(model.en_name);
 
313
                                break;
 
314
                            case i18n.tr("Favorite history"):
 
315
                                UnavDB.removeHistoryFavorite(model.name);
 
316
                            }
 
317
                            historyModel.initialize();
 
318
                        }
 
319
                    }
 
320
                ]
 
321
            }
 
322
 
 
323
            trailingActions:  ListItemActions {
 
324
                actions: [
 
325
                    Action {
 
326
                        iconName: "send"
 
327
                        visible: model.title !== i18n.tr("Nearby history")
 
328
                        onTriggered: {
 
329
                            mainPageStack.clear();
 
330
                            mainPageStack.center_onpos = 2;
 
331
                            mainPageStack.routeState = 'yes';
 
332
                            mainPageStack.executeJavaScript("calc2coord("+ model.lat + "," + model.lng + ");");
 
333
                        }
 
334
                    },
 
335
                    Action {
 
336
                        iconName: "share"
 
337
                        visible: model.title !== i18n.tr("Nearby history")
 
338
                        onTriggered: {
 
339
                            mainPageStack.push(Qt.resolvedUrl("Share.qml"), {"lat": model.lat, "lon": model.lng});
 
340
                        }
 
341
                    }
 
342
                ]
 
343
            }
 
344
 
 
345
            ListItemLayout {
 
346
                id: historyDelegateLayout
 
347
 
 
348
                title.text: model.name
 
349
                title.wrapMode: Text.WordWrap
 
350
                title.maximumLineCount: 2
 
351
                subtitle.text: QmlJs.formatDistance(QmlJs.calcPoiDistance(mainPageStack.currentLat, mainPageStack.currentLng, model.lat, model.lng, 10), navApp.settings.unit)
 
352
                subtitle.visible: model.title !== i18n.tr("Nearby history") && mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null"
 
353
 
 
354
                Loader {
 
355
                    id: resultTypeIconLoader
 
356
                    SlotsLayout.position: SlotsLayout.First
 
357
                    SlotsLayout.overrideVerticalPositioning: true
 
358
                    anchors.verticalCenter: parent.verticalCenter
 
359
                    sourceComponent: model.title !== i18n.tr("Nearby history") ? resultTypeIconName : resultTypeIconSource
 
360
                }
 
361
 
 
362
                Component {
 
363
                    id: resultTypeIconName
 
364
                    Icon {
 
365
                        width: height
 
366
                        height: units.gu(2.5)
 
367
                        color: UbuntuColors.jet
 
368
                        name: {
 
369
                            if (model.title === i18n.tr("Search history"))
 
370
                                return "history"
 
371
                            else if (model.title === i18n.tr("Favorite history"))
 
372
                                return "starred"
 
373
                        }
 
374
                    }
 
375
                }
 
376
 
 
377
                Component {
 
378
                    id: resultTypeIconSource
 
379
                    Icon {
 
380
                        width: height
 
381
                        height: units.gu(2.5)
 
382
                        source: Qt.resolvedUrl("../nav/img/poi/" + model.en_name + ".svg")
 
383
                    }
 
384
                }
 
385
 
 
386
                Icon {
 
387
                    id: progressionIcon
 
388
                    height: units.gu(2.5)
 
389
                    name: "next"
 
390
                    visible: model.title === i18n.tr("Nearby history")
 
391
                    SlotsLayout.position: SlotsLayout.Last
 
392
                }
 
393
            }
 
394
 
 
395
            onClicked: {
 
396
                if (model.title === i18n.tr("Nearby history")) {
 
397
                    mainPageStack.push(Qt.resolvedUrl("PoiListPage.qml"),
 
398
                                       {
 
399
                                           lat: mainPageStack.currentLat,
 
400
                                           lng: mainPageStack.currentLng,
 
401
                                           poiType: model.name,
 
402
                                           clause: model.clause,
 
403
                                           geoDistFactor: 5
 
404
                                       })
 
405
                } else {
269
406
                    mainPageStack.clear();
270
 
                    mainPageStack.executeJavaScript("ui.markers_POI_set([{title: \"" + model.name + "\", lat: " + model.lat + ", lng: " + model.lng + "}]);");
271
 
                }
272
 
 
273
 
                ListItemLayout {
274
 
                    id: resultsDelegateLayout
275
 
 
276
 
                    title.text: model.name
277
 
                    title.maximumLineCount: 2
278
 
                    title.wrapMode: Text.WordWrap
279
 
                    subtitle.text: QmlJs.formatDistance(model.distance, navApp.settings.unit)
280
 
                    subtitle.visible: mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null"
281
 
 
282
 
                    Icon {
283
 
                        id: resIcon
284
 
                        height: units.gu(2.5)
285
 
                        width: height
286
 
                        visible: model.icon !== ""
287
 
                        source: model.icon
288
 
                        SlotsLayout.position: SlotsLayout.Last
289
 
                    }
290
 
                }
291
 
            }
292
 
        }
293
 
    }
294
 
 
295
 
    Component {
296
 
 
297
 
        id: historyListViewComponent
298
 
 
299
 
        ListView {
300
 
            id: historyListView
301
 
 
302
 
            clip: true
303
 
            model: historyModel
304
 
 
305
 
            section.property: "title"
306
 
            section.criteria: ViewSection.FullString
307
 
            section.delegate: ListItemHeader {
308
 
                title: section
309
 
            }
310
 
 
311
 
            delegate: ListItem {
312
 
                height: historyDelegateLayout.height + divider.height
313
 
                leadingActions:  ListItemActions {
314
 
                    actions: [
315
 
                        Action {
316
 
                            iconName: "delete"
317
 
                            onTriggered: {
318
 
                                switch (model.title) {
319
 
                                case i18n.tr("Search history"):
320
 
                                    UnavDB.removeHistorySearch(model.name);
321
 
                                    break;
322
 
                                case i18n.tr("Nearby history"):
323
 
                                    UnavDB.removeHistoryNearby(model.en_name);
324
 
                                    break;
325
 
                                case i18n.tr("Favorite history"):
326
 
                                    UnavDB.removeHistoryFavorite(model.name);
327
 
                                }
328
 
                                historyModel.initialize();
329
 
                            }
330
 
                        }
331
 
                    ]
332
 
                }
333
 
 
334
 
                trailingActions:  ListItemActions {
335
 
                    actions: [
336
 
                        Action {
337
 
                            iconName: "send"
338
 
                            visible: model.title !== i18n.tr("Nearby history")
339
 
                            onTriggered: {
340
 
                                mainPageStack.clear();
341
 
                                mainPageStack.center_onpos = 2;
342
 
                                mainPageStack.routeState = 'yes';
343
 
                                mainPageStack.executeJavaScript("calc2coord("+ model.lat + "," + model.lng + ");");
344
 
                            }
345
 
                        },
346
 
                        Action {
347
 
                            iconName: "share"
348
 
                            visible: model.title !== i18n.tr("Nearby history")
349
 
                            onTriggered: {
350
 
                                mainPageStack.push(Qt.resolvedUrl("Share.qml"), {"lat": model.lat, "lon": model.lng});
351
 
                            }
352
 
                        }
353
 
                    ]
354
 
                }
355
 
 
356
 
                ListItemLayout {
357
 
                    id: historyDelegateLayout
358
 
 
359
 
                    title.text: model.name
360
 
                    title.wrapMode: Text.WordWrap
361
 
                    title.maximumLineCount: 2
362
 
                    subtitle.text: QmlJs.formatDistance(QmlJs.calcPoiDistance(mainPageStack.currentLat, mainPageStack.currentLng, model.lat, model.lng, 10), navApp.settings.unit)
363
 
                    subtitle.visible: model.title !== i18n.tr("Nearby history") && mainPageStack.currentLat !== "null" && mainPageStack.currentLng !== "null"
364
 
 
365
 
                    Loader {
366
 
                        id: resultTypeIconLoader
367
 
                        SlotsLayout.position: SlotsLayout.First
368
 
                        SlotsLayout.overrideVerticalPositioning: true
369
 
                        anchors.verticalCenter: parent.verticalCenter
370
 
                        sourceComponent: model.title !== i18n.tr("Nearby history") ? resultTypeIconName : resultTypeIconSource
371
 
                    }
372
 
 
373
 
                    Component {
374
 
                        id: resultTypeIconName
375
 
                        Icon {
376
 
                            width: height
377
 
                            height: units.gu(2.5)
378
 
                            color: UbuntuColors.jet
379
 
                            name: {
380
 
                                if (model.title === i18n.tr("Search history"))
381
 
                                    return "history"
382
 
                                else if (model.title === i18n.tr("Favorite history"))
383
 
                                    return "starred"
384
 
                            }
385
 
                        }
386
 
                    }
387
 
 
388
 
                    Component {
389
 
                        id: resultTypeIconSource
390
 
                        Icon {
391
 
                            width: height
392
 
                            height: units.gu(2.5)
393
 
                            source: Qt.resolvedUrl("../nav/img/poi/" + model.en_name + ".svg")
394
 
                        }
395
 
                    }
396
 
 
397
 
                    Icon {
398
 
                        id: progressionIcon
399
 
                        height: units.gu(2.5)
400
 
                        name: "next"
401
 
                        visible: model.title === i18n.tr("Nearby history")
402
 
                        SlotsLayout.position: SlotsLayout.Last
403
 
                    }
404
 
                }
405
 
 
406
 
                onClicked: {
407
 
                    if (model.title === i18n.tr("Nearby history")) {
408
 
                        mainPageStack.push(Qt.resolvedUrl("PoiListPage.qml"),
409
 
                                           {
410
 
                                               lat: mainPageStack.currentLat,
411
 
                                               lng: mainPageStack.currentLng,
412
 
                                               poiType: model.name,
413
 
                                               clause: model.clause,
414
 
                                               geoDistFactor: 5
415
 
                                           })
416
 
                    } else {
417
 
                        mainPageStack.clear();
418
 
                        mainPageStack.executeJavaScript("ui.markers_POI_set([{ title: \"" +
419
 
                                                        model.name + "\", lat: " +
420
 
                                                        model.lat + ", lng: " +
421
 
                                                        model.lng + "}]);");
422
 
                    }
 
407
                    mainPageStack.executeJavaScript("ui.markers_POI_set([{ title: \"" +
 
408
                                                    model.name + "\", lat: " +
 
409
                                                    model.lat + ", lng: " +
 
410
                                                    model.lng + "}]);");
423
411
                }
424
412
            }
425
413
        }