Warning, /utilities/kweather/src/qml/settings/SettingsComponent.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-2022 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 import org.kde.kirigamiaddons.formcard as FormCard 0014 0015 ColumnLayout { 0016 id: root 0017 property var dialog: null // dialog component if this is within a dialog 0018 0019 spacing: 0 0020 0021 signal closeRequested() 0022 0023 // HACK: dialog switching requires some time between closing and opening 0024 Timer { 0025 id: dialogTimer 0026 interval: 1 0027 property var dialog 0028 onTriggered: { 0029 root.dialog.close(); 0030 dialog.open(); 0031 } 0032 } 0033 0034 FormCard.FormHeader { 0035 title: i18n("General") 0036 } 0037 0038 FormCard.FormCard { 0039 FormCard.FormComboBoxDelegate { 0040 id: forecastStyleDropdown 0041 text: i18n("Forecast Style") 0042 currentIndex: indexOfValue(settingsModel.forecastStyle) 0043 model: ListModel { 0044 // we can't use i18n with ListElement 0045 Component.onCompleted: { 0046 append({"name": i18n("Flat"), "value": "Flat"}); 0047 append({"name": i18n("Dynamic"), "value": "Dynamic"}); 0048 0049 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here 0050 forecastStyleDropdown.currentIndex = forecastStyleDropdown.indexOfValue(settingsModel.forecastStyle) 0051 } 0052 } 0053 0054 textRole: "name" 0055 valueRole: "value" 0056 onActivated: settingsModel.save() 0057 onCurrentValueChanged: settingsModel.forecastStyle = currentValue; 0058 0059 onClicked: { 0060 if (root.dialog && forecastStyleDropdown.mode === FormCard.FormComboBoxDelegate.Dialog) { 0061 dialogTimer.dialog = forecastStyleDropdown.dialog; 0062 dialogTimer.restart(); 0063 } 0064 } 0065 0066 Connections { 0067 target: forecastStyleDropdown.dialog 0068 function onClosed() { 0069 if (root.dialog) { 0070 root.dialog.open(); 0071 } 0072 } 0073 } 0074 } 0075 0076 FormCard.FormDelegateSeparator { above: forecastStyleDropdown; below: aboutButton } 0077 0078 FormCard.FormButtonDelegate { 0079 id: aboutButton 0080 text: i18n("About") 0081 onClicked: { 0082 applicationWindow().pageStack.push(getPage("About")); 0083 0084 if (root.dialog) { 0085 root.dialog.close(); 0086 } 0087 } 0088 } 0089 } 0090 0091 FormCard.FormHeader { 0092 title: i18n("Units") 0093 } 0094 0095 FormCard.FormCard { 0096 FormCard.FormComboBoxDelegate { 0097 id: temperatureUnitsDropdown 0098 text: i18n("Temperature Units") 0099 currentIndex: indexOfValue(settingsModel.temperatureUnits) 0100 model: ListModel { 0101 // we can't use i18n with ListElement 0102 Component.onCompleted: { 0103 append({"name": i18n("Use System Default"), "value": "Use System Default"}); 0104 append({"name": i18n("Celsius"), "value": "Celsius"}); 0105 append({"name": i18n("Fahrenheit"), "value": "Fahrenheit"}); 0106 0107 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here 0108 temperatureUnitsDropdown.currentIndex = temperatureUnitsDropdown.indexOfValue(settingsModel.temperatureUnits) 0109 } 0110 } 0111 0112 textRole: "name" 0113 valueRole: "value" 0114 onActivated: settingsModel.save() 0115 onCurrentValueChanged: settingsModel.temperatureUnits = currentValue; 0116 0117 onClicked: { 0118 if (root.dialog && temperatureUnitsDropdown.mode === FormCard.FormComboBoxDelegate.Dialog) { 0119 dialogTimer.dialog = temperatureUnitsDropdown.dialog; 0120 dialogTimer.restart(); 0121 } 0122 } 0123 0124 Connections { 0125 target: temperatureUnitsDropdown.dialog 0126 function onClosed() { 0127 if (root.dialog) { 0128 root.dialog.open(); 0129 } 0130 } 0131 } 0132 } 0133 0134 FormCard.FormDelegateSeparator { above: temperatureUnitsDropdown; below: speedUnitsDropdown } 0135 0136 FormCard.FormComboBoxDelegate { 0137 id: speedUnitsDropdown 0138 text: i18n("Speed Units") 0139 currentIndex: indexOfValue(settingsModel.speedUnits) 0140 model: ListModel { 0141 // we can't use i18n with ListElement 0142 Component.onCompleted: { 0143 append({"name": i18nc("kilometers per hour", "kph"), "value": "kph"}); 0144 append({"name": i18nc("miles per hour", "mph"), "value": "mph"}); 0145 append({"name": i18nc("meters per second", "m/s"), "value": "m/s"}); 0146 0147 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here 0148 speedUnitsDropdown.currentIndex = speedUnitsDropdown.indexOfValue(settingsModel.speedUnits) 0149 } 0150 } 0151 0152 textRole: "name" 0153 valueRole: "value" 0154 onActivated: settingsModel.save() 0155 onCurrentValueChanged: settingsModel.speedUnits = currentValue; 0156 0157 onClicked: { 0158 if (root.dialog && speedUnitsDropdown.mode === FormCard.FormComboBoxDelegate.Dialog) { 0159 dialogTimer.dialog = speedUnitsDropdown.dialog; 0160 dialogTimer.restart(); 0161 } 0162 } 0163 0164 Connections { 0165 target: speedUnitsDropdown.dialog 0166 function onClosed() { 0167 if (root.dialog) { 0168 root.dialog.open(); 0169 } 0170 } 0171 } 0172 } 0173 0174 FormCard.FormDelegateSeparator { above: speedUnitsDropdown; below: pressureUnitsDropdown } 0175 0176 FormCard.FormComboBoxDelegate { 0177 id: pressureUnitsDropdown 0178 text: i18n("Pressure Units") 0179 currentIndex: indexOfValue(settingsModel.pressureUnits) 0180 model: ListModel { 0181 // we can't use i18n with ListElement 0182 Component.onCompleted: { 0183 append({"name": i18nc("Hectopascal Pressure", "hPa"), "value": "hPa"}); 0184 append({"name": i18nc("Millimetre of mercury", "mmHg"), "value": "mmHg"}); 0185 0186 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here 0187 pressureUnitsDropdown.currentIndex = pressureUnitsDropdown.indexOfValue(settingsModel.pressureUnits) 0188 } 0189 } 0190 0191 textRole: "name" 0192 valueRole: "value" 0193 onActivated: settingsModel.save() 0194 onCurrentValueChanged: settingsModel.pressureUnits = currentValue; 0195 0196 onClicked: { 0197 if (root.dialog && pressureUnitsDropdown.mode === FormCard.FormComboBoxDelegate.Dialog) { 0198 dialogTimer.dialog = pressureUnitsDropdown.dialog; 0199 dialogTimer.restart(); 0200 } 0201 } 0202 0203 Connections { 0204 target: pressureUnitsDropdown.dialog 0205 function onClosed() { 0206 if (root.dialog) { 0207 root.dialog.open(); 0208 } 0209 } 0210 } 0211 } 0212 0213 FormCard.FormDelegateSeparator { above: pressureUnitsDropdown; below: precipitationUnitsDropdown } 0214 0215 // Precipitation 0216 FormCard.FormComboBoxDelegate { 0217 id: precipitationUnitsDropdown 0218 text: i18n("Precipitation Units") 0219 currentIndex: indexOfValue(settingsModel.precipitationUnits) 0220 model: ListModel { 0221 // we can't use i18n with ListElement 0222 Component.onCompleted: { 0223 append({"name": i18nc("Millimeters", "mm"), "value": "mm"}); 0224 append({"name": i18nc("Inches", "in"), "value": "in"}); 0225 0226 // indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here 0227 precipitationUnitsDropdown.currentIndex = precipitationUnitsDropdown.indexOfValue(settingsModel.precipitationUnits) 0228 } 0229 } 0230 0231 textRole: "name" 0232 valueRole: "value" 0233 onActivated: settingsModel.save() 0234 onCurrentValueChanged: settingsModel.precipitationUnits = currentValue; 0235 0236 onClicked: { 0237 if (root.dialog && precipitationUnitsDropdown.mode === FormCard.FormComboBoxDelegate.Dialog) { 0238 dialogTimer.dialog = precipitationUnitsDropdown.dialog; 0239 dialogTimer.restart(); 0240 } 0241 } 0242 0243 Connections { 0244 target: precipitationUnitsDropdown.dialog 0245 function onClosed() { 0246 if (root.dialog) { 0247 root.dialog.open(); 0248 } 0249 } 0250 } 0251 } 0252 } 0253 }