1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 13:32:50 -05:00

weather: m/s wind units and feels like

fixes #1463
fixes #1456
This commit is contained in:
bbedward
2026-01-22 14:44:40 -05:00
parent acdd1d2ec4
commit f24ecf1b99
6 changed files with 69 additions and 17 deletions

View File

@@ -147,6 +147,7 @@ Singleton {
property bool use24HourClock: true property bool use24HourClock: true
property bool showSeconds: false property bool showSeconds: false
property bool useFahrenheit: false property bool useFahrenheit: false
property string windSpeedUnit: "kmh"
property bool nightModeEnabled: false property bool nightModeEnabled: false
property int animationSpeed: SettingsData.AnimationSpeed.Short property int animationSpeed: SettingsData.AnimationSpeed.Short
property int customAnimationDuration: 500 property int customAnimationDuration: 500

View File

@@ -33,6 +33,7 @@ var SPEC = {
use24HourClock: { def: true }, use24HourClock: { def: true },
showSeconds: { def: false }, showSeconds: { def: false },
useFahrenheit: { def: false }, useFahrenheit: { def: false },
windSpeedUnit: { def: "kmh" },
nightModeEnabled: { def: false }, nightModeEnabled: { def: false },
animationSpeed: { def: 1 }, animationSpeed: { def: 1 },
customAnimationDuration: { def: 500 }, customAnimationDuration: { def: 500 },

View File

@@ -47,10 +47,17 @@ Rectangle {
readonly property var humidity: WeatherService.formatPercent(root.forecastData?.humidity) readonly property var humidity: WeatherService.formatPercent(root.forecastData?.humidity)
readonly property string humidityText: humidity ?? "--" readonly property string humidityText: humidity ?? "--"
readonly property var wind: WeatherService.formatSpeed(root.forecastData?.wind) readonly property var wind: {
SettingsData.windSpeedUnit;
SettingsData.useFahrenheit;
return WeatherService.formatSpeed(root.forecastData?.wind);
}
readonly property string windText: wind ?? "--" readonly property string windText: wind ?? "--"
readonly property var pressure: WeatherService.formatPressure(root.forecastData?.pressure) readonly property var pressure: {
SettingsData.useFahrenheit;
return WeatherService.formatPressure(root.forecastData?.pressure);
}
readonly property string pressureText: pressure ?? "--" readonly property string pressureText: pressure ?? "--"
readonly property var precipitation: root.forecastData?.precipitationProbability readonly property var precipitation: root.forecastData?.precipitationProbability

View File

@@ -229,10 +229,17 @@ Item {
} }
} }
StyledText {
property var feelsLike: SettingsData.useFahrenheit ? (WeatherService.weather.feelsLikeF || WeatherService.weather.tempF) : (WeatherService.weather.feelsLike || WeatherService.weather.temp)
text: I18n.tr("Feels Like %1°", "weather feels like temperature").arg(feelsLike)
font.pixelSize: Theme.fontSizeSmall
color: Theme.withAlpha(Theme.surfaceText, 0.7)
}
StyledText { StyledText {
text: WeatherService.weather.city || "" text: WeatherService.weather.city || ""
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7) color: Theme.withAlpha(Theme.surfaceText, 0.7)
visible: text.length > 0 visible: text.length > 0
} }
} }
@@ -253,7 +260,7 @@ Item {
id: sunriseIcon id: sunriseIcon
name: "wb_twilight" name: "wb_twilight"
size: Theme.iconSize - 6 size: Theme.iconSize - 6
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6) color: Theme.withAlpha(Theme.surfaceText, 0.6)
anchors.left: parent.left anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -272,7 +279,7 @@ Item {
} }
} }
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6) color: Theme.withAlpha(Theme.surfaceText, 0.6)
anchors.left: sunriseIcon.right anchors.left: sunriseIcon.right
anchors.leftMargin: Theme.spacingXS anchors.leftMargin: Theme.spacingXS
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View File

@@ -363,6 +363,25 @@ Item {
onToggled: checked => SettingsData.set("useFahrenheit", checked) onToggled: checked => SettingsData.set("useFahrenheit", checked)
} }
Rectangle {
width: parent.width
height: 1
color: Theme.outline
opacity: 0.15
visible: !SettingsData.useFahrenheit
}
SettingsToggleRow {
tab: "time"
tags: ["weather", "wind", "speed", "units", "metric"]
settingKey: "windSpeedUnit"
text: I18n.tr("Wind Speed in m/s")
description: I18n.tr("Use meters per second instead of km/h for wind speed")
checked: SettingsData.windSpeedUnit === "ms"
onToggled: checked => SettingsData.set("windSpeedUnit", checked ? "ms" : "kmh")
visible: !SettingsData.useFahrenheit
}
Rectangle { Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
@@ -689,6 +708,13 @@ Item {
} }
} }
StyledText {
property var feelsLike: SettingsData.useFahrenheit ? (WeatherService.weather.feelsLikeF || WeatherService.weather.tempF) : (WeatherService.weather.feelsLike || WeatherService.weather.temp)
text: I18n.tr("Feels Like %1°").arg(feelsLike)
font.pixelSize: Theme.fontSizeSmall
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.5)
}
StyledText { StyledText {
text: WeatherService.weather.city || "" text: WeatherService.weather.city || ""
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
@@ -891,20 +917,24 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
StyledText { StyledText {
id: windText
text: { text: {
if (!WeatherService.weather.wind) SettingsData.windSpeedUnit;
return "--"; SettingsData.useFahrenheit;
const windKmh = parseFloat(WeatherService.weather.wind); return WeatherService.formatSpeed(WeatherService.weather.wind) || "--";
if (isNaN(windKmh))
return WeatherService.weather.wind;
if (SettingsData.useFahrenheit)
return Math.round(windKmh * 0.621371) + " mph";
return WeatherService.weather.wind;
} }
font.pixelSize: Theme.fontSizeSmall + 1 font.pixelSize: Theme.fontSizeSmall + 1
color: Theme.surfaceText color: Theme.surfaceText
font.weight: Font.Medium font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: SettingsData.useFahrenheit ? Qt.ArrowCursor : Qt.PointingHandCursor
enabled: !SettingsData.useFahrenheit
onClicked: SettingsData.set("windSpeedUnit", SettingsData.windSpeedUnit === "kmh" ? "ms" : "kmh")
}
} }
} }
} }

View File

@@ -354,9 +354,15 @@ Singleton {
if (kmh == null) { if (kmh == null) {
return null; return null;
} }
const value = SettingsData.useFahrenheit ? Math.round(kmh * 0.621371) : kmh; if (SettingsData.useFahrenheit) {
const unit = SettingsData.useFahrenheit ? "mph" : "km/h"; const value = Math.round(kmh * 0.621371);
return includeUnits ? value + " " + unit : value; return includeUnits ? value + " mph" : value;
}
if (SettingsData.windSpeedUnit === "ms") {
const value = (kmh / 3.6).toFixed(1);
return includeUnits ? value + " m/s" : value;
}
return includeUnits ? kmh + " km/h" : kmh;
} }
function formatPressure(hpa, includeUnits = true) { function formatPressure(hpa, includeUnits = true) {
@@ -805,7 +811,7 @@ Singleton {
"country": root.location?.country || "Unknown", "country": root.location?.country || "Unknown",
"wCode": current.weather_code || 0, "wCode": current.weather_code || 0,
"humidity": Math.round(current.relative_humidity_2m || 0), "humidity": Math.round(current.relative_humidity_2m || 0),
"wind": Math.round(current.wind_speed_10m || 0) + " " + (currentUnits.wind_speed_10m || 'm/s'), "wind": Math.round(current.wind_speed_10m || 0),
"sunrise": formatTime(daily.sunrise?.[0]) || "06:00", "sunrise": formatTime(daily.sunrise?.[0]) || "06:00",
"sunset": formatTime(daily.sunset?.[0]) || "18:00", "sunset": formatTime(daily.sunset?.[0]) || "18:00",
"rawSunrise": daily.sunrise?.[0] || "", "rawSunrise": daily.sunrise?.[0] || "",