Debian Codegraph @

src/GUI/qml/AircraftListView.qml

raw
1 // SPDX-FileCopyrightText: 2018 James Turner
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 import QtQuick 2.0
5 import QtQuick.Controls 2.2
6 import FlightGear.Launcher 1.0 as FG
7 import FlightGear 1.0
8
9 Item {
10 id: root
11
12 property alias model: aircraftList.model
13 property alias header: aircraftList.header
14 property alias footer: aircraftList.footer
15
16 signal showDetails(var uri);
17
18 function updateSelectionFromLauncher()
19 {
20 if (!model)
21 return;
22
23 model.selectVariantForAircraftURI(_launcher.selectedAircraft);
24 var row = model.indexForURI(_launcher.selectedAircraft);
25 if (row >= 0) {
26 // sequence here is necessary so programmatic moves
27 // are instant
28 aircraftList.highlightMoveDuration = 0;
29 aircraftList.currentIndex = row;
30 aircraftList.highlightMoveDuration = aircraftList.__realHighlightMoveDuration;
31 } else {
32 // clear selection in view, so we don't show something
33 // erroneous such as the previous value
34 aircraftList.currentIndex = -1;
35 }
36 }
37
38 onModelChanged: updateSelectionFromLauncher()
39
40 Component {
41 id: highlight
42 Rectangle {
43 gradient: Gradient {
44 GradientStop { position: 0.0; color: "#98A3B4" }
45 GradientStop { position: 1.0; color: "#5A6B83" }
46 }
47 }
48 }
49
50 ListView {
51 id: aircraftList
52 ScrollBar.vertical: ScrollBar {}
53
54 anchors {
55 left: parent.left
56 top: parent.top
57 bottom: parent.bottom
58 right: parent.right
59 topMargin: Style.margin
60 }
61
62 delegate: AircraftCompactDelegate {
63 onSelect: function(uri) {
64 aircraftList.currentIndex = model.index;
65 _launcher.selectedAircraft = uri;
66 }
67
68 onShowDetails: function(uri) {
69 root.showDetails(uri);
70 }
71 }
72
73 spacing: 0
74
75 clip: true
76 focus: true
77
78 highlight: highlight
79 highlightMoveDuration: __realHighlightMoveDuration
80
81 // saved here because we need to reset highlightMoveDuration
82 // when doing a programmatic set
83 readonly property int __realHighlightMoveDuration: 200
84 }
85 }