~cibersheep/unav/systemcolors

« back to all changes in this revision

Viewing changes to qml/Coordinate.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
 *
 
5
 * GPS Navigation is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * GPS Navigation is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 */
 
15
 
 
16
import QtQuick 2.4
 
17
import QtQuick.Layouts 1.1
 
18
import Ubuntu.Components 1.3
 
19
import Ubuntu.Components.Pickers 1.3
 
20
import Ubuntu.Components.Popups 1.3
 
21
 
 
22
Page {
 
23
    id: coordPage
 
24
 
 
25
    title: i18n.tr("Coordinates")
 
26
    anchors.fill: parent
 
27
 
 
28
    head {
 
29
        id: headPage
 
30
        backAction: Action {
 
31
            iconName: "back"
 
32
            text: i18n.tr("Back")
 
33
            onTriggered: {
 
34
                mainPageStack.pop(coordPage)
 
35
                mainPageStack.push(Qt.resolvedUrl("RoutePage.qml"))
 
36
            }
 
37
        }
 
38
        sections {
 
39
            model: [i18n.tr("Decimal"), i18n.tr("Sexagesimal")]
 
40
            selectedIndex: 0
 
41
        }
 
42
    }
 
43
 
 
44
 
 
45
    Column {
 
46
        id: colCoordDec
 
47
        visible: !coordPage.head.sections.selectedIndex
 
48
        anchors.horizontalCenter: parent.horizontalCenter
 
49
        anchors.verticalCenter: parent.verticalCenter
 
50
        width: units.gu(28)
 
51
        height: units.gu(10)
 
52
     
 
53
        spacing: units.gu(2)
 
54
     
 
55
        Row {
 
56
            spacing: units.gu(1)
 
57
            Label {
 
58
                anchors.verticalCenter: parent.verticalCenter
 
59
                text: i18n.tr("Lat:")
 
60
                width: units.gu(5)
 
61
            }
 
62
     
 
63
            TextField {
 
64
                id: lat1
 
65
                anchors.verticalCenter: parent.verticalCenter
 
66
                hasClearButton: true
 
67
                maximumLength: 15
 
68
                width: units.gu(22)
 
69
                placeholderText: '51.506177'
 
70
            }
 
71
        }
 
72
     
 
73
        Row {
 
74
            spacing: units.gu(1)
 
75
            Label {
 
76
                anchors.verticalCenter: parent.verticalCenter
 
77
                text: i18n.tr("Long:")
 
78
                width: units.gu(5)
 
79
            }
 
80
     
 
81
            TextField {
 
82
                id: lng1
 
83
                anchors.verticalCenter: parent.verticalCenter
 
84
                hasClearButton: true
 
85
                maximumLength: 15
 
86
                width: units.gu(22)
 
87
                placeholderText: '-0.100236'
 
88
            }
 
89
        }
 
90
     
 
91
        Button {
 
92
            id: showCoordDec
 
93
            text: i18n.tr("Show on Map")
 
94
            width: colCoordDec.width
 
95
            anchors.topMargin: units.gu(5)
 
96
            anchors.horizontalCenter: parent.horizontalCenter
 
97
            color: UbuntuColors.green
 
98
            onClicked: {
 
99
                try {
 
100
                    var aux_lat = lat1.text;
 
101
                    var aux_lng = lng1.text;
 
102
                    if (!isNaN(aux_lat) && aux_lat.toString().indexOf('.') != -1 && !isNaN(aux_lng) && aux_lng.toString().indexOf('.') != -1 && aux_lat >= -90 && aux_lat <= 90 && aux_lng >= -180 && aux_lng <= 180) { // It's a float
 
103
                        mainPageStack.clickedLat = parseFloat(aux_lat).toFixed(5);
 
104
                        mainPageStack.clickedLng = parseFloat(aux_lng).toFixed(5);
 
105
                        if (mainPageStack.center_onpos === 2)
 
106
                            mainPageStack.center_onpos = 1;
 
107
                        mainPageStack.pop(coordPage);
 
108
                        mainPageStack.executeJavaScript(
 
109
                            "ui.markers_POI_set([{title: '', lat: " + mainPageStack.clickedLat + ", lng: " + mainPageStack.clickedLng + "}]);" 
 
110
                        );
 
111
                        mainPageStack.favPopup = false;
 
112
                        goThereActionPopover.show();
 
113
                    }
 
114
                    else {
 
115
                        PopupUtils.open(coordDecNotValid)
 
116
                    }
 
117
                }
 
118
                catch(e){
 
119
                    PopupUtils.open(coordDecNotValid)
 
120
                }
 
121
            }
 
122
        }
 
123
 
 
124
        Component {
 
125
            id: coordDecNotValid
 
126
            Dialog {
 
127
                id: dialogue
 
128
                title: i18n.tr("Coordinates are not valid")
 
129
                text: i18n.tr("Enter valid decimal coordinates\n\nExpected format is:") + "\n51.506177\n-0.100236"
 
130
                Button {
 
131
                     text: i18n.tr("Close")
 
132
                     onClicked: PopupUtils.close(dialogue)
 
133
                }
 
134
            }
 
135
        }
 
136
    }
 
137
    
 
138
    
 
139
    Column {
 
140
        id: colCoordPolar
 
141
        visible: coordPage.head.sections.selectedIndex
 
142
        anchors.horizontalCenter: parent.horizontalCenter
 
143
        anchors.verticalCenter: parent.verticalCenter
 
144
        width: units.gu(35)
 
145
        height: units.gu(10)
 
146
    
 
147
        spacing: units.gu(2)
 
148
    
 
149
        Row {
 
150
            Label {
 
151
                anchors.verticalCenter: parent.verticalCenter
 
152
                text: i18n.tr("Lat:")
 
153
                width: units.gu(5)
 
154
            }
 
155
            
 
156
            TextField {
 
157
                id: lat2a
 
158
                anchors.verticalCenter: parent.verticalCenter
 
159
                hasClearButton: false
 
160
                width: units.gu(6)
 
161
                placeholderText: '51'
 
162
            }
 
163
            Label {
 
164
                anchors.verticalCenter: parent.verticalCenter
 
165
                text: "º"
 
166
                width: units.gu(1)
 
167
            }
 
168
 
 
169
            TextField {
 
170
                id: lat2b
 
171
                anchors.verticalCenter: parent.verticalCenter
 
172
                hasClearButton: false
 
173
                width: units.gu(8)
 
174
                placeholderText: '30'
 
175
            }
 
176
            Label {
 
177
                anchors.verticalCenter: parent.verticalCenter
 
178
                text: "'"
 
179
                width: units.gu(1)
 
180
            }
 
181
 
 
182
            TextField {
 
183
                id: lat2c
 
184
                anchors.verticalCenter: parent.verticalCenter
 
185
                hasClearButton: false
 
186
                width: units.gu(8)
 
187
                placeholderText: '22.23'
 
188
            }
 
189
            Label {
 
190
                anchors.verticalCenter: parent.verticalCenter
 
191
                text: "\""
 
192
                width: units.gu(1)
 
193
            }
 
194
 
 
195
            TextField {
 
196
                id: lat2d
 
197
                anchors.verticalCenter: parent.verticalCenter
 
198
                hasClearButton: false
 
199
                width: units.gu(5)
 
200
                maximumLength: 1
 
201
                placeholderText: 'N'
 
202
            }
 
203
            Label {
 
204
                anchors.verticalCenter: parent.verticalCenter
 
205
                width: units.gu(2)
 
206
            }
 
207
        }
 
208
     
 
209
        Row {
 
210
            Label {
 
211
                anchors.verticalCenter: parent.verticalCenter
 
212
                text: i18n.tr("Long:")
 
213
                width: units.gu(5)
 
214
            }
 
215
            
 
216
            TextField {
 
217
                id: lng2a
 
218
                anchors.verticalCenter: parent.verticalCenter
 
219
                hasClearButton: false
 
220
                width: units.gu(6)
 
221
                placeholderText: '0'
 
222
            }
 
223
            Label {
 
224
                anchors.verticalCenter: parent.verticalCenter
 
225
                text: "º"
 
226
                width: units.gu(1)
 
227
            }
 
228
 
 
229
            TextField {
 
230
                id: lng2b
 
231
                anchors.verticalCenter: parent.verticalCenter
 
232
                hasClearButton: false
 
233
                width: units.gu(8)
 
234
                placeholderText: '6'
 
235
            }
 
236
            Label {
 
237
                anchors.verticalCenter: parent.verticalCenter
 
238
                text: "'"
 
239
                width: units.gu(1)
 
240
            }
 
241
 
 
242
            TextField {
 
243
                id: lng2c
 
244
                anchors.verticalCenter: parent.verticalCenter
 
245
                hasClearButton: false
 
246
                width: units.gu(8)
 
247
                placeholderText: '0.84'
 
248
            }
 
249
            Label {
 
250
                anchors.verticalCenter: parent.verticalCenter
 
251
                text: "\""
 
252
                width: units.gu(1)
 
253
            }
 
254
 
 
255
            TextField {
 
256
                id: lng2d
 
257
                anchors.verticalCenter: parent.verticalCenter
 
258
                hasClearButton: false
 
259
                width: units.gu(5)
 
260
                maximumLength: 1
 
261
                placeholderText: 'W'
 
262
            }
 
263
            Label {
 
264
                anchors.verticalCenter: parent.verticalCenter
 
265
                width: units.gu(2)
 
266
            }
 
267
        }
 
268
 
 
269
        Button {
 
270
            id: showCoordPolar
 
271
            text: i18n.tr("Show on Map")
 
272
            width: colCoordPolar.width
 
273
            anchors.topMargin: units.gu(5)
 
274
            anchors.horizontalCenter: parent.horizontalCenter
 
275
            color: UbuntuColors.green
 
276
            onClicked: {
 
277
                try {
 
278
                    var aux_lat_day = parseInt(lat2a.text);
 
279
                    var aux_lat_min = parseFloat(lat2b.text);
 
280
                    var aux_lat_sec = lat2c.text === "" ? 0 : parseFloat(lat2c.text);
 
281
                    var aux_lat_dir = lat2d.text.toUpperCase();
 
282
                    var aux_lng_day = parseInt(lng2a.text);
 
283
                    var aux_lng_min = parseFloat(lng2b.text);
 
284
                    var aux_lng_sec = lng2c.text === "" ? 0 : parseFloat(lng2c.text);
 
285
                    var aux_lng_dir = lng2d.text.toUpperCase();
 
286
                    
 
287
                    if ((!isNaN(aux_lat_day) && !isNaN(aux_lat_min) && !isNaN(aux_lat_sec) && (aux_lat_dir === 'S' || aux_lat_dir === 'N')) &&
 
288
                        (!isNaN(aux_lng_day) && !isNaN(aux_lng_min) && !isNaN(aux_lng_sec) && (aux_lng_dir === 'W' || aux_lng_dir === 'E'))) {
 
289
                        var aux_lat = aux_lat_day + aux_lat_min/60 + aux_lat_sec/(60*60);
 
290
                        if (aux_lat_dir === "S" || aux_lat_dir === "W")
 
291
                            aux_lat = aux_lat * -1;
 
292
                        
 
293
                        var aux_lng = aux_lng_day + aux_lng_min/60 + aux_lng_sec/(60*60);
 
294
                        if (aux_lng_dir === "S" || aux_lng_dir === "W")
 
295
                            aux_lng = aux_lng * -1;
 
296
                        
 
297
                        if (aux_lat >= -90 && aux_lat <= 90 && aux_lng >= -180 && aux_lng <= 180) {
 
298
                            mainPageStack.clickedLat = parseFloat(aux_lat).toFixed(5);
 
299
                            mainPageStack.clickedLng = parseFloat(aux_lng).toFixed(5);
 
300
                            if (mainPageStack.center_onpos === 2)
 
301
                                mainPageStack.center_onpos = 1;
 
302
                            mainPageStack.pop(coordPage);
 
303
                            mainPageStack.executeJavaScript(
 
304
                                "ui.markers_POI_set([{title: '', lat: " + mainPageStack.clickedLat + ", lng: " + mainPageStack.clickedLng + "}]);" 
 
305
                            );
 
306
                            mainPageStack.favPopup = false;
 
307
                            goThereActionPopover.show();
 
308
                        }
 
309
                        else {
 
310
                            PopupUtils.open(coordPolarNotValid)
 
311
                        }
 
312
                    }
 
313
                    else {
 
314
                        PopupUtils.open(coordPolarNotValid)
 
315
                    }
 
316
                }
 
317
                catch(e){
 
318
                    PopupUtils.open(coordPolarNotValid)
 
319
                }
 
320
            }
 
321
        }
 
322
 
 
323
        Component {
 
324
            id: coordPolarNotValid
 
325
            Dialog {
 
326
                id: dialogue
 
327
                title: i18n.tr("Coordinates are not valid")
 
328
                text: i18n.tr("Enter valid sexagesimal coordinates\n\nExpected format is:") + "\n51° 30' 22.23'' N\n0° 6' 0.84'' W"
 
329
                Button {
 
330
                     text: i18n.tr("Close")
 
331
                     onClicked: PopupUtils.close(dialogue)
 
332
                }
 
333
            }
 
334
        }
 
335
    }
 
336
}
 
337