Warning, /utilities/kweather/src/qml/Main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020-2021 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Controls 0010 import QtQuick.Layouts 0011 0012 import org.kde.kirigami as Kirigami 0013 0014 import org.kde.kweather.locations 0015 import org.kde.kweather.settings 0016 0017 import org.kde.kweather 0018 0019 Kirigami.ApplicationWindow { 0020 id: appwindow 0021 title: i18n("Weather") 0022 0023 minimumWidth: Kirigami.Settings.isMobile ? 0 : 360 0024 minimumHeight: Kirigami.Settings.isMobile ? 0 : 360 0025 width: Kirigami.Settings.isMobile ? Kirigami.Units.gridUnit * 27 : Kirigami.Units.gridUnit * 40 0026 height: Kirigami.Settings.isMobile ? Kirigami.Units.gridUnit * 45 : Kirigami.Units.gridUnit * 35 0027 0028 pageStack.globalToolBar.canContainHandles: true; // move handles to toolbar 0029 pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.ToolBar; // ensure toolbar style for mobile 0030 pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.ShowBackButton; 0031 pageStack.popHiddenPages: true 0032 0033 pageStack.columnView.columnResizeMode: Kirigami.ColumnView.SingleColumn 0034 0035 readonly property bool isWideScreen: width > 540 0036 0037 readonly property bool isDialogOpen: settingsDialogLoader.isOpen || addLocationDialogLoader.isOpen || locationsListDialogLoader.isOpen 0038 0039 Component.onCompleted: { 0040 // initial page 0041 switchToPage(getPage("Forecast"), 1); 0042 0043 if (settingsModel.firstStartup) { 0044 setupWizardLoader.source = "SetupWizard.qml"; 0045 setupWizardLoader.item.open(); 0046 } 0047 } 0048 0049 Loader { 0050 id: setupWizardLoader 0051 } 0052 0053 Kirigami.PagePool { 0054 id: pagePool 0055 } 0056 0057 // page switch animation 0058 NumberAnimation { 0059 id: anim 0060 from: 0 0061 to: 1 0062 duration: Kirigami.Units.longDuration * 2 0063 easing.type: Easing.InOutQuad 0064 } 0065 NumberAnimation { 0066 id: yAnim 0067 from: Kirigami.Units.gridUnit * 3 0068 to: 0 0069 duration: Kirigami.Units.longDuration * 3 0070 easing.type: Easing.OutQuint 0071 } 0072 0073 function switchToPage(page, depth) { 0074 while (pageStack.layers.depth > 1) pageStack.layers.pop(); 0075 while (pageStack.depth > depth) pageStack.pop(); 0076 runPageAnimations(page); 0077 pageStack.push(page); 0078 } 0079 0080 function pushPage(page, depth) { 0081 while (depth !== undefined && pageStack.depth > depth + 1) pageStack.pop(); 0082 runPageAnimations(page); 0083 pageStack.push(page); 0084 } 0085 0086 function runPageAnimations(page) { 0087 yAnim.target = page; 0088 yAnim.properties = "yTranslate"; 0089 anim.target = page; 0090 anim.properties = "contentItem.opacity"; 0091 if (page.header) { 0092 anim.properties += ",header.opacity"; 0093 } 0094 yAnim.restart(); 0095 anim.restart(); 0096 } 0097 0098 function getPage(name) { 0099 console.log('fetch ' + name) 0100 switch (name) { 0101 case "Forecast": return pagePool.loadPage(WeatherLocationListModel.count === 0 ? getPageUrl('', 'DefaultPage.qml') : getPageUrl('', 'ForecastContainerPage.qml')); 0102 case "Locations": return pagePool.loadPage("qrc:/qt/qml/org/kde/kweather/locations/qml/locationslist/LocationsListPage.qml"); 0103 case "Settings": return pagePool.loadPage(getPageUrl('settings', 'settings/SettingsPage.qml')); 0104 case "About": return pagePool.loadPage(getPageUrl('', 'AboutPage.qml')); 0105 case "Default": return pagePool.loadPage(getPageUrl('', 'DefaultPage.qml')); 0106 } 0107 } 0108 0109 function getPageUrl(module: string, file: string): string { 0110 if (module === '') { 0111 return `qrc:/qt/qml/org/kde/kweather/qml/${file}`; 0112 } 0113 return `qrc:/qt/qml/org/kde/kweather/${module}/qml/${file}`; 0114 } 0115 0116 function openSettings() { 0117 if (isWideScreen) { 0118 settingsDialogLoader.active = true; 0119 0120 if (Kirigami.Settings.isMobile) { 0121 // SettingsDialog 0122 settingsDialogLoader.item.open(); 0123 } else { 0124 // SettingsWindow 0125 settingsDialogLoader.item.close(); 0126 settingsDialogLoader.item.show(); 0127 } 0128 } else { 0129 applicationWindow().pushPage(getPage("Settings"), 0); 0130 } 0131 } 0132 0133 function openLocationsList() { 0134 if (isWideScreen) { 0135 locationsListDialogLoader.active = true; 0136 locationsListDialogLoader.item.open(); 0137 } else { 0138 applicationWindow().pushPage(getPage("Locations"), 0); 0139 } 0140 } 0141 0142 function openAddLocation() { 0143 if (isWideScreen) { 0144 addLocationDialogLoader.active = true; 0145 addLocationDialogLoader.item.open(); 0146 } else { 0147 applicationWindow().pageStack.push(getPageUrl('locations', 'locationslist/AddLocationPage.qml')) 0148 } 0149 } 0150 0151 Connections { 0152 target: WeatherLocationListModel 0153 0154 function onLocationsChanged() { 0155 // wwitch to default page if the count is zero 0156 if (WeatherLocationListModel.count === 0) { 0157 applicationWindow().switchToPage(applicationWindow().getPage("Default"), 0); 0158 } 0159 } 0160 } 0161 0162 Loader { 0163 id: settingsDialogLoader 0164 property bool isOpen: item && item.visible 0165 active: false 0166 sourceComponent: Kirigami.Settings.isMobile ? Qt.createComponent("org.kde.kweather.settings", "SettingsDialog") : Qt.createComponent("org.kde.kweather.settings", "SettingsWindow") 0167 } 0168 0169 Loader { 0170 id: addLocationDialogLoader 0171 property bool isOpen: item && item.visible 0172 active: false 0173 sourceComponent: AddLocationDialog {} 0174 } 0175 0176 Loader { 0177 id: locationsListDialogLoader 0178 property bool isOpen: item && item.visible 0179 active: false 0180 sourceComponent: LocationsListDialog {} 0181 } 0182 0183 FontLoader { 0184 id: lightHeadingFont 0185 source: "qrc:/resources/NotoSans-Light.ttf" 0186 } 0187 }