Fix weather panel clipping and units
This commit is contained in:
@@ -32,6 +32,37 @@ function formatTemp(value, useImperial) {
|
||||
return value + "°" + (useImperial ? "F" : "C")
|
||||
}
|
||||
|
||||
function normalizedUnit(value) {
|
||||
return String(value || "").replace(/^\s+|\s+$/g, "").toLowerCase()
|
||||
}
|
||||
|
||||
function localeUsesImperial(localeName) {
|
||||
var name = String(localeName || "").replace(".", "_")
|
||||
return /^en[_-]US($|[_.-])/.test(name) || /^en[_-]LR($|[_.-])/.test(name) || /^my($|[_.-])/.test(name)
|
||||
}
|
||||
|
||||
function countryUsesImperial(countryName) {
|
||||
var country = String(countryName || "")
|
||||
.replace(/^\s+|\s+$/g, "")
|
||||
.replace(/[._-]+/g, " ")
|
||||
.toLowerCase()
|
||||
if (!country) return null
|
||||
if (country === "us" || country === "usa" || country === "united states" || country === "united states of america") return true
|
||||
if (country === "liberia" || country === "myanmar" || country === "burma") return true
|
||||
return false
|
||||
}
|
||||
|
||||
function shouldUseImperial(unitOverride, localeName, countryName) {
|
||||
var unit = normalizedUnit(unitOverride)
|
||||
if (unit === "imperial") return true
|
||||
if (unit === "metric") return false
|
||||
|
||||
var countryPreference = countryUsesImperial(countryName)
|
||||
if (countryPreference !== null) return countryPreference
|
||||
|
||||
return localeUsesImperial(localeName)
|
||||
}
|
||||
|
||||
function dayName(dateString, formatter) {
|
||||
if (!dateString) return ""
|
||||
var d = new Date(dateString + "T12:00:00")
|
||||
@@ -143,6 +174,10 @@ if (typeof module !== "undefined") {
|
||||
roundedTemp: roundedTemp,
|
||||
celsiusToFahrenheit: celsiusToFahrenheit,
|
||||
formatTemp: formatTemp,
|
||||
normalizedUnit: normalizedUnit,
|
||||
localeUsesImperial: localeUsesImperial,
|
||||
countryUsesImperial: countryUsesImperial,
|
||||
shouldUseImperial: shouldUseImperial,
|
||||
dayName: dayName,
|
||||
openMeteoForecastDays: openMeteoForecastDays,
|
||||
wttrNextForecastDays: wttrNextForecastDays,
|
||||
|
||||
@@ -61,14 +61,9 @@ Panel {
|
||||
readonly property var current: report && report.current_condition && report.current_condition[0] ? report.current_condition[0] : null
|
||||
readonly property var areaInfo: report && report.nearest_area && report.nearest_area[0] ? report.nearest_area[0] : null
|
||||
readonly property var forecastDays: buildForecastDays()
|
||||
readonly property string reportCountry: areaInfo && areaInfo.country && areaInfo.country[0] ? areaInfo.country[0].value : ""
|
||||
|
||||
readonly property bool useImperial: {
|
||||
var override = setting("unit", "")
|
||||
if (override === "imperial") return true
|
||||
if (override === "metric") return false
|
||||
var name = String(Qt.locale().name || "")
|
||||
return /^en_US/.test(name) || /^en_LR/.test(name) || /^my/.test(name)
|
||||
}
|
||||
readonly property bool useImperial: Model.shouldUseImperial(setting("unit", ""), Qt.locale().name, reportCountry)
|
||||
|
||||
// Auto-refresh interval in minutes; clamped to a sane minimum.
|
||||
readonly property int refreshMinutes: Math.max(1, parseInt(setting("refreshMinutes", 15), 10) || 15)
|
||||
|
||||
Reference in New Issue
Block a user