| 1 |
import QtQuick 2.0 |
| 2 |
import QtQuick.Controls 2.2 |
| 3 |
|
| 4 |
import FlightGear.Launcher 1.0 as FG |
| 5 |
|
| 6 |
Item { |
| 7 |
id: root |
| 8 |
|
| 9 |
property alias model: view.model |
| 10 |
property alias header: view.header |
| 11 |
property alias footer: view.footer |
| 12 |
|
| 13 |
signal showDetails(var uri); |
| 14 |
|
| 15 |
function updateSelectionFromLauncher() |
| 16 |
{ |
| 17 |
if (!model) |
| 18 |
return; |
| 19 |
|
| 20 |
var row = model.indexForURI(_launcher.selectedAircraft); |
| 21 |
if (row >= 0) { |
| 22 |
view.currentIndex = row; |
| 23 |
} else { |
| 24 |
// clear selection in view, so we don't show something |
| 25 |
// erroneous such as the previous value |
| 26 |
view.currentIndex = -1; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
onModelChanged: updateSelectionFromLauncher(); |
| 31 |
|
| 32 |
Component { |
| 33 |
id: highlight |
| 34 |
Rectangle { |
| 35 |
gradient: Gradient { |
| 36 |
GradientStop { position: 0.0; color: "#98A3B4" } |
| 37 |
GradientStop { position: 1.0; color: "#5A6B83" } |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
GridView { |
| 43 |
id: view |
| 44 |
cellWidth: width / colCount |
| 45 |
cellHeight: 128 + Style.strutSize |
| 46 |
highlightMoveDuration: 0 |
| 47 |
|
| 48 |
ScrollBar.vertical: ScrollBar {} |
| 49 |
|
| 50 |
readonly property int baseCellWidth: 172 + (Style.strutSize * 2) |
| 51 |
readonly property int colCount: Math.floor(width / baseCellWidth) |
| 52 |
|
| 53 |
anchors { |
| 54 |
left: parent.left |
| 55 |
top: parent.top |
| 56 |
bottom: parent.bottom |
| 57 |
right: parent.right |
| 58 |
topMargin: Style.margin |
| 59 |
} |
| 60 |
|
| 61 |
delegate: AircraftGridDelegate { |
| 62 |
width: view.cellWidth |
| 63 |
height: view.cellHeight |
| 64 |
|
| 65 |
onSelect: { |
| 66 |
view.currentIndex = model.index; |
| 67 |
_launcher.selectedAircraft = uri; |
| 68 |
} |
| 69 |
|
| 70 |
onShowDetails: root.showDetails(uri) |
| 71 |
} |
| 72 |
|
| 73 |
clip: true |
| 74 |
focus: true |
| 75 |
highlight: highlight |
| 76 |
} |
| 77 |
} |