Warning, /utilities/kweather/src/qml/TemperatureChartCard.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2020 Han Young <hanyoung@protonmail.com>
0003 * Copyright 2020 Devin Lin <espidev@gmail.com>
0004 * SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0005 *
0006 * SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008
0009 import QtQuick
0010 import QtQuick.Controls
0011 import QtQuick.Layouts
0012 import QtCharts
0013 import org.kde.kirigami as Kirigami
0014 import org.kde.kweather
0015 import org.kde.kweather.backgrounds
0016
0017 Kirigami.AbstractCard {
0018 id: tempChartCard
0019
0020 required property var location
0021 property var backgroundColor: location.cardBackgroundColor
0022 property var textColor: location.cardTextColor
0023
0024 leftPadding: 0; rightPadding: 0; topPadding: 0; bottomPadding: 0;
0025 implicitHeight: Math.round(Kirigami.Units.gridUnit * 8.5)
0026
0027 clip: true
0028
0029 contentItem: ScrollView {
0030 id: scrollView
0031 contentHeight: -1
0032 contentWidth: page.maximumContentWidth
0033
0034 Item {
0035 width: page.maximumContentWidth
0036 height: Math.round(Kirigami.Units.gridUnit * 8.5)
0037
0038 TemperatureChartData {
0039 id: chartData
0040 weatherData: location.dayForecasts
0041 }
0042
0043 ChartView {
0044 id: chartView
0045 anchors.fill: parent
0046 margins.left: Kirigami.Units.largeSpacing; margins.right: Kirigami.Units.largeSpacing
0047 margins.top: 0; margins.bottom: Kirigami.Units.smallSpacing
0048 legend.visible: false
0049 antialiasing: true
0050 localizeNumbers: true
0051 animationOptions: ChartView.NoAnimation
0052 backgroundColor: tempChartCard.backgroundColor
0053 plotAreaColor: tempChartCard.backgroundColor
0054
0055 height: tempChartCard.height
0056 width: Math.max(Kirigami.Units.gridUnit * 25, tempChartCard.width)
0057
0058 SplineSeries {
0059 id: splineSeries
0060 axisX: DateTimeAxis {
0061 id: axisX
0062 tickCount: dailyListView.count
0063 format: "ddd"
0064 labelsColor: tempChartCard.textColor
0065 lineVisible: false
0066 gridLineColor: Qt.rgba(tempChartCard.textColor.r, tempChartCard.textColor.g, tempChartCard.textColor.b, 0.05)
0067 }
0068 axisY: ValueAxis {
0069 id: axisY
0070 visible: false
0071
0072 min: chartData.minTempLimit
0073 max: chartData.maxTempLimit
0074 labelsColor: tempChartCard.textColor
0075 }
0076 name: i18n("temperature")
0077 pointLabelsVisible: true
0078 pointLabelsFormat: "@yPoint°"
0079 pointLabelsClipping: false
0080 pointLabelsColor: tempChartCard.textColor
0081 pointLabelsFont.pointSize: Kirigami.Theme.defaultFont.pointSize
0082 }
0083
0084 Component.onCompleted: {
0085 chartData.initAxes(axisX, axisY);
0086 chartData.initSeries(chartView.series(0));
0087 }
0088 Component.onDestruction: {
0089 // ensure that the series is a nullptr
0090 chartData.initSeries(null);
0091 }
0092 }
0093
0094 // allow continuous mouse scrolling
0095 MouseArea {
0096 anchors.fill: parent
0097 property int scrollDist: Kirigami.Units.gridUnit * 2
0098 onWheel: wheel => {
0099 //check if mouse is scrolling up or down
0100 if (wheel.angleDelta.y < 0){
0101 page.flickable.contentY += scrollDist
0102 } else {
0103 page.flickable.contentY -= scrollDist
0104 }
0105 }
0106 onPressed: mouse => mouse.accepted = false // forward mouse event
0107 onReleased: mouse => mouse.accepted = false // forward mouse event
0108 }
0109 }
0110 }
0111 }