| 1 |
import QtQuick 2.4 |
| 2 |
import QtQuick.Controls 2.2 |
| 3 |
|
| 4 |
import FlightGear 1.0 |
| 5 |
import FlightGear.Launcher 1.0 |
| 6 |
|
| 7 |
Item { |
| 8 |
id: root |
| 9 |
|
| 10 |
property bool __searchActive: false |
| 11 |
property string lastSearch |
| 12 |
|
| 13 |
property bool showCarriers: false |
| 14 |
readonly property var locationModel: showCarriers ? _location.carriersModel : _location.searchModel |
| 15 |
GettingStartedScope.controller: tips.controller |
| 16 |
|
| 17 |
function backToSearch() |
| 18 |
{ |
| 19 |
detailLoader.sourceComponent = null |
| 20 |
if (!_location.searchModel.haveExistingSearch) { |
| 21 |
_location.showHistoryInSearchModel(); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
function selectLocation(guid, type) |
| 26 |
{ |
| 27 |
selectedLocation.guid = guid; |
| 28 |
_location.setBaseLocation(selectedLocation) |
| 29 |
_location.addToRecent(selectedLocation); |
| 30 |
|
| 31 |
if (selectedLocation.isAirportType) { |
| 32 |
// default to using the active runway when making a selection |
| 33 |
// via the GUI |
| 34 |
_location.useActiveRunway = true |
| 35 |
detailLoader.sourceComponent = airportDetails |
| 36 |
} else { |
| 37 |
detailLoader.sourceComponent = navaidDetails |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
function selectCarrier(name) |
| 42 |
{ |
| 43 |
selectedLocation.guid = 0; |
| 44 |
_location.carrier = name; |
| 45 |
detailLoader.sourceComponent = carrierDetails |
| 46 |
} |
| 47 |
|
| 48 |
Component.onCompleted: { |
| 49 |
// important so we can leave the location page and return to it, |
| 50 |
// preserving the state |
| 51 |
if (_location.base.valid) { |
| 52 |
selectedLocation.guid = _location.base.guid; |
| 53 |
|
| 54 |
if (selectedLocation.isAirportType) { |
| 55 |
detailLoader.sourceComponent = airportDetails |
| 56 |
} else { |
| 57 |
detailLoader.sourceComponent = navaidDetails |
| 58 |
} |
| 59 |
} else if (_location.isBaseLatLon) { |
| 60 |
detailLoader.sourceComponent = navaidDetails |
| 61 |
} else if (_location.isCarrier) { |
| 62 |
detailLoader.sourceComponent = carrierDetails; |
| 63 |
} else { |
| 64 |
_location.showHistoryInSearchModel(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
Positioned { |
| 69 |
id: selectedLocation |
| 70 |
} |
| 71 |
|
| 72 |
Component { |
| 73 |
id: airportDetails |
| 74 |
LocationAirportView { |
| 75 |
id: airportView |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
Component { |
| 80 |
id: navaidDetails |
| 81 |
LocationNavaidView { |
| 82 |
id: navaidView |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
Component { |
| 87 |
id: carrierDetails |
| 88 |
LocationCarrierView { |
| 89 |
id: carrierView |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
Rectangle { |
| 94 |
anchors.fill: parent |
| 95 |
color: Style.backgroundColor |
| 96 |
} |
| 97 |
|
| 98 |
Component { |
| 99 |
id: locationSearchDelegate |
| 100 |
Rectangle { |
| 101 |
id: delegateRoot |
| 102 |
height: delegateContent.height + Style.margin |
| 103 |
width: searchView.width |
| 104 |
color: Style.backgroundColor |
| 105 |
|
| 106 |
function itemDescription() |
| 107 |
{ |
| 108 |
if (model.type === Positioned.Fix) return model.ident |
| 109 |
|
| 110 |
if (model.type === Positioned.VOR) { |
| 111 |
var freq = (model.frequency / 100).toFixed(3); |
| 112 |
return "%1 - %2 (%3 MHz)".arg(model.ident).arg(model.name).arg(freq); |
| 113 |
} |
| 114 |
|
| 115 |
if (model.type === "Carrier") { |
| 116 |
return "%1 - %2\n%3".arg(model.ident).arg(model.name).arg(model.description); |
| 117 |
} |
| 118 |
|
| 119 |
// general case |
| 120 |
return "%1 - %2".arg(model.ident).arg(model.name); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
Item { |
| 125 |
id: delegateContent |
| 126 |
height: Math.max(delegateIcon.height, delegateText.height) |
| 127 |
width: parent.width |
| 128 |
|
| 129 |
// Rectangle { |
| 130 |
// visible: delegateMouse.containsMouse |
| 131 |
// color: "#cfcfcf" |
| 132 |
// } |
| 133 |
|
| 134 |
PixmapImage { |
| 135 |
id: delegateIcon |
| 136 |
anchors.left: parent.left |
| 137 |
anchors.leftMargin: Style.margin |
| 138 |
anchors.verticalCenter: parent.verticalCenter |
| 139 |
image: model.icon |
| 140 |
} |
| 141 |
|
| 142 |
StyledText { |
| 143 |
id: delegateText |
| 144 |
anchors.right: parent.right |
| 145 |
anchors.left: delegateIcon.right |
| 146 |
anchors.rightMargin: Style.margin |
| 147 |
anchors.leftMargin: Style.margin |
| 148 |
anchors.verticalCenter: parent.verticalCenter |
| 149 |
text: delegateRoot.itemDescription(); |
| 150 |
wrapMode: Text.WordWrap |
| 151 |
} |
| 152 |
|
| 153 |
MouseArea { |
| 154 |
id: delegateMouse |
| 155 |
anchors.fill: parent |
| 156 |
hoverEnabled: true |
| 157 |
onClicked: { |
| 158 |
if (root.showCarriers) { |
| 159 |
root.selectCarrier(model.name); |
| 160 |
} else { |
| 161 |
root.selectLocation(model.guid, model.type); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
Item { |
| 168 |
id: footer |
| 169 |
height: Style.margin |
| 170 |
width: parent.width |
| 171 |
anchors.bottom: parent.bottom |
| 172 |
|
| 173 |
Rectangle { |
| 174 |
color: Style.frameColor |
| 175 |
height: 1 |
| 176 |
width: parent.width - Style.strutSize |
| 177 |
anchors.centerIn: parent |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
StyledText { |
| 184 |
id: headerText |
| 185 |
text: qsTr("Location") |
| 186 |
font.pixelSize: Style.headingFontPixelSize |
| 187 |
anchors.left: parent.left |
| 188 |
anchors.leftMargin: Style.inset |
| 189 |
anchors.top: parent.top |
| 190 |
anchors.topMargin: Style.margin |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
SearchButton { |
| 196 |
id: searchButton |
| 197 |
|
| 198 |
anchors.right: carriersButton.left |
| 199 |
anchors.top: headerText.bottom |
| 200 |
anchors.left: parent.left |
| 201 |
anchors.margins: Style.margin |
| 202 |
|
| 203 |
autoSubmit: false |
| 204 |
placeholder: qsTr("Search for an airport or navaid"); |
| 205 |
|
| 206 |
onSearch: function(term) { |
| 207 |
root.showCarriers = false; |
| 208 |
// when the search term is cleared, show the history |
| 209 |
if (term == "") { |
| 210 |
_location.showHistoryInSearchModel(); |
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
var geod = _location.parseStringAsGeod(term) |
| 215 |
if (geod.valid) { |
| 216 |
_location.baseGeod = geod |
| 217 |
selectedLocation.guid = 0; |
| 218 |
detailLoader.sourceComponent = navaidDetails |
| 219 |
return; |
| 220 |
} |
| 221 |
|
| 222 |
root.lastSearch = term; |
| 223 |
_location.searchModel.setSearch(term, _launcher.aircraftType) |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
IconButton { |
| 228 |
id: carriersButton |
| 229 |
anchors.top: headerText.bottom |
| 230 |
anchors.right: parent.right |
| 231 |
anchors.margins: Style.margin |
| 232 |
icon: root.showCarriers ? "image://colored-icon/carrier2?text" |
| 233 |
: "image://colored-icon/airport?text" |
| 234 |
|
| 235 |
onClicked: root.showCarriers = ! root.showCarriers; |
| 236 |
|
| 237 |
GettingStartedTip { |
| 238 |
tipId: "locationCarriersList" |
| 239 |
|
| 240 |
anchors { |
| 241 |
horizontalCenter: parent.horizontalCenter |
| 242 |
horizontalCenterOffset: -Style.margin |
| 243 |
top: parent.bottom |
| 244 |
} |
| 245 |
arrow: GettingStartedTip.TopRight |
| 246 |
text: qsTr("View available aircraft carriers to start at.") |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
StyledText { |
| 251 |
id: searchHelpText |
| 252 |
anchors.right: parent.right |
| 253 |
anchors.top: searchButton.bottom |
| 254 |
anchors.left: parent.left |
| 255 |
anchors.margins: Style.margin |
| 256 |
wrapMode: Text.WordWrap |
| 257 |
|
| 258 |
text: qsTr("Enter the name, partial name or ident of a navaid or fix, or an " + |
| 259 |
"airport name or ICAO identifier. Alternatively, enter a latitude & longitude: for " + |
| 260 |
"example 53.4,-3.4 or 18.4S, 87.23W") |
| 261 |
} |
| 262 |
|
| 263 |
Rectangle { |
| 264 |
id: headerSplit |
| 265 |
color: Style.frameColor |
| 266 |
height: 1 |
| 267 |
width: parent.width - Style.inset |
| 268 |
anchors.horizontalCenter: parent.horizontalCenter |
| 269 |
anchors.top: searchHelpText.bottom |
| 270 |
anchors.topMargin: Style.margin |
| 271 |
} |
| 272 |
|
| 273 |
ListView { |
| 274 |
id: searchView |
| 275 |
anchors.top: headerSplit.bottom |
| 276 |
anchors.topMargin: Style.margin |
| 277 |
width: parent.width |
| 278 |
anchors.bottom: parent.bottom |
| 279 |
model: root.locationModel |
| 280 |
delegate: locationSearchDelegate |
| 281 |
clip: true |
| 282 |
ScrollBar.vertical: ScrollBar {} |
| 283 |
|
| 284 |
header: Item { |
| 285 |
visible: !root.showCarriers && _location.searchModel.isSearchActive |
| 286 |
width: parent.width |
| 287 |
height: visible ? 50 : 0 |
| 288 |
|
| 289 |
Text { |
| 290 |
text: qsTr("Searching") |
| 291 |
anchors.verticalCenter: parent.verticalCenter |
| 292 |
anchors.right: parent.horizontalCenter |
| 293 |
} |
| 294 |
|
| 295 |
AnimatedImage { |
| 296 |
source: "qrc:///linear-spinner" |
| 297 |
anchors.verticalCenter: parent.verticalCenter |
| 298 |
anchors.left: parent.horizontalCenter |
| 299 |
} |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
footer: Item { |
| 304 |
width: parent.width |
| 305 |
height: noResultsText.height |
| 306 |
visible: !root.showCarriers && (parent.count === 0) && !_location.searchModel.isSearchActive |
| 307 |
Text { |
| 308 |
id: noResultsText |
| 309 |
width: parent.width |
| 310 |
text: qsTr("No results for found search '%1'").arg(root.lastSearch) |
| 311 |
wrapMode: Text.WordWrap |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
GettingStartedTipLayer { |
| 317 |
id: tips |
| 318 |
anchors.fill: parent |
| 319 |
scopeId: "location" |
| 320 |
} |
| 321 |
|
| 322 |
// scrollbar |
| 323 |
|
| 324 |
Loader { |
| 325 |
id: detailLoader |
| 326 |
anchors.fill: parent |
| 327 |
visible: sourceComponent != null |
| 328 |
|
| 329 |
onStatusChanged: { |
| 330 |
if (status == Loader.Ready) { |
| 331 |
if (selectedLocation.valid) { |
| 332 |
item.location = selectedLocation.guid |
| 333 |
} else { |
| 334 |
// lon-lat |
| 335 |
item.geod = _location.baseGeod |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
BackButton { |
| 342 |
id: backButton |
| 343 |
anchors { left: parent.left; top: parent.top; margins: Style.margin } |
| 344 |
visible: detailLoader.visible |
| 345 |
onClicked: root.backToSearch(); |
| 346 |
} |
| 347 |
} |