summaryrefslogtreecommitdiff
path: root/examples/declarative/qmlplaces/qmlplaces.qml
blob: 181436cd4bdfddf0822fb2a6282d105cac86cb4d (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import QtQuick 2.0
import Qt.location 5.0

Rectangle {
    id: fullView
    width: 800
    height: 360

    Text {
        id: queryText
        text: "Query:"
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.top: parent.top
        anchors.topMargin: 10
        font.pixelSize: 18
    }

    Rectangle {
        id: searchTermRect
        color: "#ffffff"
        anchors.right: searchButton.left
        anchors.rightMargin: 5
        anchors.left: queryText.right
        anchors.leftMargin: 5
        anchors.top: parent.top
        anchors.topMargin: 10
        height: search_term.height
        border.color: "#23b98a"

        TextInput {
            id: search_term
            text: "p"
            anchors.fill: parent
            clip: false
            opacity: 1
            font.pixelSize: 18

            onAccepted: searchTerm(text)
            onTextChanged: {
                resultSuggestion.executeQuery();
                suggestions.visible = true;
            }
        }
    }

    Button {
        id: searchButton

        text: "Search"

        anchors.bottom: searchTermRect.bottom
        anchors.right: parent.right
        anchors.rightMargin: 10
        anchors.top: searchTermRect.top

        onClicked: searchTerm(search_term.text)
    }

    ListView {
        id: placesList
        anchors.rightMargin: 10
        anchors.leftMargin: 10
        anchors.bottomMargin: 10
        anchors.top: queryText.bottom
        anchors.right: categoriesList.left
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.topMargin: 10
        clip: true
        visible: !reviewList.visible

        snapMode: ListView.SnapToItem
        model: resultModel
        delegate: SearchResultDelegate { result: searchResult }
    }

    ListView {
        id: reviewList
        anchors.fill: placesList
        clip: true
        snapMode: ListView.SnapToItem

        visible: model != undefined
        delegate: ReviewDelegate {
            review: model.review
        }
    }

    ListView {
        id: descriptionList
        anchors.fill: placesList
        clip: true
        snapMode: ListView.SnapToItem

        visible: model != undefined
        delegate: DescriptionDelegate {
            description: model.modelData
        }
    }

    Text {
        id: categoriesText
        text: "Categories tree:"
        anchors.top: queryText.bottom
        anchors.topMargin: 10
        anchors.left: categoriesList.left
        font.pixelSize: 18
    }

    CategoryView {
        id: categoriesList

        width: 300
        anchors.topMargin: 10
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.top: categoriesText.bottom
        anchors.bottomMargin: 10
        anchors.rightMargin: 10
        model: categoriesModel

        onCategorySelected: searchCategory(category);
    }

    Rectangle {
        id: suggestions
        anchors.left: searchTermRect.left
        anchors.right: searchTermRect.right
        anchors.top: searchTermRect.bottom
        height: Math.min(4, resultSuggestion.predictions.length) * 19
        visible: false
        color: "#f0f0f0"
        clip: true
        ListView {
            id: suggestionsList
            anchors.fill: parent
            model: resultSuggestion
            delegate: Component {
                Text {
                    width: parent.width
                    text: textPrediction
                    font.pixelSize: 16

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            search_term.text = textPrediction;
                            searchTerm(search_term.text);
                        }
                    }
                }
            }
        }
    }

    Plugin {
        id: geoServices
        name: "nokia"
    }

    SearchResultModel {
        id: resultModel
        plugin: geoServices

        searchArea: BoundingCircle {
            id: proximity
            center: Coordinate {
                id: searchCoordinate
                // Paris
                longitude: 2.296
                latitude: 48.87
            }
            radius:5000
        }
        didYouMean: 5
        //onQueryFinished: console.log("datareceived " + error)
    }

    function searchTerm(term)
    {
        resultModel.clearCategories();
        resultModel.searchTerm = term;
        resultModel.executeQuery();
        suggestions.visible = false;
    }

    function searchCategory(category)
    {
        resultModel.clearSearchTerm();
        resultModel.searchCategory = category;
        resultModel.executeQuery();
        suggestions.visible = false;
    }

    TextPredictionModel {
        id: resultSuggestion
        plugin: geoServices

        searchArea: proximity
        offset: 0
        limit: 15
        searchTerm: search_term.text
    }

    RecommendationModel {
        id: recommendationModel
        plugin: geoServices

        searchArea: proximity
        offset: 0
        limit: 15
        //onQueryFinished: console.log("datareceived " + error)
    }

    SupportedCategoriesModel {
        id: categoriesModel
        plugin: geoServices
        hierarchical: true
    }

    MediaGrid {
        id: mediaGrid

        anchors.fill: parent
        visible: model != undefined
    }
}