~cibersheep/unav/systemcolors

« back to all changes in this revision

Viewing changes to qml/PoiPage.qml

  • Committer: costales
  • Date: 2016-03-26 18:53:17 UTC
  • Revision ID: costales.marcos@gmail.com-20160326185317-4iau3yhe8986h5pg
Init team

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GPS Navigation http://launchpad.net/unav
 
3
 * Copyright (C) 2015-2016 Marcos Alvarez Costales https://launchpad.net/~costales
 
4
 * Copyright (C) 2015-2016 JkB https://launchpad.net/~joergberroth
 
5
 *
 
6
 * GPS Navigation is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * GPS Navigation is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import QtQuick.Layouts 1.1
 
19
import Ubuntu.Components 1.3
 
20
import Ubuntu.Components.ListItems 1.3 as ListItems
 
21
import QtQuick.XmlListModel 2.0
 
22
import "js/PoiCategories.js" as Categories
 
23
import QtQuick.LocalStorage 2.0
 
24
import "js/db.js" as UnavDB
 
25
 
 
26
Page {
 
27
    id: poiPage
 
28
 
 
29
    title: i18n.tr("Nearby")
 
30
    anchors.fill: parent
 
31
    
 
32
    property var fromPage
 
33
    property var lat
 
34
    property var lng
 
35
    property string unit: navApp.settings.unit === 0 ? "km" : "mi"
 
36
    property var factorList: ["1", "5", "15", "30", "50"]
 
37
    state: "default"
 
38
    states: [
 
39
        PageHeadState {
 
40
            name: "default"
 
41
            head: poiPage.head
 
42
 
 
43
            backAction: Action {
 
44
                iconName: "back"
 
45
                text: i18n.tr("Back")
 
46
                onTriggered: {
 
47
                    mainPageStack.pop(poiPage);
 
48
                    if (poiPage.fromPage === "RoutePage.qml")
 
49
                        mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"));
 
50
                }
 
51
            }
 
52
 
 
53
            actions: [
 
54
                Action {
 
55
                    id: searchAction
 
56
                    iconName: "find"
 
57
                    text: i18n.tr("Search")
 
58
                    onTriggered: {
 
59
                        poiPage.state = "search"
 
60
                        poiSearchField.forceActiveFocus()
 
61
                    }
 
62
                }
 
63
            ]
 
64
        },
 
65
 
 
66
        PageHeadState {
 
67
            name: "search"
 
68
            head: poiPage.head
 
69
 
 
70
            backAction: Action {
 
71
                iconName: "back"
 
72
                text: i18n.tr("Back")
 
73
                onTriggered: {
 
74
                    mainPageStack.pop(poiPage)
 
75
                    if (poiPage.fromPage === "RoutePage.qml")
 
76
                        mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"));
 
77
                }
 
78
            }
 
79
 
 
80
            contents: TextField {
 
81
                id: poiSearchField
 
82
                anchors {
 
83
                    rightMargin: units.gu(2)
 
84
                }
 
85
                width:  parent ? parent.width - units.gu(2) : undefined
 
86
                inputMethodHints: Qt.ImhNoPredictiveText
 
87
                hasClearButton: true
 
88
                onTriggered: {
 
89
                    if ( text.length > 0) {
 
90
                        categoryList.searchString(text);
 
91
                    }
 
92
                }
 
93
                onTextChanged: {
 
94
                    if (text.length === 0) {
 
95
                        categoryListModel.clear();
 
96
                        categoryListModel.initialize();
 
97
                        poiSearchField.forceActiveFocus();
 
98
                    }
 
99
                }
 
100
            }
 
101
        }
 
102
    ]
 
103
 
 
104
    head {
 
105
        sections {
 
106
            model: [factorList[0]+unit, factorList[1]+unit, factorList[2]+unit, factorList[3]+unit, factorList[4]+unit]
 
107
            selectedIndex: 1
 
108
        }
 
109
    }
 
110
 
 
111
    ListModel {
 
112
        id: categoryListModel
 
113
        function initialize() {
 
114
            categoryListModel.clear();
 
115
            Categories.data.forEach( function(category) {
 
116
                categoryListModel.append(category);
 
117
            });
 
118
 
 
119
            var res = UnavDB.getNearByHistory();
 
120
            var len = res.rows.length;
 
121
            for ( var i = 0; i < len; ++i) {
 
122
                categoryListModel.insert(
 
123
                    i,
 
124
                    {
 
125
                        theme: i18n.tr("Most recent"),
 
126
                        label: i18n.tr(res.rows.item(i).type),
 
127
                        en_label: res.rows.item(i).type,
 
128
                        clause: res.rows.item(i).clause
 
129
                    }
 
130
                );
 
131
            }
 
132
        }
 
133
        Component.onCompleted: initialize()
 
134
    }
 
135
 
 
136
    Component {
 
137
        id: sectionHeading
 
138
 
 
139
        Rectangle {
 
140
            width: parent.width
 
141
            height: childrenRect.height
 
142
 
 
143
            ListItems.Header {
 
144
                id: listHeader
 
145
                text: section
 
146
            }
 
147
        }
 
148
    }
 
149
 
 
150
    UbuntuListView {
 
151
        id: categoryList
 
152
        model: categoryListModel
 
153
 
 
154
        anchors.fill: parent
 
155
        clip: true
 
156
 
 
157
        function searchString( string) {
 
158
            categoryListModel.initialize();
 
159
            for( var i = 0; i < categoryListModel.count; i++){
 
160
                if (model.get(i).label.toLowerCase().indexOf(string.toLowerCase()) === -1) {
 
161
                    model.remove(i); i--;
 
162
                }
 
163
            }
 
164
        }
 
165
 
 
166
        section.property: "theme"
 
167
        section.criteria: ViewSection.FullString
 
168
        section.labelPositioning: ViewSection.CurrentLabelAtStart + ViewSection.InlineLabels
 
169
        section.delegate: sectionHeading
 
170
        delegate: ListItems.Standard {
 
171
            id: poiItem
 
172
            showDivider: false
 
173
            text: label
 
174
            progression: true
 
175
            onClicked: {
 
176
                //mainPageStack.pop(poiPage);
 
177
                mainPageStack.push(Qt.resolvedUrl("PoiListPage.qml"), {
 
178
                    fromPage: poiPage,
 
179
                    lat: poiPage.lat,
 
180
                    lng: poiPage.lng,
 
181
                    poiType: model.label,
 
182
                    clause: model.clause,
 
183
                    geoDistFactor: Number(factorList[poiPage.head.sections.selectedIndex])
 
184
                });
 
185
                if (navApp.settings.saveHistory) {
 
186
                    UnavDB.saveToNearByHistory(model.en_label, model.clause);
 
187
                }
 
188
            }
 
189
        }
 
190
    }
 
191
}
 
192
 
 
193