Warning, /plasma/kdeplasma-addons/applets/weather/package/contents/ui/SwitchPanel.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: 2023 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 import QtQuick.Controls as QQC2
0012 
0013 import org.kde.plasma.components as PlasmaComponents
0014 
0015 ColumnLayout {
0016     id: root
0017 
0018     required property var forecastModel
0019     required property var detailsModel
0020     required property var noticesModel
0021 
0022     required property bool forecastViewNightRow
0023     required property string forecastViewTitle
0024 
0025     readonly property var pagesModel: {
0026         const pages = [{
0027             title: root.forecastViewTitle,
0028             view: forecastView,
0029         }]
0030         if (root.detailsModel && root.detailsModel.length > 0) {
0031             pages.push({
0032                 title: i18nc("@title:tab", "Details"),
0033                 view: detailsView,
0034             })
0035         }
0036         if (root.noticesModel && root.noticesModel.length > 0) {
0037             pages.push({
0038                 title: i18ncp("@title:tab %1 is the number of weather notices (alerts, warnings, watches, ...) issued",
0039                               "%1 Notice", "%1 Notices", noticesModel.length),
0040                 view: noticesView,
0041                 // Show warning icon if the maximum priority shown is at least 2 (Moderate)
0042                 icon: noticesModel.reduce((acc, notice) => Math.max(notice.priority, acc), 0) >= 2 ?
0043                     'data-warning-symbolic' : 'data-information-symbolic',
0044             })
0045         }
0046         return pages
0047     }
0048 
0049     PlasmaComponents.TabBar {
0050         id: tabBar
0051 
0052         Layout.fillWidth: true
0053         visible: root.pagesModel.length > 1
0054 
0055         Repeater {
0056             model: root.pagesModel
0057             delegate: PlasmaComponents.TabButton {
0058                 text: modelData.title
0059                 icon.name: modelData.icon ?? ""
0060             }
0061         }
0062 
0063         onCurrentIndexChanged: {
0064             // Avoid scrolling conflicts between SwipeView and NoticesView
0065             swipeView.interactive = false;
0066             swipeView.setCurrentIndex(currentIndex);
0067             swipeView.interactive = true;
0068         }
0069     }
0070 
0071     QQC2.SwipeView {
0072         id: swipeView
0073 
0074         Layout.fillWidth: true
0075         Layout.fillHeight: true
0076         Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
0077         Layout.minimumWidth: contentChildren.reduce((acc, loader) => Math.max(loader.item.Layout.minimumWidth, acc), 0)
0078         Layout.minimumHeight: contentChildren.reduce((acc, loader) => Math.max(loader.item.Layout.minimumHeight, acc), 0)
0079         clip: true // previous/next views are prepared outside of view, do not render them
0080 
0081         Repeater {
0082             model: root.pagesModel
0083             delegate: Loader {
0084                 sourceComponent: modelData.view
0085             }
0086         }
0087 
0088         onCurrentIndexChanged: {
0089             tabBar.setCurrentIndex(currentIndex);
0090         }
0091     }
0092 
0093     Component {
0094         id: forecastView
0095         ForecastView {
0096             model: root.forecastModel
0097             showNightRow: root.forecastViewNightRow
0098         }
0099     }
0100 
0101     Component {
0102         id: detailsView
0103         DetailsView {
0104             model: root.detailsModel
0105         }
0106     }
0107 
0108     Component {
0109         id: noticesView
0110         NoticesView {
0111             model: root.noticesModel
0112             // Avoid scrolling conflicts between SwipeView and NoticesView
0113             interactive: swipeView.contentItem.atXEnd
0114         }
0115     }
0116 }