Debian Codegraph @

src/GUI/qml/Environment.qml

raw
1 import QtQuick 2.4
2 import QtQml 2.4
3 import FlightGear.Launcher 1.0
4 import FlightGear 1.0
5
6 Item {
7 Binding {
8 target: _launcher
9 property: "environmentSummary"
10 value: timeOfDay.summary().concat(weatherSettings.summary());
11 }
12
13 Flickable {
14 contentHeight: sectionColumn.childrenRect.height
15 flickableDirection: Flickable.VerticalFlick
16 anchors.fill: parent
17 anchors.leftMargin: Style.margin
18 anchors.rightMargin: Style.margin
19
20 Column
21 {
22 id: sectionColumn
23 width: parent.width
24
25 Item {
26 // below header margin
27 width: parent.width
28 height: Style.margin
29 }
30
31 Section {
32 id: timeOfDaySettings
33 title: qsTr("Time & Date")
34 settingGroup: "timeDate"
35
36 contents: [
37
38 SettingsComboBox {
39 id: timeOfDay
40 label: qsTr("Time of day")
41 description: qsTr("Select the time of day used when the simulator starts, or enter a "
42 + "custom date and time.")
43 choices: [qsTr("Current time"), qsTr("Dawn"), qsTr("Morning"), qsTr("Noon"),
44 qsTr("Afternoon"), qsTr("Dusk"), qsTr("Evening"),
45 qsTr("Midnight"), qsTr("Custom time & date")]
46 defaultIndex: 0
47 setting: "time-of-day"
48 readonly property var args: ["", "dawn", "morning", "noon", "afternoon",
49 "dusk", "evening", "midnight"]
50
51 readonly property bool isCustom: (selectedIndex == 8)
52 readonly property bool isDefault: (selectedIndex == 0)
53
54 function summary()
55 {
56 if (!timeOfDay.isCustom && !timeOfDay.isDefault) {
57 return [choices[selectedIndex].toLowerCase()];
58 }
59
60 return [];
61 }
62 },
63
64 SettingsDateTimePicker
65 {
66 id: customTime
67 label: qsTr("Custom time & date")
68 hidden: !timeOfDay.isCustom
69 description: qsTr("Enter a date and time to begin the flight at. By default this is "
70 + "in local time for the chosen starting location - use the option "
71 + "below to request a time in GMT / UTC.")
72 setting: "custom-time"
73 },
74
75 SettingCheckbox {
76 id: customTimeIsGMT
77 label: qsTr("Custom time is GMT / UTC")
78 visible: timeOfDay.isCustom
79 setting: "custom-time-is-gmt"
80 }
81 ]
82
83 onApply: {
84 if (timeOfDay.isCustom) {
85 var timeString = Qt.formatDateTime(customTime.value, "yyyy:MM:dd:hh:mm:ss");
86 if (customTimeIsGMT.checked) {
87 _config.setArg("start-date-gmt", timeString)
88 } else {
89 _config.setArg("start-date-sys", timeString)
90 }
91 } else if (timeOfDay.selectedIndex > 0) {
92 _config.setArg("timeofday", timeOfDay.args[timeOfDay.selectedIndex])
93 }
94 }
95 }
96
97 Section {
98 id: weatherSettings
99 title: qsTr("Weather")
100 settingGroup: "weather"
101
102 contents: [
103 SettingCheckbox {
104 id: advancedWeather
105 label: qsTr("Advanced weather modelling")
106 description: qsTr("Detailed weather simulation based on local terrain and "
107 + "atmospheric simulation. Note that using advanced weather with "
108 + "real-world weather data (METAR) information may not show exactly "
109 + "the conditions recorded, and is not recommended for multi-player "
110 + "flight since the weather simulation is not shared over the network.")
111 setting: "aws-enabled"
112 },
113
114 SettingCheckbox {
115 id: fetchMetar
116 label: qsTr("Real-world weather")
117 description: qsTr("Download real-world weather from the NOAA servers based on location.")
118 option: "real-weather-fetch"
119 setting: "fetch-metar"
120 },
121
122 SettingsComboBox {
123 id: weatherScenario
124 enabled: !fetchMetar.checked
125 label: qsTr("Weather scenario")
126 displayRole: "name"
127 model: _weatherScenarios
128 readonly property bool isCustomMETAR: (selectedIndex == 0);
129 description: _weatherScenarios.descriptionForItem(selectedIndex)
130 defaultIndex: 1
131 setting: "weather-scenario"
132 },
133
134 SettingLineEdit {
135 id: customMETAR
136
137 property bool isMETARValid: false
138
139 function revalidate() {
140 isMETARValid = _launcher.validateMetarString(value);
141 }
142
143 hidden: !weatherScenario.isCustomMETAR
144 enabled: !fetchMetar.checked
145 label: qsTr("METAR")
146 placeholder: "XXXX 012345Z 28035G50KT 250V300 9999 TSRA SCT022CB BKN030 13/09 Q1005"
147 useFullWidth: true
148 setting: "custom-metar"
149 description: isMETARValid ? qsTr("Enter a custom METAR string, e.g: '%1'").arg(placeholder)
150 : qsTr("The entered METAR string doesn't seem to be valid.")
151
152 onValueChanged: {
153 validateTimeout.restart()
154 }
155 }
156 ]
157
158 Timer {
159 id: validateTimeout
160 interval: 200
161 onTriggered: customMETAR.revalidate();
162 }
163
164 onApply: {
165 // important that we always set a value here, to override
166 // the auto-saved value in FlightGear. Otherwise we get
167 // confusing behaviour when the user toggles the setting
168 // inside the sim
169 _config.setProperty("/nasal/local_weather/enabled", advancedWeather.checked);
170
171 // Thorsten R advises that these are also needed for AW to startup
172 // correctly.
173 if (advancedWeather.checked) {
174 _config.setProperty("/sim/gui/dialogs/metar/mode/global-weather", !advancedWeather.checked);
175 _config.setProperty("/sim/gui/dialogs/metar/mode/local-weather", advancedWeather.checked);
176 _config.setProperty("/sim/gui/dialogs/metar/mode/manual-weather", advancedWeather.checked);
177 }
178
179 var index = weatherScenario.selectedIndex;
180
181 // set description from the weather scenarios, so Local-weather
182 // can run the appropriate simulation
183 if (fetchMetar.checked) {
184 if (advancedWeather.checked) {
185 _config.setProperty("/local-weather/tmp/tile-management", "METAR");
186 _config.setProperty("/local-weather/tmp/tile-type", "live");
187 }
188 } else {
189 if (weatherScenario.isCustomMETAR) {
190 if (customMETAR.isMETARValid && (customMETAR.value != "")) {
191 _config.setArg("metar", customMETAR.value)
192 }
193 } else {
194 _config.setArg("metar", _weatherScenarios.metarForItem(index))
195
196 var isISA = _weatherScenarios.nameForItem(index) == "International Standard Atmosphere";
197 _config.setProperty("/environment/atmosphere/is-isa", isISA);
198 }
199
200 // either way, set the scenario name since Local-Weather keys off
201 // this to know what to do with the scenario + metar data
202 _config.setProperty("/environment/weather-scenario",
203 _weatherScenarios.nameForItem(index))
204
205 if (advancedWeather.checked) {
206 // set AW tile options
207 var s = _weatherScenarios.localWeatherData(index);
208 if (s.length === 0) {
209 // local weather will use METAR
210 } else {
211 _config.setProperty("/local-weather/tmp/tile-management", s[0]);
212 _config.setProperty("/local-weather/tmp/tile-type", s[1]);
213 }
214 } // of using Advanced (local) weather
215 } // of not using real-wxr
216 }
217
218 function summary()
219 {
220 var result = [];
221 if (advancedWeather.checked) result.push(qsTr("advanced weather"));
222 if (fetchMetar.checked) result.push(qsTr("real-world weather"));
223 return result;
224 }
225 }
226 } // of Column
227 } // of Flickable
228 }