Debian Codegraph @

src/GUI/qml/AircraftList.qml

raw
1 // SPDX-FileCopyrightText: 2018 James Turner
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 import QtQuick 2.2
5 import FlightGear.Launcher 1.0 as FG
6 import FlightGear 1.0
7
8 FocusScope
9 {
10 id: root
11
12 property var __model: null
13 property Component __header: null
14 property Component __footer: null
15 property string __lastState: "installed"
16
17 function updateSelectionFromLauncher()
18 {
19 if (aircraftContent.item) {
20 aircraftContent.item.updateSelectionFromLauncher();
21 }
22 }
23
24 state: "installed"
25
26 Component.onCompleted: {
27 _launcher.browseAircraftModel.loadRatingsSettings();
28
29 // if the user has favourites defined, default to that tab
30 if (_launcher.favouriteAircraftModel.count > 0) {
31 root.state = "favourites"
32 root.updateSelectionFromLauncher();
33 }
34 }
35
36 GettingStartedScope.controller: tipsLayer.controller
37
38 Rectangle
39 {
40 id: tabBar
41 height: searchButton.height + (Style.margin * 2)
42 width: parent.width
43 color: Style.backgroundColor
44
45 GridToggleButton {
46 id: gridModeToggle
47 anchors.verticalCenter: parent.verticalCenter
48 anchors.left: parent.left
49 anchors.leftMargin: Style.margin
50 gridMode: !_launcher.aircraftGridMode
51 onClicked: _launcher.aircraftGridMode = !_launcher.aircraftGridMode
52
53 GettingStartedTip {
54 tipId: "gridModeTip"
55
56 anchors {
57 horizontalCenter: parent.horizontalCenter
58 horizontalCenterOffset: Style.margin
59 top: parent.bottom
60 }
61 arrow: GettingStartedTip.TopLeft
62 text: qsTr("Toggle between grid and list view")
63 }
64 }
65
66 Row {
67 anchors.centerIn: parent
68 spacing: Style.margin
69
70 TabButton {
71 id: installedAircraftButton
72 text: qsTr("Installed Aircraft")
73 onClicked: {
74 root.state = "installed"
75 root.updateSelectionFromLauncher();
76 }
77 active: root.state == "installed"
78
79 GettingStartedTip {
80 tipId: "installedAircraftTip"
81 nextTip: "gridModeTip"
82
83 anchors {
84 horizontalCenter: parent.horizontalCenter
85 top: parent.bottom
86 }
87 arrow: GettingStartedTip.TopCenter
88 text: qsTr("Use this button to view installed aircraft")
89 }
90 }
91
92 TabButton {
93 id: favouritesButton
94 text: qsTr("Favourites")
95 onClicked: {
96 root.state = "favourites"
97 root.updateSelectionFromLauncher();
98 }
99 active: root.state == "favourites"
100 }
101
102 TabButton {
103 id: browseButton
104 enabled: _launcher.isNetworkAvailable
105
106 text: qsTr("Browse")
107 onClicked: {
108 root.state = "browse"
109 root.updateSelectionFromLauncher();
110 }
111 active: root.state == "browse"
112
113 GettingStartedTip {
114 tipId: "browseTip"
115 nextTip: "searchAircraftTip"
116
117 anchors {
118 horizontalCenter: parent.horizontalCenter
119 top: parent.bottom
120 }
121 arrow: GettingStartedTip.TopCenter
122 text: qsTr("View available aircraft to download")
123 }
124 }
125
126 TabButton {
127 id: updatesButton
128 enabled: _launcher.isNetworkAvailable
129 // visible: _launcher.baseAircraftModel.showUpdateAll
130 text: qsTr("Updates")
131 onClicked: {
132 root.state = "updates"
133 root.updateSelectionFromLauncher();
134 }
135 active: root.state == "updates"
136 }
137 } // of header row
138
139 SearchButton {
140 id: searchButton
141
142 height: installedAircraftButton.height
143
144 anchors.right: parent.right
145 anchors.rightMargin: Style.margin
146 anchors.verticalCenter: parent.verticalCenter
147
148 onSearch: function(term) {
149 _launcher.searchAircraftModel.setAircraftFilterString(term)
150 root.state = "search"
151 root.updateSelectionFromLauncher();
152 }
153
154 active: root.state == "search"
155
156 GettingStartedTip {
157 tipId: "searchAircraftTip"
158 nextTip: "installedAircraftTip"
159
160 anchors {
161 horizontalCenter: parent.horizontalCenter
162 top: parent.bottom
163 }
164 arrow: GettingStartedTip.TopRight
165 text: qsTr("Enter text to search aircraft names and descriptions.")
166 }
167 }
168 }
169
170 Rectangle {
171 id: tabBarDivider
172 color: Style.frameColor
173 height: 1
174 width: parent.width - Style.inset
175 anchors.horizontalCenter: parent.horizontalCenter
176 anchors.top: tabBar.bottom
177 }
178
179 Component {
180 id: ratingsHeader
181 AircraftRatingsPanel {
182 width: aircraftContent.width
183 tips: tipsLayer
184 onClearSelection: {
185 _launcher.selectedAircraft = "";
186 root.updateSelectionFromLauncher()
187 }
188 }
189 }
190
191 Component {
192 id: noDefaultCatalogHeader
193 NoDefaultCatalogPanel {
194 width: aircraftContent.width
195 }
196 }
197
198 Component {
199 id: updateAllHeader
200 UpdateAllPanel {
201 width: aircraftContent.width
202 }
203 }
204
205 Component {
206 id: searchHeader
207 Rectangle {
208 visible: _launcher.searchAircraftModel.count === 0
209 width: aircraftContent.width
210 height: visible ? Style.strutSize : 0
211
212 StyledText {
213 anchors.fill: parent
214 text: qsTr("No aircraft match the search.")
215 wrapMode: Text.WordWrap
216 font.pixelSize: Style.headingFontPixelSize
217 horizontalAlignment: Text.AlignHCenter
218 verticalAlignment: Text.AlignVCenter
219 }
220 }
221 }
222
223 Component {
224 id: noFavouritesHeader
225 Rectangle {
226 visible: _launcher.favouriteAircraftModel.count === 0
227 width: aircraftContent.width
228 height: visible ? Style.strutSize : 0
229
230 StyledText {
231 anchors.fill: parent
232 text: qsTr("No favourite aircraft selected: install some aircraft and mark them as favourites by clicking the \u2605")
233 wrapMode: Text.WordWrap
234 font.pixelSize: Style.headingFontPixelSize
235 horizontalAlignment: Text.AlignHCenter
236 verticalAlignment: Text.AlignVCenter
237 }
238 }
239 }
240
241
242 Component {
243 id: emptyHeaderFooter
244 Item {
245 }
246 }
247
248 Component {
249 id: installMoreAircraftFooter
250 Rectangle {
251 visible: _launcher.baseAircraftModel.installedAircraftCount < 50
252 width: aircraftContent.width
253 height: Style.strutSize
254
255 StyledText {
256 anchors.fill: parent
257 text: qsTr("To install additional aircraft, click on the 'Browse' tab at the top of this page. (This requires a network connection.)")
258 wrapMode: Text.WordWrap
259 font.pixelSize: Style.headingFontPixelSize
260 horizontalAlignment: Text.AlignHCenter
261 verticalAlignment: Text.AlignVCenter
262 }
263 }
264 }
265
266 Loader {
267 id: aircraftContent
268 // we use gridModeToggle vis to mean enabled, effectively
269 source: (gridModeToggle.visible && _launcher.aircraftGridMode) ? "qrc:///qml/AircraftGridView.qml"
270 : "qrc:///qml/AircraftListView.qml"
271
272 anchors {
273 left: parent.left
274 top: tabBarDivider.bottom
275 bottom: parent.bottom
276 right: parent.right
277 topMargin: Style.margin
278 }
279
280 Binding {
281 target: aircraftContent.item
282 property: "model"
283 value: root.__model
284 }
285
286 Binding {
287 target: aircraftContent.item
288 property: "header"
289 value: root.__header
290 }
291
292 Binding {
293 target: aircraftContent.item
294 property: "footer"
295 value: root.__footer
296 }
297
298 Connections {
299 target: aircraftContent.item
300 function onShowDetails(uri) {
301 root.showDetails(uri);
302 }
303 }
304 }
305
306 StyledText {
307 id: noUpdatesMessage
308 anchors {
309 left: parent.left
310 top: tabBar.bottom
311 bottom: parent.bottom
312 right: parent.right
313 }
314 horizontalAlignment: Text.AlignHCenter
315 verticalAlignment: Text.AlignVCenter
316 font.pixelSize: Style.headingFontPixelSize
317 text: qsTr("No aircraft updates available right now")
318 visible: (root.state == "updates") && (_launcher.aircraftWithUpdatesModel.count == 0)
319 }
320
321 states: [
322 State {
323 name: "installed"
324 PropertyChanges {
325 target: root
326 __model: _launcher.installedAircraftModel
327 __header: emptyHeaderFooter
328 __footer: installMoreAircraftFooter
329 }
330
331 PropertyChanges {
332 target: gridModeToggle; visible: true
333 }
334 },
335
336 State {
337 name: "search"
338 PropertyChanges {
339 target: root
340 __model: _launcher.searchAircraftModel
341 __header: searchHeader
342 __footer: emptyHeaderFooter
343 }
344
345 PropertyChanges {
346 target: gridModeToggle; visible: true
347 }
348 },
349
350 State {
351 name: "browse"
352 PropertyChanges {
353 target: root
354 __model: _launcher.browseAircraftModel
355 __header: _addOns.showNoOfficialHangar ? noDefaultCatalogHeader : ratingsHeader
356 __footer: emptyHeaderFooter
357 }
358
359 PropertyChanges {
360 target: gridModeToggle; visible: true
361 }
362 },
363
364 State {
365 name: "updates"
366 PropertyChanges {
367 target: root
368 __model: _launcher.aircraftWithUpdatesModel
369 __header: (_launcher.aircraftWithUpdatesModel.count > 0) ? updateAllHeader : emptyHeaderFooter
370 __footer: emptyHeaderFooter
371 }
372
373 PropertyChanges {
374 target: gridModeToggle; visible: false
375 }
376 },
377
378 State {
379 name: "favourites"
380
381 PropertyChanges {
382 target: root
383 __model: _launcher.favouriteAircraftModel
384 __header: noFavouritesHeader
385 __footer: emptyHeaderFooter
386 }
387
388 PropertyChanges {
389 target: gridModeToggle; visible: true
390 }
391 }
392
393 ]
394
395 function showDetails(uri)
396 {
397 // set URI, start animation
398 // change state
399 detailsView.aircraftURI = uri;
400 detailsView.visible = true
401 }
402
403 function goBack()
404 {
405 // details view can change the aircraft URI / variant
406 updateSelectionFromLauncher();
407 detailsView.visible = false;
408 }
409
410 // we don't want our tips to interfere with the details views
411 GettingStartedTipLayer {
412 id: tipsLayer
413 anchors.fill: parent
414 scopeId: "aircraft"
415 }
416
417 AircraftDetailsView {
418 id: detailsView
419 anchors.fill: parent
420 visible: false
421
422 BackButton {
423 id: backButton
424 anchors { left: parent.left; top: parent.top; margins: Style.margin }
425 onClicked: root.goBack();
426 }
427 }
428
429
430 }