Warning, /plasma/kdeplasma-addons/applets/weather/package/contents/ui/ForecastView.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 * SPDX-FileCopyrightText: 2022 Ismael Asensio <isma.af@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 0010 import QtQuick.Layouts 0011 0012 import org.kde.plasma.core as PlasmaCore 0013 import org.kde.kirigami as Kirigami 0014 import org.kde.plasma.components as PlasmaComponents 0015 0016 GridLayout { 0017 id: root 0018 0019 property alias model: repeater.model 0020 property bool showNightRow: false 0021 readonly property int preferredIconSize: Kirigami.Units.iconSizes.large 0022 readonly property bool hasContent: model && model.length > 0 0023 readonly property var rowHasProbability: [...Array(rows).keys()].map( 0024 row => model.filter((_, index) => index % root.rows == row) 0025 .some(item => item.probability)) 0026 0027 Layout.minimumWidth: implicitWidth 0028 0029 columnSpacing: Kirigami.Units.smallSpacing 0030 rowSpacing: Kirigami.Units.largeSpacing 0031 0032 rows: showNightRow ? 2 : 1 0033 flow: showNightRow ? GridLayout.TopToBottom : GridLayout.LeftToRight 0034 0035 Repeater { 0036 id: repeater 0037 0038 delegate: ColumnLayout { 0039 id: dayDelegate 0040 // Allow to set placeholder items by leaving the data empty or setting a label text 0041 readonly property bool isPlaceHolder: !modelData || modelData.lenght === 0 || !!modelData.placeholder 0042 readonly property bool isFirstRow: (model.index % root.rows) === 0 0043 0044 Layout.fillWidth: true 0045 spacing: Math.round(Kirigami.Units.smallSpacing / 2) 0046 0047 PlasmaComponents.Label { 0048 id: periodLabel 0049 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter 0050 Layout.fillHeight: isPlaceHolder 0051 // Hide period titles on the second row 0052 visible: (isPlaceHolder || isFirstRow) 0053 0054 font.bold: true 0055 horizontalAlignment: Text.AlignHCenter 0056 text: isPlaceHolder ? modelData.placeholder || "" : modelData.period.replace(" nt", "") 0057 textFormat: Text.PlainText 0058 } 0059 0060 Kirigami.Icon { 0061 Layout.fillWidth: true 0062 Layout.preferredHeight: preferredIconSize 0063 Layout.preferredWidth: preferredIconSize 0064 visible: !isPlaceHolder 0065 0066 source: isPlaceHolder ? "" : modelData.icon 0067 0068 PlasmaCore.ToolTipArea { 0069 id: iconToolTip 0070 anchors.fill: parent 0071 mainText: { 0072 if (!modelData.condition) { 0073 return ""; 0074 } 0075 if (!modelData.probability) { 0076 return modelData.condition; 0077 } 0078 return i18nc("certain weather condition (probability percentage)", 0079 "%1 (%2%)", modelData.condition, modelData.probability); 0080 } 0081 } 0082 } 0083 0084 PlasmaComponents.Label { 0085 // Position it closer to the weather condition icon 0086 Layout.alignment: Qt.AlignTop | Qt.AlignHCenter 0087 Layout.topMargin: -Kirigami.Units.smallSpacing 0088 Layout.bottomMargin: Kirigami.Units.smallSpacing * 2 0089 0090 horizontalAlignment: Text.AlignHCenter 0091 // i18n: \ufe0e forces the text representation of the umbrella emoji 0092 text: modelData.probability ? i18nc("Probability of precipitation in percentage", "\ufe0e☂%1%", modelData.probability) : "·" 0093 textFormat: Text.PlainText 0094 visible: root.rowHasProbability[index % root.rows] && !!modelData.icon 0095 } 0096 0097 PlasmaComponents.Label { 0098 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter 0099 horizontalAlignment: Text.AlignHCenter 0100 text: !isPlaceHolder && modelData.tempHigh || i18nc("Short for no data available", "-") 0101 textFormat: Text.PlainText 0102 visible: !isPlaceHolder && (modelData.tempHigh || !showNightRow) 0103 } 0104 0105 PlasmaComponents.Label { 0106 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter 0107 horizontalAlignment: Text.AlignHCenter 0108 text: !isPlaceHolder && modelData.tempLow || i18nc("Short for no data available", "-") 0109 textFormat: Text.PlainText 0110 visible: !isPlaceHolder && (modelData.tempLow || !showNightRow) 0111 } 0112 } 0113 } 0114 }