Skip to content

Commit

Permalink
Make LocationFormatter translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Feb 27, 2022
1 parent d341aab commit 6c6df18
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 115 deletions.
2 changes: 1 addition & 1 deletion harbour-gpsinfo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DISTFILES += qml/pages/CoverPage.qml \
qml/components/InfoField.qml \
qml/pages/SatelliteBarchartPage.qml \
qml/pages/SettingsPage.qml \
qml/LocationFormatter.js \
qml/LocationFormatter.qml \
qml/components/Providers.qml \
qml/components/DoubleSwitch.qml \
qml/pages/AboutPage.qml \
Expand Down
75 changes: 0 additions & 75 deletions qml/LocationFormatter.js

This file was deleted.

79 changes: 79 additions & 0 deletions qml/components/LocationFormatter.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import QtQuick 2.0

Item {
property string mag: qsTr("M", "Magnetic North")

property string north: qsTr("N", "North")
property string south: qsTr("S", "South")
property string east: qsTr("E", "East")
property string west: qsTr("W", "West")

function roundToDecimal(inputNum, numPoints) {
var multiplier = Math.pow(10, numPoints);
return Math.round(inputNum * multiplier) / multiplier;
}

function decimalToDMS(location, hemisphere, numSecondPoints) {
if(location < 0) {
location *= -1
}
var degrees = Math.floor(location);
var minutesFromRemainder = (location - degrees) * 60;
var minutes = Math.floor(minutesFromRemainder);
var secondsFromRemainder = (minutesFromRemainder - minutes) * 60;
var seconds = roundToDecimal(secondsFromRemainder, numSecondPoints);
return degrees + '° ' + minutes + "' " + seconds + '" ' + hemisphere;
}

function decimalLatToDMS(location, numSecondPoints) {
var hemisphere = (location < 0) ? south: north;
return decimalToDMS(location, hemisphere, numSecondPoints);
}

function decimalLongToDMS(location, numSecondPoints) {
var hemisphere = (location < 0) ? west : east;
return decimalToDMS(location, hemisphere, numSecondPoints);
}

function formatDirection(direction) {
var dirStr;
if (direction < 11.25) {
dirStr = north
} else if (direction < 33.75) {
dirStr = qsTr("NNE", "North North East")
} else if (direction < 56.25) {
dirStr = qsTr("NE", "North East")
} else if (direction < 78.75) {
dirStr = qsTr("ENE", "East North East")
} else if (direction < 101.25) {
dirStr = east
} else if (direction < 123.75) {
dirStr = qsTr("ESE", "East South East")
} else if (direction < 146.25) {
dirStr = qsTr("SE", "South East")
} else if (direction < 168.75) {
dirStr = qsTr("SSE", "South South East")
} else if (direction < 191.25) {
dirStr = south
} else if (direction < 213.75) {
dirStr = qsTr("SSW", "South South West")
} else if (direction < 236.25) {
dirStr = qsTr("SW", "South West")
} else if (direction < 258.75) {
dirStr = qsTr("WSW", "West South West")
} else if (direction < 281.25) {
dirStr = west
} else if (direction < 303.75) {
dirStr = qsTr("WNW", "West North West")
} else if (direction < 326.25) {
dirStr = qsTr("NW", "Norh West")
} else if (direction < 348.75) {
dirStr = qsTr("NNW", "North North West")
} else if (direction < 360) {
dirStr = north
} else {
dirStr = "?"
}
return dirStr === "?" ? "-" : dirStr + " (" + roundToDecimal(direction, 0) + "°)"
}
}
4 changes: 2 additions & 2 deletions qml/components/MainMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Item {
text: qsTr("Copy location")
onClicked: {
if (settings.coordinateFormat === "DEG") {
Clipboard.text = LocationFormater.decimalLatToDMS(positionSource.position.coordinate.latitude, 2)
Clipboard.text = locationFormatter.decimalLatToDMS(positionSource.position.coordinate.latitude, 2)
+ ", "
+ LocationFormater.decimalLongToDMS(positionSource.position.coordinate.longitude, 2);
+ locationFormatter.decimalLongToDMS(positionSource.position.coordinate.longitude, 2);
} else {
Clipboard.text = positionSource.position.coordinate.latitude
+ ", "
Expand Down
6 changes: 3 additions & 3 deletions qml/components/Providers.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import QtPositioning 5.2
import QtSensors 5.0
import harbour.gpsinfo 1.0
import Sailfish.Silica 1.0
import "../LocationFormatter.js" as LocationFormater
import "../components"


Item {
Expand Down Expand Up @@ -97,9 +97,9 @@ Item {
function formatElapsedTime(t) { //print fn for elapsed times
if (t<=90) return Math.round(t)+ "sec"
t=t/60;
if (t<=90) return LocationFormater.roundToDecimal(T,1)+ "min"
if (t<=90) return locationFormatter.roundToDecimal(T,1)+ "min"
t=t/60;
return LocationFormater.roundToDecimal(t,1)+ "hr"
return locationFormatter.roundToDecimal(t,1)+ "hr"
}
Component.onCompleted: {

Expand Down
4 changes: 4 additions & 0 deletions qml/harbour-gpsinfo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import "components"

ApplicationWindow
{
LocationFormatter {
id: locationFormatter
}

Providers {
id: providers
}
Expand Down
30 changes: 14 additions & 16 deletions qml/pages/CoverPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import QtSensors 5.0
import harbour.gpsinfo 1.0
import "../components"

import "../LocationFormatter.js" as LocationFormater

CoverBackground {
property PositionSource positionSource
property Compass compass
Expand Down Expand Up @@ -37,7 +35,7 @@ CoverBackground {
value: {
if (positionSource.position.latitudeValid) {
if (settings.coordinateFormat === "DEG") {
return LocationFormater.decimalLatToDMS(positionSource.position.coordinate.latitude, 0)
return locationFormatter.decimalLatToDMS(positionSource.position.coordinate.latitude, 0)
} else {
return positionSource.position.coordinate.latitude
}
Expand All @@ -52,7 +50,7 @@ CoverBackground {
value: {
if (positionSource.position.longitudeValid) {
if (settings.coordinateFormat === "DEG") {
return LocationFormater.decimalLongToDMS(positionSource.position.coordinate.longitude, 0)
return locationFormatter.decimalLongToDMS(positionSource.position.coordinate.longitude, 0)
} else {
return positionSource.position.coordinate.longitude
}
Expand All @@ -67,9 +65,9 @@ CoverBackground {
value: {
if (positionSource.position.altitudeValid) {
if (settings.units == "MET") {
return LocationFormater.roundToDecimal(positionSource.position.coordinate.altitude, 2) + " m"
return locationFormatter.roundToDecimal(positionSource.position.coordinate.altitude, 2) + " m"
} else {
return LocationFormater.roundToDecimal(positionSource.position.coordinate.altitude * 3.2808399, 2) + " ft"
return locationFormatter.roundToDecimal(positionSource.position.coordinate.altitude * 3.2808399, 2) + " ft"
}
}
return "-"
Expand All @@ -83,15 +81,15 @@ CoverBackground {
if (positionSource.position.speedValid) {
if (settings.units == "MET") {
if (settings.speedUnit == "SEC") {
return LocationFormater.roundToDecimal(positionSource.position.speed, 2) + " " + qsTr("m/s")
return locationFormatter.roundToDecimal(positionSource.position.speed, 2) + " " + qsTr("m/s")
} else {
return LocationFormater.roundToDecimal(positionSource.position.speed * 60 * 60 / 1000, 2) + " " + qsTr("km/h")
return locationFormatter.roundToDecimal(positionSource.position.speed * 60 * 60 / 1000, 2) + " " + qsTr("km/h")
}
} else {
if (settings.speedUnit == "SEC") {
return LocationFormater.roundToDecimal(positionSource.position.speed * 3.2808399, 2) + " " + qsTr("ft/s")
return locationFormatter.roundToDecimal(positionSource.position.speed * 3.2808399, 2) + " " + qsTr("ft/s")
} else {
return LocationFormater.roundToDecimal(positionSource.position.speed * 2.23693629, 2) + " " + qsTr("mph")
return locationFormatter.roundToDecimal(positionSource.position.speed * 2.23693629, 2) + " " + qsTr("mph")
}
}
}
Expand All @@ -102,7 +100,7 @@ CoverBackground {
label: qsTr("Mov.")
visible: settings.showMovementDirectionCover
fontpixelSize: Theme.fontSizeMedium
value: isNaN(gpsDataSource.movementDirection) ? "-" : LocationFormater.formatDirection(gpsDataSource.movementDirection)
value: isNaN(gpsDataSource.movementDirection) ? "-" : locationFormatter.formatDirection(gpsDataSource.movementDirection)
}
InfoField {
label: ""
Expand All @@ -117,9 +115,9 @@ CoverBackground {
value: {
if (positionSource.position.verticalAccuracyValid) {
if (settings.units == "MET") {
return LocationFormater.roundToDecimal(positionSource.position.verticalAccuracy, 2) + " m"
return locationFormatter.roundToDecimal(positionSource.position.verticalAccuracy, 2) + " m"
} else {
return LocationFormater.roundToDecimal(positionSource.position.verticalAccuracy * 3.2808399, 2) + " ft"
return locationFormatter.roundToDecimal(positionSource.position.verticalAccuracy * 3.2808399, 2) + " ft"
}
}
return "-"
Expand All @@ -132,9 +130,9 @@ CoverBackground {
value: {
if (positionSource.position.horizontalAccuracyValid) {
if (settings.units == "MET") {
return LocationFormater.roundToDecimal(positionSource.position.horizontalAccuracy, 2) + " m"
return locationFormatter.roundToDecimal(positionSource.position.horizontalAccuracy, 2) + " m"
} else {
return LocationFormater.roundToDecimal(positionSource.position.horizontalAccuracy * 3.2808399, 2) + " ft"
return locationFormatter.roundToDecimal(positionSource.position.horizontalAccuracy * 3.2808399, 2) + " ft"
}
}
return "-"
Expand All @@ -150,7 +148,7 @@ CoverBackground {
label: qsTr("Com.")
visible: settings.showCompassDirectionCover
fontpixelSize: Theme.fontSizeMedium
value: LocationFormater.formatDirection(compass.reading === null ? 0 : compass.reading.azimuth)
value: locationFormatter.formatDirection(compass.reading === null ? 0 : compass.reading.azimuth)
}
InfoField {
label: qsTr("Cal.")
Expand Down
Loading

0 comments on commit 6c6df18

Please sign in to comment.