Fix weather symbol after load, fix Power Menu centering
This commit is contained in:
parent
d275efae04
commit
a22d7d75cc
2 changed files with 379 additions and 302 deletions
|
|
@ -2,19 +2,23 @@ import QtQuick
|
|||
import QtQuick.Layouts
|
||||
import QtQuick.Controls
|
||||
import qs.Settings
|
||||
import qs.Components
|
||||
import "../../Helpers/Weather.js" as WeatherHelper
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: weatherRoot
|
||||
width: 440 * Theme.scale(Screen)
|
||||
height: 180 * Theme.scale(Screen)
|
||||
color: "transparent"
|
||||
|
||||
anchors.horizontalCenterOffset: -2
|
||||
|
||||
property string city: Settings.settings.weatherCity !== undefined ? Settings.settings.weatherCity : ""
|
||||
property var weatherData: null
|
||||
property string errorString: ""
|
||||
property bool isVisible: false
|
||||
property int lastFetchTime: 0
|
||||
property bool isLoading: false
|
||||
|
||||
|
||||
// Auto-refetch weather when city changes
|
||||
Connections {
|
||||
target: Settings.settings
|
||||
|
|
@ -26,31 +30,31 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
if (isVisible) {
|
||||
fetchCityWeather()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fetchCityWeather() {
|
||||
if (!city || city.trim() === "") {
|
||||
errorString = "No city configured";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check if we should fetch new data (avoid fetching too frequently)
|
||||
var currentTime = Date.now();
|
||||
var timeSinceLastFetch = currentTime - lastFetchTime;
|
||||
|
||||
|
||||
// Only skip if we have recent data AND lastFetchTime is not 0 (initial state)
|
||||
if (lastFetchTime > 0 && timeSinceLastFetch < 60000) { // 1 minute
|
||||
return; // Skip if last fetch was less than 1 minute ago
|
||||
}
|
||||
|
||||
|
||||
isLoading = true;
|
||||
errorString = "";
|
||||
|
||||
|
||||
WeatherHelper.fetchCityWeather(city,
|
||||
function(result) {
|
||||
weatherData = result.weather;
|
||||
|
|
@ -64,138 +68,139 @@ Rectangle {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function startWeatherFetch() {
|
||||
isVisible = true
|
||||
// Force refresh when panel opens, regardless of time check
|
||||
lastFetchTime = 0;
|
||||
fetchCityWeather();
|
||||
}
|
||||
|
||||
|
||||
function stopWeatherFetch() {
|
||||
isVisible = false
|
||||
}
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: card
|
||||
anchors.fill: parent
|
||||
color: Theme.surface
|
||||
radius: 18
|
||||
|
||||
radius: 18 * Theme.scale(Screen)
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 18 * Theme.scale(screen)
|
||||
spacing: 12 * Theme.scale(screen)
|
||||
|
||||
|
||||
anchors.margins: 18 * Theme.scale(Screen)
|
||||
spacing: 12 * Theme.scale(Screen)
|
||||
|
||||
|
||||
RowLayout {
|
||||
spacing: 12 * Theme.scale(screen)
|
||||
spacing: 12 * Theme.scale(Screen)
|
||||
Layout.fillWidth: true
|
||||
|
||||
|
||||
|
||||
|
||||
RowLayout {
|
||||
spacing: 12 * Theme.scale(screen)
|
||||
Layout.preferredWidth: 140 * Theme.scale(screen)
|
||||
|
||||
spacing: 12 * Theme.scale(Screen)
|
||||
Layout.preferredWidth: 140 * Theme.scale(Screen)
|
||||
|
||||
|
||||
Spinner {
|
||||
id: loadingSpinner
|
||||
running: isLoading
|
||||
color: Theme.accentPrimary
|
||||
size: 28 * Theme.scale(Screen)
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
visible: isLoading
|
||||
}
|
||||
|
||||
Text {
|
||||
id: weatherIcon
|
||||
text: isLoading ? "sync" : (weatherData && weatherData.current_weather ? materialSymbolForCode(weatherData.current_weather.weathercode) : "cloud")
|
||||
visible: !isLoading
|
||||
text: weatherData && weatherData.current_weather ? materialSymbolForCode(weatherData.current_weather.weathercode) : "cloud"
|
||||
font.family: "Material Symbols Outlined"
|
||||
font.pixelSize: 28 * Theme.scale(screen)
|
||||
font.pixelSize: 28 * Theme.scale(Screen)
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: isLoading ? Theme.accentPrimary : Theme.accentPrimary
|
||||
color: Theme.accentPrimary
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
|
||||
// Add rotation animation for loading state
|
||||
RotationAnimation on rotation {
|
||||
running: isLoading
|
||||
from: 0
|
||||
to: 360
|
||||
duration: 1000
|
||||
loops: Animation.Infinite
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ColumnLayout {
|
||||
spacing: 2 * Theme.scale(screen)
|
||||
spacing: 2 * Theme.scale(Screen)
|
||||
RowLayout {
|
||||
spacing: 4 * Theme.scale(screen)
|
||||
spacing: 4 * Theme.scale(Screen)
|
||||
Text {
|
||||
text: city
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 14 * Theme.scale(screen)
|
||||
font.pixelSize: 14 * Theme.scale(Screen)
|
||||
font.bold: true
|
||||
color: Theme.textPrimary
|
||||
}
|
||||
Text {
|
||||
text: weatherData && weatherData.timezone_abbreviation ? `(${weatherData.timezone_abbreviation})` : ""
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 10 * Theme.scale(screen)
|
||||
font.pixelSize: 10 * Theme.scale(Screen)
|
||||
color: Theme.textSecondary
|
||||
leftPadding: 2 * Theme.scale(screen)
|
||||
leftPadding: 2 * Theme.scale(Screen)
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: weatherData && weatherData.current_weather ? ((Settings.settings.useFahrenheit !== undefined ? Settings.settings.useFahrenheit : false) ? `${Math.round(weatherData.current_weather.temperature * 9/5 + 32)}°F` : `${Math.round(weatherData.current_weather.temperature)}°C`) : ((Settings.settings.useFahrenheit !== undefined ? Settings.settings.useFahrenheit : false) ? "--°F" : "--°C")
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 24 * Theme.scale(screen)
|
||||
font.pixelSize: 24 * Theme.scale(Screen)
|
||||
font.bold: true
|
||||
color: Theme.textPrimary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 1 // Don't scale divider
|
||||
height: 1 * Theme.scale(Screen)
|
||||
color: Qt.rgba(Theme.textSecondary.g, Theme.textSecondary.g, Theme.textSecondary.b, 0.12)
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 2 * Theme.scale(screen)
|
||||
Layout.bottomMargin: 2 * Theme.scale(screen)
|
||||
Layout.topMargin: 2 * Theme.scale(Screen)
|
||||
Layout.bottomMargin: 2 * Theme.scale(Screen)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RowLayout {
|
||||
spacing: 12 * Theme.scale(screen)
|
||||
spacing: 12 * Theme.scale(Screen)
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
visible: weatherData && weatherData.daily && weatherData.daily.time
|
||||
|
||||
|
||||
Repeater {
|
||||
model: weatherData && weatherData.daily && weatherData.daily.time ? 5 : 0
|
||||
delegate: ColumnLayout {
|
||||
spacing: 2 * Theme.scale(screen)
|
||||
spacing: 2 * Theme.scale(Screen)
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
Text {
|
||||
|
||||
|
||||
text: Qt.formatDateTime(new Date(weatherData.daily.time[index]), "ddd")
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 12 * Theme.scale(screen)
|
||||
font.pixelSize: 12 * Theme.scale(Screen)
|
||||
color: Theme.textSecondary
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
Text {
|
||||
|
||||
|
||||
text: materialSymbolForCode(weatherData.daily.weathercode[index])
|
||||
font.family: "Material Symbols Outlined"
|
||||
font.pixelSize: 22 * Theme.scale(screen)
|
||||
font.pixelSize: 22 * Theme.scale(Screen)
|
||||
color: Theme.accentPrimary
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
Text {
|
||||
|
||||
|
||||
text: weatherData && weatherData.daily ? ((Settings.settings.useFahrenheit !== undefined ? Settings.settings.useFahrenheit : false) ? `${Math.round(weatherData.daily.temperature_2m_max[index] * 9/5 + 32)}° / ${Math.round(weatherData.daily.temperature_2m_min[index] * 9/5 + 32)}°` : `${Math.round(weatherData.daily.temperature_2m_max[index])}° / ${Math.round(weatherData.daily.temperature_2m_min[index])}°`) : ((Settings.settings.useFahrenheit !== undefined ? Settings.settings.useFahrenheit : false) ? "--° / --°" : "--° / --°")
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 12 * Theme.scale(screen)
|
||||
font.pixelSize: 12 * Theme.scale(Screen)
|
||||
color: Theme.textPrimary
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
|
@ -203,21 +208,21 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Text {
|
||||
text: errorString
|
||||
color: Theme.error
|
||||
visible: errorString !== ""
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 10 * Theme.scale(screen)
|
||||
font.pixelSize: 10 * Theme.scale(Screen)
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function materialSymbolForCode(code) {
|
||||
if (code === 0) return "sunny";
|
||||
if (code === 1 || code === 2) return "partly_cloudy_day";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue