FlatLocationForecast.qml 5.44 KB
Newer Older
Devin Lin's avatar
Devin Lin committed
1
/*
2
3
 * SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com>
 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com>
4
 * SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
Devin Lin's avatar
Devin Lin committed
5
6
7
8
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

Devin Lin's avatar
Devin Lin committed
9
10
11
12
13
import QtQuick 2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.2
import QtQuick.Shapes 1.12
import org.kde.kirigami 2.11 as Kirigami
Nicolas Fella's avatar
Nicolas Fella committed
14
import kweather 1.0
Devin Lin's avatar
Devin Lin committed
15

Devin Lin's avatar
Devin Lin committed
16
17
18
Kirigami.ScrollablePage {
    id: page
    verticalScrollBarPolicy: ScrollBar.AlwaysOff
Devin Lin's avatar
Devin Lin committed
19

Devin Lin's avatar
Devin Lin committed
20
21
    background: null // transparent, since there is a page behind

22
    property var weatherLocation
Nicolas Fella's avatar
Nicolas Fella committed
23
    property var currentDay: dailyListView.currentItem.weather
Nicolas Fella's avatar
Nicolas Fella committed
24
    property var currentHour: hourlyListView.currentItem.weather
Nicolas Fella's avatar
Nicolas Fella committed
25

Devin Lin's avatar
Devin Lin committed
26
    property bool inView: false
Devin Lin's avatar
Devin Lin committed
27

Devin Lin's avatar
Devin Lin committed
28
29
30
31
    // swipe down to refresh
    supportsRefreshing: true
    onRefreshingChanged: {
        if (refreshing) {
Han Young's avatar
Han Young committed
32
            weatherLocation.update();
Devin Lin's avatar
Devin Lin committed
33
        } else {
Pino Toscano's avatar
Pino Toscano committed
34
            showPassiveNotification(i18n("Weather refreshed for %1", weatherLocation.name));
Devin Lin's avatar
Devin Lin committed
35
36
37
38
        }
    }
    Connections {
        target: weatherLocation
39
40
41
        function onStopLoadingIndicator() {
            page.refreshing = false;
        }
Devin Lin's avatar
Devin Lin committed
42
    }
Devin Lin's avatar
Devin Lin committed
43

Devin Lin's avatar
Devin Lin committed
44
    // all elements are in a column
Devin Lin's avatar
Devin Lin committed
45
    ColumnLayout {
46
        spacing: 0
Devin Lin's avatar
Devin Lin committed
47
48
49
        RowLayout {
            Layout.alignment: Qt.AlignHCenter
            Kirigami.Icon {
Devin Lin's avatar
Devin Lin committed
50
                id: weatherIcon
Nicolas Fella's avatar
Nicolas Fella committed
51
                source: page.currentHour.weatherIcon
52
53
                Layout.preferredHeight: width
                Layout.preferredWidth: page.width * 0.8 - headerText.width
Devin Lin's avatar
Devin Lin committed
54
55
                Layout.maximumHeight: Kirigami.Theme.defaultFont.pointSize * 15
                Layout.maximumWidth: Kirigami.Theme.defaultFont.pointSize * 15
56
57
                Layout.minimumHeight: Kirigami.Theme.defaultFont.pointSize * 5
                Layout.minimumWidth: Kirigami.Theme.defaultFont.pointSize * 5
Devin Lin's avatar
Devin Lin committed
58
59
                smooth: true
            }
Devin Lin's avatar
Devin Lin committed
60
61

            // weather header
Devin Lin's avatar
Devin Lin committed
62
            ColumnLayout {
63
                id: headerText
Devin Lin's avatar
Devin Lin committed
64
                Label {
Devin Lin's avatar
Devin Lin committed
65
                    font.pointSize: Kirigami.Theme.defaultFont.pointSize * 3
Devin Lin's avatar
Devin Lin committed
66
                    font.weight: Font.Light
67
                    font.family: lightHeadingFont.name
Nicolas Fella's avatar
Nicolas Fella committed
68
                    text: Formatter.formatTemperatureRounded(page.currentHour.temperature)
Devin Lin's avatar
Devin Lin committed
69
70
                }
                Label {
Devin Lin's avatar
Devin Lin committed
71
                    font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.3
Devin Lin's avatar
Devin Lin committed
72
                    font.weight: Font.Bold
Nicolas Fella's avatar
Nicolas Fella committed
73
                    text: page.currentHour.weatherDescription
Devin Lin's avatar
Devin Lin committed
74
75
                }
                Label {
Devin Lin's avatar
Devin Lin committed
76
77
78
                    color: Kirigami.Theme.disabledTextColor
                    Layout.topMargin: Kirigami.Units.largeSpacing
                    font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.9
Yuri Chornoivan's avatar
Yuri Chornoivan committed
79
                    text: i18n("Updated at %1", weatherLocation.lastUpdated)
Devin Lin's avatar
Devin Lin committed
80
81
82
                }
            }
        }
83
84
85
86
87
88
89
90
91
        
        PageIndicator {
            visible: Kirigami.Settings.isMobile
            Layout.topMargin: Kirigami.Units.largeSpacing
            Layout.alignment: Qt.AlignHCenter
            opacity: forecastView.count > 1 ? 1 : 0
            count: forecastView.count
            currentIndex: forecastView.currentIndex
        }
Devin Lin's avatar
Devin Lin committed
92
93
94
95
96

        // daily view
        Label {
            text: i18n("Daily")
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.3
97
            Layout.topMargin: Kirigami.Units.largeSpacing
Devin Lin's avatar
Devin Lin committed
98
99
100
        }
        Kirigami.Separator {
            Layout.fillWidth: true
101
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
102
103
        }

104
        WeatherStrip {
Nicolas Fella's avatar
Nicolas Fella committed
105
            id: dailyListView
Devin Lin's avatar
Devin Lin committed
106
            Layout.fillWidth: true
107
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
            implicitHeight: Kirigami.Units.gridUnit * 8
            spacing: Kirigami.Units.largeSpacing

            highlightMoveDuration: 400
            highlightMoveVelocity: -1
            highlight: Rectangle {
                color: Kirigami.Theme.focusColor
                border {
                    color: Kirigami.Theme.focusColor
                    width: 1
                }
                radius: 4
                opacity: 0.3
                focus: true
            }
Devin Lin's avatar
Devin Lin committed
123

Nicolas Fella's avatar
Nicolas Fella committed
124
            model: weatherLocation.dayForecasts
Devin Lin's avatar
Devin Lin committed
125
            delegate: WeatherDayDelegate {
Nicolas Fella's avatar
Nicolas Fella committed
126
                weather: modelData
Devin Lin's avatar
Devin Lin committed
127
                textColor: Kirigami.Theme.textColor
Devin Lin's avatar
Devin Lin committed
128
            }
Nicolas Fella's avatar
Nicolas Fella committed
129
130
131
132

            onCurrentIndexChanged: {
                weatherLocation.selectedDay = currentIndex
            }
Devin Lin's avatar
Devin Lin committed
133
134
135
136
        }

        // hourly view
        Label {
137
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
138
139
140
141
142
            text: i18n("Hourly")
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.3
        }
        Kirigami.Separator {
            Layout.fillWidth: true
143
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
144
145
        }

146
        WeatherStrip {
Nicolas Fella's avatar
Nicolas Fella committed
147
            id: hourlyListView
148
            implicitHeight: Kirigami.Units.gridUnit * 10.5
149
150
            Layout.fillWidth: true
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
151

Nicolas Fella's avatar
Nicolas Fella committed
152
            model: weatherLocation.hourForecasts
153

Devin Lin's avatar
Devin Lin committed
154
            delegate: WeatherHourDelegate {
Nicolas Fella's avatar
Nicolas Fella committed
155
                weather: modelData
Nicolas Fella's avatar
Nicolas Fella committed
156
                textColor: Kirigami.Theme.textColor
157
            }
Devin Lin's avatar
Devin Lin committed
158
        }
Devin Lin's avatar
Devin Lin committed
159

160
        InfoCard {
Devin Lin's avatar
Devin Lin committed
161
            Layout.fillWidth: true
162
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
163
164
        }

165
        SunriseCard {
Devin Lin's avatar
Devin Lin committed
166
            Layout.fillWidth: true
167
            Layout.topMargin: Kirigami.Units.largeSpacing * 2
Devin Lin's avatar
Devin Lin committed
168
169
170
171
        }
    }
}