Debian Codegraph @

src/app/qml/components/CurrentInfo.qml

raw
1 /*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This file is part of Lomiri Weather App
5 *
6 * Lomiri Weather App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Lomiri Weather App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 import QtQuick 2.12
20 import Lomiri.Components 1.3
21 import QtQuick.Layouts 1.1
22
23 Item {
24 id: currentInfoItem
25 anchors {
26 horizontalCenter: parent.horizontalCenter
27 }
28 height: collapsedHeight
29 width: weatherApp.width
30
31 state: "normal"
32 states: [
33 State {
34 name: "normal"
35 PropertyChanges {
36 target: currentInfoItem
37 height: collapsedHeight
38 }
39 PropertyChanges {
40 target: expandedInfo
41 opacity: 0
42 }
43 PropertyChanges {
44 target: updownIcon
45 name: "down"
46 }
47 },
48 State {
49 name: "expanded"
50 PropertyChanges {
51 target: currentInfoItem
52 height: expandedHeight
53 }
54 PropertyChanges {
55 target: expandedInfo
56 opacity: 1
57 }
58 PropertyChanges {
59 target: updownIcon
60 name: "up"
61 }
62 }
63 ]
64 transitions: [
65 Transition {
66 from: "normal"
67 to: "expanded"
68 SequentialAnimation {
69 ScriptAction {
70 script: expandedInfo.active = true
71 }
72 NumberAnimation {
73 easing.type: Easing.InOutQuad
74 properties: "height,opacity"
75 }
76 }
77 },
78 Transition {
79 from: "expanded"
80 to: "normal"
81 SequentialAnimation {
82 NumberAnimation {
83 easing.type: Easing.InOutQuad
84 properties: "height,opacity"
85 }
86 ScriptAction {
87 script: expandedInfo.active = false
88 }
89 }
90 }
91 ]
92
93 property int collapsedHeight //set in LocationPane.qml at coloredBackgroundRectangle
94 property int expandedHeight: collapsedHeight + units.gu(4) + (expandedInfo.item ? expandedInfo.item.height : 0)
95
96 objectName: "currentInfo"
97
98 property var modelData
99
100 property alias now: nowTempLabel.text
101 property alias icon: conditionIcon.source
102 property alias conditionNow: descriptionLabel.text
103 property alias feelsLike: feelsLabel.text
104 property alias clouds: cloudsLabel.text
105 property alias visibility: visibilityLabel.text
106 property alias wind: windLabel.text
107 property alias windGusts: gustsLabel.text
108 property alias humidity: humidityLabel.text
109 property alias uvIndex: uvLabel.text
110 property alias precipitationPropability: precipPropLabel.text
111
112 property color highColor: LomiriColors.orange
113 property color lowColor: LomiriColors.blue
114
115 RowLayout {
116 id: conditionRow
117 width: parent.width
118 anchors {
119 top: parent.top
120 topMargin: units.gu(1.25)
121 }
122 Label {
123 id: descriptionLabel
124 Layout.alignment: Qt.AlignHCenter
125
126 font.weight: Font.Normal
127 fontSize: "large"
128 width: parent.width
129 }
130 }
131
132 Item {
133 id: currentDataItem
134 width: parent.width
135
136 anchors {
137 horizontalCenter: parent.horizontalCenter
138 top: conditionRow.bottom
139 topMargin: units.gu(1.25)
140 }
141
142 Column {
143 id: leftColumn
144 width: parent.width/2 - units.gu(1)
145 anchors {
146 right: parent.horizontalCenter
147 rightMargin: units.gu(1)
148 }
149 spacing: units.gu(1)
150
151 Row {
152 anchors.right: parent.right
153 width: parent.width
154 spacing: units.gu(1.5)
155 layoutDirection: Qt.RightToLeft
156
157 GridLayout {
158 width: units.gu(8)
159 rowSpacing: units.gu(0.2)
160 columnSpacing: units.gu(0.5)
161 columns: 2
162
163 anchors {
164 top: parent.top
165 topMargin: units.gu(0.4)
166 }
167
168 Icon {
169 id: highImage
170 Layout.alignment: Qt.AlignLeft
171 height: units.gu(2)
172 width: units.gu(2)
173 name: "weather-clear-symbolic"
174 color: settings.highColor
175 }
176
177 Label {
178 id: highLabel
179 Layout.alignment: Qt.AlignRight
180 color: settings.highColor
181 font.weight: Font.Normal
182 font.pixelSize: units.gu(2.2)
183 text: modelData.high
184 }
185
186 Icon {
187 id: lowImage
188 Layout.alignment: Qt.AlignLeft
189 height: units.gu(2)
190 width: units.gu(2)
191 source: "qrc:/extended-information_moon.svg"
192 color: settings.lowColor
193 }
194
195 Label {
196 id: lowLabel
197 Layout.alignment: Qt.AlignRight
198 color: settings.lowColor
199 font.weight: Font.Normal
200 font.pixelSize: units.gu(2.2)
201 // font.weight: Font.Light //use this when emphasising high temp
202 // fontSize: "medium" //use this when emphasising high temp
203 text: modelData.low
204 }
205
206 Rectangle {
207 id: spacer1
208 height: units.gu(0.75)
209 width: height
210 color: "transparent"
211 }
212
213 Rectangle {
214 id: spacer2
215 height: units.gu(0.75)
216 width: height
217 color: "transparent"
218 }
219
220 Icon {
221 id: popIcon
222 Layout.alignment: Qt.AlignLeft
223 color: theme.palette.normal.baseText
224 width: units.gu(2.2)
225 height: width
226 source: "qrc:/extended-information_chance-of-sleet.svg"
227 }
228
229 Label {
230 id: precipPropLabel
231 Layout.alignment: Qt.AlignRight
232 font.pixelSize: units.gu(2.2)
233 font.weight: Font.Normal
234 }
235 }
236
237 Label {
238 id: nowTempLabel
239 font.pixelSize: units.gu(5.5)
240 font.weight: Font.Light
241 height: units.gu(6)
242 // width: units.gu(6)
243 verticalAlignment: Text.AlignBottom // AlignBottom seems to put it at the top?
244 }
245 }
246
247 Label {
248 id: feelsLabel
249 anchors.right: parent.right
250 font.weight: Font.Normal
251 font.pixelSize: units.gu(2.2)
252 }
253 }
254
255 Icon {
256 id: conditionIcon
257
258 anchors {
259 left: parent.horizontalCenter
260 leftMargin: units.gu(1)
261
262 top: parent.top
263 topMargin: units.gu(0.5)
264 }
265 width: units.gu(14)
266 height: width
267 }
268
269 Item {
270 id: bottomColumn
271 width: parent.width
272 height: childrenRect.height
273 anchors {
274 horizontalCenter: parent.horizontalCenter
275
276 top: conditionIcon.bottom
277 topMargin: units.gu(0.5)
278 }
279
280
281 Column {
282 spacing: units.gu(1)
283 anchors.right: centerSpacer.left
284 Label {
285 id: visibilityLabel
286 font.weight: Font.Normal
287 font.pixelSize: units.gu(1.75)
288 }
289 Label {
290 id: humidityLabel
291 font.weight: Font.Normal
292 font.pixelSize: units.gu(1.75)
293 }
294 Label {
295 id: uvLabel
296 font.weight: Font.Normal
297 font.pixelSize: units.gu(1.75)
298 }
299 }
300
301 Rectangle {
302 id: centerSpacer
303 anchors.horizontalCenter: parent.horizontalCenter
304 width: units.gu(2)
305 color: "transparent"
306 }
307
308 Column {
309 spacing: units.gu(1)
310 anchors.left: centerSpacer.right
311 Label {
312 id: windLabel
313 font.weight: Font.Normal
314 font.pixelSize: units.gu(1.75)
315 }
316 Label {
317 id: gustsLabel
318 font.weight: Font.Normal
319 font.pixelSize: units.gu(1.75)
320 }
321 Label {
322 id: cloudsLabel
323 font.weight: Font.Normal
324 font.pixelSize: units.gu(1.75)
325 }
326 }
327 }
328
329 Icon {
330 id: updownIcon
331 anchors {
332 horizontalCenter: parent.horizontalCenter
333 top: bottomColumn.bottom
334 topMargin: units.gu(0.5)
335 }
336 height: units.gu(2)
337 width: units.gu(2)
338 name: "down"
339 }
340
341 Loader {
342 id: expandedInfo
343 width: parent.width
344 active: false
345 anchors {
346 top: updownIcon.bottom
347 topMargin: units.gu(3)
348 }
349 asynchronous: true
350 opacity: 0
351 source: "DayDelegateExtraInfo.qml"
352
353 property var modelData: {
354 var tmp = ({});
355
356 // Remove the condition only for today extended info modelData
357 // as it is provided in current data in the column above
358 if (todayData) {
359 tmp = todayData;
360 tmp.condition = "";
361 }
362
363 return tmp;
364 }
365 }
366 }
367
368 MouseArea {
369 anchors {
370 fill: parent
371 }
372 onClicked: {
373 parent.state = parent.state === "normal" ? "expanded" : "normal"
374 // -2 as this is in header (not a delegate) and needs a fake index
375 locationPages.collapseOtherDelegates(-2)
376 }
377 }
378
379 Behavior on height {
380 NumberAnimation {
381 easing.type: Easing.InOutQuad
382 }
383 }
384
385 Component.onCompleted: {
386 locationPages.collapseOtherDelegates.connect(function(otherIndex) {
387 // -2 as this is in header (not a delegate) and needs a fake index
388 if (currentInfoItem && typeof index !== "undefined" && otherIndex !== -2) {
389 state = "normal"
390 }
391 });
392 }
393 }