on xenial help sign in
expose the lat,lon coords from the model
c2977cbLukáš Tinkl
plugins/Wizard/timezonemodel.cpp+12
@@ -35,6 +35,8 @@ TimeZoneLocationModel::TimeZoneLocationModel(QObject *parent):
35 m_roleNames[CityRole] = "city";
35 m_roleNames[CityRole] = "city";
36 m_roleNames[CountryRole] = "country";
36 m_roleNames[CountryRole] = "country";
37 m_roleNames[OffsetRole] = "offset";
37 m_roleNames[OffsetRole] = "offset";
38+ m_roleNames[LatitudeRole] = "latitude";
39+ m_roleNames[LongitudeRole] = "longitude";
38
40
39 QObject::connect(m_workerThread,
41 QObject::connect(m_workerThread,
40 &TimeZonePopulateWorker::resultReady,
42 &TimeZonePopulateWorker::resultReady,
@@ -103,6 +105,10 @@ QVariant TimeZoneLocationModel::data(const QModelIndex &index, int role) const
103 QTimeZone tmp(tz.timezone.toLatin1());
105 QTimeZone tmp(tz.timezone.toLatin1());
104 return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600;
106 return static_cast<double>(tmp.standardTimeOffset(QDateTime::currentDateTime())) / 3600;
105 }
107 }
108+ case LatitudeRole:
109+ return tz.latitude;
110+ case LongitudeRole:
111+ return tz.longitude;
106 default:
112 default:
107 qWarning() << Q_FUNC_INFO << "Unknown role";
113 qWarning() << Q_FUNC_INFO << "Unknown role";
108 return QVariant();
114 return QVariant();
@@ -129,11 +135,15 @@ void TimeZonePopulateWorker::buildCityMap()
129 for (guint i = 0; i < tz_locations->len; ++i) {
135 for (guint i = 0; i < tz_locations->len; ++i) {
130 auto tmp = static_cast<CcTimezoneLocation *>(g_ptr_array_index(tz_locations, i));
136 auto tmp = static_cast<CcTimezoneLocation *>(g_ptr_array_index(tz_locations, i));
131 gchar *en_name, *country, *zone, *state, *full_country;
137 gchar *en_name, *country, *zone, *state, *full_country;
138+ gdouble latitude;
139+ gdouble longitude;
132 g_object_get (tmp, "en_name", &en_name,
140 g_object_get (tmp, "en_name", &en_name,
133 "country", &country,
141 "country", &country,
134 "zone", &zone,
142 "zone", &zone,
135 "state", &state,
143 "state", &state,
136 "full_country", &full_country,
144 "full_country", &full_country,
145+ "latitude", &latitude,
146+ "longitude", &longitude,
137 nullptr);
147 nullptr);
138 // There are empty entries in the DB
148 // There are empty entries in the DB
139 if (g_strcmp0(en_name, "") != 0) {
149 if (g_strcmp0(en_name, "") != 0) {
@@ -142,6 +152,8 @@ void TimeZonePopulateWorker::buildCityMap()
142 tmpTz.timezone = zone;
152 tmpTz.timezone = zone;
143 tmpTz.state = state;
153 tmpTz.state = state;
144 tmpTz.full_country = full_country;
154 tmpTz.full_country = full_country;
155+ tmpTz.latitude = latitude;
156+ tmpTz.longitude = longitude;
145
157
146 Q_EMIT (resultReady(tmpTz));
158 Q_EMIT (resultReady(tmpTz));
147 }
159 }
plugins/Wizard/timezonemodel.h+5−2
@@ -37,7 +37,9 @@ public:
37 CityRole,
37 CityRole,
38 CountryRole,
38 CountryRole,
39 SimpleRole,
39 SimpleRole,
40− OffsetRole
40+ OffsetRole,
41+ LatitudeRole,
42+ LongitudeRole
41 };
43 };
42
44
43 struct TzLocation {
45 struct TzLocation {
@@ -46,7 +48,8 @@ public:
46 QString timezone;
48 QString timezone;
47 QString state;
49 QString state;
48 QString full_country;
50 QString full_country;
49− double offset;
51+ double latitude;
52+ double longitude;
50 };
53 };
51
54
52 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
55 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
qml/Wizard/Pages/50-timezone.qml+102−6
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import QtGraphicalEffects 1.0
18import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
19import Wizard 0.1
20import Wizard 0.1
20import Ubuntu.SystemSettings.TimeDate 1.0
21import Ubuntu.SystemSettings.TimeDate 1.0
@@ -33,6 +34,36 @@ LocalComponents.Page {
33 // for testing
34 // for testing
34 readonly property alias tdModule: timeDatePanel
35 readonly property alias tdModule: timeDatePanel
35
36
37+ function highlightTimezone(offset) {
38+ highlightImage.source = "file:/usr/share/libtimezonemap/ui/timezone_" + offset + ".png";
39+ }
40+
41+ // geo coords conversion functions (adapted from libtimezonemap)
42+ function radians (degrees) {
43+ return degrees * Math.PI / 180;
44+ }
45+
46+ function longitudeToX(longitude, map_width) {
47+ var xdeg_offset = -6;
48+ var x = (map_width * (180.0 + longitude) / 360.0) + (map_width * xdeg_offset / 180.0);
49+ return x;
50+ }
51+
52+ function latitudeToY(latitude, map_height) {
53+ var bottom_lat = -59;
54+ var top_lat = 81;
55+
56+ var top_per = top_lat / 180.0;
57+ var y = 1.25 * Math.log(Math.tan(0.25*Math.PI + 0.4 * radians(latitude)));
58+ var full_range = 4.6068250867599998;
59+ var top_offset = full_range * top_per;
60+ var map_range = Math.abs(1.25 * Math.log(Math.tan(0.25*Math.PI + 0.4 * radians(bottom_lat))) - top_offset);
61+ y = Math.abs(y - top_offset);
62+ y = y / map_range;
63+ y = y * map_height;
64+ return y;
65+ }
66+
36 UbuntuTimeDatePanel {
67 UbuntuTimeDatePanel {
37 id: timeDatePanel
68 id: timeDatePanel
38 }
69 }
@@ -110,8 +141,13 @@ LocalComponents.Page {
110 }
141 }
111
142
112 onClicked: {
143 onClicked: {
144+ highlightTimezone(offset);
113 ListView.view.currentIndex = index;
145 ListView.view.currentIndex = index;
114 selectedTimeZone = timeZone;
146 selectedTimeZone = timeZone;
147+ print("Clicked at city with coords:", longitude, latitude);
148+ print("Highlight at (x,y):", longitudeToX(longitude, map.width), latitudeToY(latitude, map.height));
149+ pinImage.x = longitudeToX(longitude, map.width) - 8;
150+ pinImage.y = latitudeToY(latitude, map.height) - 16;
115 }
151 }
116 }
152 }
117 }
153 }
@@ -120,16 +156,16 @@ LocalComponents.Page {
120 id: column
156 id: column
121 anchors {
157 anchors {
122 fill: content
158 fill: content
123− topMargin: customMargin
159+ topMargin: units.gu(4)
124− leftMargin: desktopLook ? parent.leftMargin : 0
160+ leftMargin: desktopLook ? staticMargin : 0
125− rightMargin: desktopLook ? parent.rightMargin : 0
161+ rightMargin: desktopLook ? staticMargin : 0
126 }
162 }
127
163
128 LocalComponents.WizardTextField {
164 LocalComponents.WizardTextField {
129 id: searchField
165 id: searchField
130 objectName: "tzFilter"
166 objectName: "tzFilter"
131 anchors.left: parent.left
167 anchors.left: parent.left
132− anchors.right: parent.right
168+ anchors.right: !desktopLook ? parent.right : undefined
133 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
169 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
134 anchors.rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
170 anchors.rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
135 placeholderText: i18n.tr("Enter your city")
171 placeholderText: i18n.tr("Enter your city")
@@ -138,13 +174,14 @@ LocalComponents.Page {
138 // reset when switching between filter modes (text/country)
174 // reset when switching between filter modes (text/country)
139 selectedTimeZone = ""
175 selectedTimeZone = ""
140 tzList.currentIndex = -1
176 tzList.currentIndex = -1
177+ highlightImage.source = ""
141 }
178 }
142 }
179 }
143
180
144 Rectangle {
181 Rectangle {
145 id: divider
182 id: divider
146 anchors.left: parent.left
183 anchors.left: parent.left
147− anchors.right: parent.right
184+ anchors.right: !desktopLook ? parent.right : undefined
148 anchors.top: searchField.bottom
185 anchors.top: searchField.bottom
149 anchors.topMargin: units.gu(3)
186 anchors.topMargin: units.gu(3)
150 height: units.dp(1)
187 height: units.dp(1)
@@ -161,14 +198,73 @@ LocalComponents.Page {
161
198
162 anchors {
199 anchors {
163 left: parent.left
200 left: parent.left
164− right: parent.right
201+ right: !desktopLook ? parent.right : undefined
165 top: divider.bottom
202 top: divider.bottom
166 }
203 }
167
204
205+ width: desktopLook ? searchField.width : undefined
168 height: column.height - searchField.height - column.anchors.topMargin - divider.height
206 height: column.height - searchField.height - column.anchors.topMargin - divider.height
169 model: tzFilterModel
207 model: tzFilterModel
170 delegate: tzComponent
208 delegate: tzComponent
171 }
209 }
210+
211+ Item {
212+ id: mapContainer
213+ visible: desktopLook
214+ anchors {
215+ left: tzList.right
216+ right: parent.right
217+ top: parent.top
218+ bottom: parent.bottom
219+ }
220+
221+ Item {
222+ id: map
223+ width: units.dp(800)
224+ height: units.dp(410)
225+ anchors {
226+ centerIn: parent
227+ }
228+
229+ Image {
230+ id: backgroundImage
231+ source: "file:/usr/share/libtimezonemap/ui/bg.png"
232+ sourceSize: Qt.size(map.width, map.height)
233+ fillMode: Image.PreserveAspectFit
234+ smooth: true
235+ visible: false
236+ }
237+
238+ Image {
239+ id: highlightImage
240+ sourceSize: Qt.size(map.width, map.height)
241+ fillMode: Image.PreserveAspectFit
242+ smooth: true
243+ visible: false
244+ }
245+
246+ Blend {
247+ anchors.fill: map
248+ cached: true
249+ source: backgroundImage
250+ foregroundSource: highlightImage
251+ }
252+
253+ MouseArea {
254+ anchors.fill: parent
255+ onClicked: {
256+ print("Clicked map at:", mouseX, mouseY)
257+ }
258+ }
259+
260+ Image {
261+ id: pinImage
262+ source: "file:/usr/share/libtimezonemap/ui/pin.png"
263+ visible: selectedTimeZone != ""
264+ z: map.z + 1
265+ }
266+ }
267+ }
172 }
268 }
173
269
174 Component {
270 Component {