-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
296 lines (245 loc) · 8.78 KB
/
main.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
import QtQuick 1.0
import 'reittiopas.js' as Reittiopas
import 'reittiopas-hsl.js' as HSL
import 'helper.js' as Helper
Rectangle {
// initilize helper
Component.onCompleted: Helper.init();
id: main
width: 360
height: 480
Text {
id: title
anchors.top: parent.top
anchors.topMargin: 10
anchors.left: parent.left
anchors.leftMargin: 10
font.family: "Arial Hebrew"
color: 'blue'
font.pointSize: 25
text: 'Perille'
}
Text {
anchors.top: parent.top
anchors.topMargin: 10
anchors.right: parent.right
anchors.rightMargin: 10
text: 'Exit'
MouseArea {
anchors.fill: parent
onClicked: Qt.quit()
}
}
// Here starts real app logic
// helper JS
function showAddressSuggestion(field, response) {
routeOptionsModel.clear();
for( var location in response ) {
location = response[location]
routeOptionsModel.append( {
name : location.name,
city : location.city,
coord : location.coords,
clickLocation : field
} );
}
}
function showRoute( r ) {
// for initial release, only handle one route (the best one
for( var index in r ) {
var route = r[index][0];
var points = [];
for( var leg in route.legs ) {
leg = route.legs[leg];
// console.log( HSL.decode( leg ).type )
leg = HSL.decode( leg )
points.push( leg );
Helper.DATA_MODELS[index].append( {
type : leg.type,
code : leg.code,
first : leg.first.name,
last: leg.last.name,
time : leg.first.time,
latitude : leg.first.location.x,
longitude : leg.first.location.y
} )
}
// need to loop this again... :(
// at the initial time we can not confirtm that the values in models have been correct onces
// the joy and love of async
// xxx fixme
Helper.DATA_CONTAINERS[index].model = Helper.DATA_MODELS[index];
}
}
Item {
id: search
anchors.top: title.bottom
x : title.anchors.leftMargin
width: main.width
height: main.width
Behavior on x {
NumberAnimation { duration: 2500 }
}
LocationEntry {
id: from
width: parent.parent.width - 2 * title.anchors.leftMargin
text: 'From'
function input(text) {
if( text.length > 3 )
Reittiopas.address_to_location( text, function(response){ showAddressSuggestion(from, response) } )
}
}
LocationEntry {
id: to
width: from.width
anchors.top: from.bottom
anchors.topMargin: 10
text: 'To'
function input(text) {
if( text.length > 3 )
Reittiopas.address_to_location( text, function(response){ showAddressSuggestion(to, response) } )
}
}
Rectangle {
id: searchFrame
anchors.top: to.bottom
anchors.topMargin: 10
radius: 10
color: 'lightblue'
border.color: 'lightblue'
border.width: 2
height: 75
width: from.width
Text {
anchors.centerIn: parent
text: 'Search'
color: 'white'
}
MouseArea {
anchors.fill: parent
onClicked: {
Reittiopas.route( from.coord, to.coord ,
new Date() , // hardcoded
'departure',
showRoute )
// hide search, show result
// xxx fixme
routeOptionsModel.clear()
search.x = - main.width + title.anchors.leftMargin
}
}
}
ListModel {
id: routeOptionsModel
}
ListView {
id: routeOptions
anchors.top: searchFrame.bottom
anchors.topMargin: 10
width: from.width
orientation: ListView.Horizontal
height: 70
model: routeOptionsModel
delegate: Item {
height: 70
width: 100
Text {
width: parent.width
wrapMode: Text.WordWrap
text : name + ' (' + city + ')'
}
MouseArea {
anchors.fill: parent
onClicked: {
clickLocation.text = name;
clickLocation.coord = coord;
// routeOptionsModel.clear();
}
}
}
}
} // search end
Item {
id: response
anchors.top: title.bottom
anchors.topMargin: 10
anchors.left: search.right
width: main.width
Column {
spacing: 5
anchors.top: parent.top
anchors.topMargin: 10
Repeater {
model: 5
Item {
height: 70
width: main.width - 20
ListView {
id: list
Component.onCompleted: {
Helper.DATA_CONTAINERS.push(list);
}
width: from.width
orientation: ListView.Horizontal
height: parent.height
model: Helper.DATA_MODELS[index]
delegate: Item {
height: parent.height
width: 250
Text {
id: text
width: 140
wrapMode: Text.WordWrap
text : type + ' ' + code + ' @ ' + first + ' ' + Qt.formatTime( time, 'hh:mm' )
}
Image {
id: image
anchors.left: text.right
anchors.leftMargin: 5
anchors.top: text.top
source : 'http://perille.mante.li/streetimage/image.php?latitude=' + latitude + '&longitude=' + longitude
height: parent.height
width: 100
fillMode: Image.PreserveAspectFit
Behavior on scale {
NumberAnimation { duration: 250 }
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("Mui")
// fixme ? :
if( parent.scale == 1 ) {
parent.scale = 3;
} else {
parent.scale = 1;
}
}
}
}
}
}
// display indicator for more data
Text {
text: '>'
color: 'blue'
anchors.left: parent.right
anchors.horizontalCenter: parent.horizontalCenter
style: Text.Outline
styleColor: 'white'
visible: !list.atXEnd
}
Text {
text: '<'
color: 'blue'
anchors.right: parent.right
anchors.horizontalCenter: parent.horizontalCenter
style: Text.Outline
styleColor: 'white'
visible: !list.atXBeginning
}
}
}
}
} // response end
}