1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
import QtQuick
import qs.Common
import qs.Services
import qs.Widgets
Rectangle {
id: root
radius: Theme.cornerRadius
property var date: null
property var daily: true
property var forecastData: null
property var dense: false
readonly property bool isCurrent: {
if (daily) {
date ? WeatherService.calendarDayDifference(new Date(), date) === 0 : false;
} else {
date ? WeatherService.calendarHourDifference(new Date(), date) === 0 : false;
}
}
readonly property string dateText: {
if (daily)
return root.forecastData?.day ?? "--";
if (!root.forecastData?.rawTime)
return root.forecastData?.time ?? "--";
try {
const date = new Date(root.forecastData.rawTime);
const format = SettingsData.use24HourClock ? "HH:mm" : "h:mm AP";
return date.toLocaleTimeString(Qt.locale(), format);
} catch (e) {
return root.forecastData?.time ?? "--";
}
}
readonly property var minTemp: WeatherService.formatTemp(root.forecastData?.tempMin)
readonly property var maxTemp: WeatherService.formatTemp(root.forecastData?.tempMax)
readonly property string minMaxTempText: (minTemp ?? "--") + "/" + (maxTemp ?? "--")
readonly property var temp: WeatherService.formatTemp(root.forecastData?.temp)
readonly property string tempText: temp ?? "--"
readonly property var feelsLikeTemp: WeatherService.formatTemp(root.forecastData?.feelsLike)
readonly property string feelsLikeText: feelsLikeTemp ?? "--"
readonly property var humidity: WeatherService.formatPercent(root.forecastData?.humidity)
readonly property string humidityText: humidity ?? "--"
readonly property var wind: {
SettingsData.windSpeedUnit;
SettingsData.useFahrenheit;
return WeatherService.formatSpeed(root.forecastData?.wind);
}
readonly property string windText: wind ?? "--"
readonly property var pressure: {
SettingsData.useFahrenheit;
return WeatherService.formatPressure(root.forecastData?.pressure);
}
readonly property string pressureText: pressure ?? "--"
readonly property var precipitation: root.forecastData?.precipitationProbability
readonly property string precipitationText: precipitation + "%" ?? "--"
readonly property var visibility: WeatherService.formatVisibility(root.forecastData?.visibility)
readonly property string visibilityText: visibility ?? "--"
readonly property var values: daily ? [] : [
{
"name"// 'name': "Temperature",
:
// 'text': root.tempText,
// 'icon': "thermometer"
// }, {
// 'name': "Feels Like",
// 'text': root.feelsLikeText,
// 'icon': "thermostat"
// }, {
I18n.tr("Humidity"),
"text": root.humidityText,
"icon": "humidity_low"
},
{
"name": I18n.tr("Wind Speed"),
"text": root.windText,
"icon": "air"
},
{
"name": I18n.tr("Pressure"),
"text": root.pressureText,
"icon": "speed"
},
{
"name": I18n.tr("Precipitation Chance"),
"text": root.precipitationText,
"icon": "rainy"
},
{
"name": I18n.tr("Visibility"),
"text": root.visibilityText,
"icon": "wb_sunny"
}
]
color: isCurrent ? Theme.withAlpha(Theme.primary, 0.1) : Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)
border.color: isCurrent ? Theme.withAlpha(Theme.primary, 0.3) : "transparent"
border.width: isCurrent ? 1 : 0
Column {
anchors.centerIn: parent
spacing: Theme.spacingXS
StyledText {
text: root.forecastData != null ? root.dateText : I18n.tr("Forecast Not Available")
font.pixelSize: Theme.fontSizeSmall
color: root.isCurrent ? Theme.primary : (root.forecastData ? Theme.surfaceText : Theme.outline)
font.weight: root.isCurrent ? Font.Medium : Font.Normal
anchors.horizontalCenter: parent.horizontalCenter
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: Theme.spacingM
visible: root.forecastData != null
Column {
spacing: Theme.spacingXS
DankIcon {
name: root.forecastData ? WeatherService.getWeatherIcon(root.forecastData.wCode || 0, root.forecastData.isDay ?? true) : "cloud"
size: Theme.iconSize
color: root.isCurrent ? Theme.primary : Theme.withAlpha(Theme.primary, 0.8)
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: root.daily ? root.minMaxTempText : root.tempText
font.pixelSize: Theme.fontSizeSmall
color: root.isCurrent ? Theme.primary : Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: root.feelsLikeText
font.pixelSize: Theme.fontSizeSmall
color: root.isCurrent ? Theme.primary : Theme.surfaceText
font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter
visible: !root.daily
}
}
Column {
id: detailsColumn
spacing: 2
visible: !root.dense
width: implicitWidth
states: [
State {
name: "dense"
when: root.dense
PropertyChanges {
target: detailsColumn
opacity: 0
width: 0
}
}
]
transitions: [
Transition {
NumberAnimation {
properties: "opacity,width"
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
]
Repeater {
model: root.values.length
Row {
spacing: 2
DankIcon {
name: root.values[index].icon
size: 8
color: Theme.withAlpha(Theme.surfaceText, 0.6)
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: root.values[index].text
font.pixelSize: Theme.fontSizeSmall - 2
color: Theme.withAlpha(Theme.surfaceText, 0.6)
anchors.verticalCenter: parent.verticalCenter
}
}
}
}
}
}
}
|