| 1 |
// SPDX-FileCopyrightText: 2018 James Turner |
| 2 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 3 |
|
| 4 |
import QtQuick 2.4 |
| 5 |
import QtQml 2.4 |
| 6 |
import FlightGear 1.0 |
| 7 |
|
| 8 |
Item { |
| 9 |
id: root |
| 10 |
// order of this model sets the order of buttons in the sidebar |
| 11 |
ListModel { |
| 12 |
id: startupPagesModel |
| 13 |
ListElement { title: qsTr("Summary"); pageSource: "qrc:///qml/Summary.qml"; iconPath: "image://colored-icon/toolbox-summary"; state:"loader" } |
| 14 |
ListElement { title: qsTr("Aircraft"); pageSource: "qrc:///qml/AircraftList.qml"; iconPath: "image://colored-icon/toolbox-aircraft"; state:"loader" } |
| 15 |
|
| 16 |
ListElement { |
| 17 |
title: qsTr("Location"); pageSource: "qrc:///qml/Location.qml"; |
| 18 |
iconPath: "image://colored-icon/toolbox-location"; state:"loader" |
| 19 |
buttonDisabled: false |
| 20 |
disabledText: qsTr("Location page disabled due to conflicting user arguments (in Settings)"); |
| 21 |
} |
| 22 |
|
| 23 |
// due to some design stupidity by James, we can't use the Loader mechanism for these pages; they need to exist |
| 24 |
// permanently so that collecting args works. So we instantiate them down below, and toggle the visibility |
| 25 |
// of them and the loader using a state. |
| 26 |
|
| 27 |
ListElement { title: qsTr("Environment"); pageSource: ""; iconPath: "image://colored-icon/toolbox-environment"; state:"environment" } |
| 28 |
ListElement { title: qsTr("Settings"); pageSource: ""; iconPath: "image://colored-icon/toolbox-settings"; state:"settings" } |
| 29 |
|
| 30 |
ListElement { title: qsTr("Add-ons"); pageSource: "qrc:///qml/AddOns.qml"; iconPath: "image://colored-icon/toolbox-addons"; state:"loader" } |
| 31 |
ListElement { title: qsTr("Help"); pageSource: "qrc:///qml/HelpSupport.qml"; iconPath: "image://colored-icon/toolbox-help"; state:"loader" } |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
ListModel { |
| 36 |
id: inAppPagesModel |
| 37 |
ListElement { title: qsTr("Summary"); pageSource: "qrc:///qml/Summary.qml"; iconPath: "image://colored-icon/toolbox-summary"; state:"loader" } |
| 38 |
ListElement { title: qsTr("Aircraft"); pageSource: "qrc:///qml/AircraftList.qml"; iconPath: "image://colored-icon/toolbox-aircraft"; state:"loader" } |
| 39 |
|
| 40 |
ListElement { |
| 41 |
title: qsTr("Location"); pageSource: "qrc:///qml/Location.qml"; |
| 42 |
iconPath: "image://colored-icon/toolbox-location"; state:"loader" |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
Component.onCompleted: |
| 48 |
{ |
| 49 |
_launcher.minimumWindowSize = Qt.size(Style.strutSize * 12, sidebar.minimumHeight); |
| 50 |
|
| 51 |
if (_launcher.versionLaunchCount == 0) { |
| 52 |
popupOverlay.showOverlay(firstRun) |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
Component { |
| 57 |
id: firstRun |
| 58 |
FirstRun { |
| 59 |
width: root.width |
| 60 |
height: root.height |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
Connections { |
| 65 |
target: _location |
| 66 |
function onSkipFromArgsChanged() { |
| 67 |
startupPagesModel.setProperty(2, "buttonDisabled", _location.skipFromArgs); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
Connections { |
| 72 |
target: _launcher |
| 73 |
function onSkipAircraftFromArgsChanged() { |
| 74 |
startupPagesModel.setProperty(1, "buttonDisabled", _launcher.skipAircraftFromArgs); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
state: "loader" |
| 79 |
states: [ |
| 80 |
State { |
| 81 |
name: "loader" |
| 82 |
PropertyChanges { target: pageLoader; visible: true } |
| 83 |
PropertyChanges { target: settings; visible: false } |
| 84 |
PropertyChanges { target: environment; visible: false } |
| 85 |
}, |
| 86 |
|
| 87 |
State { |
| 88 |
name: "settings" |
| 89 |
PropertyChanges { target: pageLoader; visible: false } |
| 90 |
PropertyChanges { target: settings; visible: true } |
| 91 |
PropertyChanges { target: environment; visible: false } |
| 92 |
}, |
| 93 |
|
| 94 |
State { |
| 95 |
name: "environment" |
| 96 |
PropertyChanges { target: pageLoader; visible: false } |
| 97 |
PropertyChanges { target: settings; visible: false } |
| 98 |
PropertyChanges { target: environment; visible: true } |
| 99 |
} |
| 100 |
] |
| 101 |
|
| 102 |
Connections { |
| 103 |
target: _launcher |
| 104 |
function onViewCommandLine() { |
| 105 |
sidebar.selectedPage = -1; |
| 106 |
pageLoader.source = "qrc:///qml/ViewCommandLine.qml" |
| 107 |
root.state = "loader"; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
function enterFlightPlan() |
| 112 |
{ |
| 113 |
sidebar.selectedPage = -1; |
| 114 |
pageLoader.source = "qrc:///qml/FlightPlan.qml" |
| 115 |
root.state = "loader"; |
| 116 |
} |
| 117 |
|
| 118 |
Sidebar { |
| 119 |
id: sidebar |
| 120 |
height: parent.height |
| 121 |
z: 1 |
| 122 |
pagesModel: _launcher.inAppMode ? inAppPagesModel : startupPagesModel |
| 123 |
selectedPage: 0 // open on the summary page |
| 124 |
|
| 125 |
onShowMenu: menu.show(); |
| 126 |
|
| 127 |
onSelectPage: function(pageSource) { |
| 128 |
pageLoader.source = pageSource |
| 129 |
root.state = pagesModel.get(selectedPage).state |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
// background fill |
| 134 |
Rectangle { |
| 135 |
height: parent.height |
| 136 |
anchors { |
| 137 |
left: sidebar.right |
| 138 |
right: parent.right |
| 139 |
} |
| 140 |
color: Style.backgroundColor |
| 141 |
} |
| 142 |
|
| 143 |
Settings { |
| 144 |
id: settings |
| 145 |
|
| 146 |
height: parent.height |
| 147 |
anchors { |
| 148 |
left: sidebar.right |
| 149 |
right: parent.right |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
Environment { |
| 154 |
id: environment |
| 155 |
|
| 156 |
height: parent.height |
| 157 |
anchors { |
| 158 |
left: sidebar.right |
| 159 |
right: parent.right |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
Loader { |
| 164 |
id: pageLoader |
| 165 |
height: parent.height |
| 166 |
anchors { |
| 167 |
left: sidebar.right |
| 168 |
right: parent.right |
| 169 |
} |
| 170 |
|
| 171 |
source: "qrc:///qml/Summary.qml" |
| 172 |
} |
| 173 |
|
| 174 |
NotificationArea { |
| 175 |
id: notifications |
| 176 |
// only show on the summary page |
| 177 |
visible: sidebar.selectedPage === 0 |
| 178 |
|
| 179 |
anchors { |
| 180 |
right: parent.right |
| 181 |
top: parent.top |
| 182 |
bottom: parent.bottom |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
function selectPage(index) |
| 187 |
{ |
| 188 |
sidebar.setSelectedPage(index); |
| 189 |
var page = sidebar.pagesModel.get(index); |
| 190 |
pageLoader.source = page.pageSource |
| 191 |
root.state = page.state |
| 192 |
} |
| 193 |
|
| 194 |
Connections { |
| 195 |
target: pageLoader.item |
| 196 |
ignoreUnknownSignals: true |
| 197 |
function onShowSelectedAircraft() { root.selectPage(1); } |
| 198 |
function onShowSelectedLocation() { root.selectPage(2); } |
| 199 |
function onShowFlightPlan() { root.enterFlightPlan(); } |
| 200 |
} |
| 201 |
|
| 202 |
Menu { |
| 203 |
id: menu |
| 204 |
z: 100 |
| 205 |
|
| 206 |
items: [ |
| 207 |
MenuItem { |
| 208 |
text:qsTr("Fly!") |
| 209 |
shortcut: "Ctrl+F" |
| 210 |
enabled: _launcher.canFly |
| 211 |
onTriggered: _launcher.fly() |
| 212 |
}, |
| 213 |
|
| 214 |
MenuItem { text:qsTr("Open saved configuration..."); shortcut: "Ctrl+O"; |
| 215 |
onTriggered: _launcher.openConfig(); }, |
| 216 |
MenuItem { text:qsTr("Save configuration as..."); shortcut: "Ctrl+S"; |
| 217 |
onTriggered: _launcher.saveConfigAs(); }, |
| 218 |
MenuDivider {}, |
| 219 |
MenuItem { text:qsTr("Flight-planning"); onTriggered: root.enterFlightPlan(); shortcut: "Ctrl+P"; enabled: true}, |
| 220 |
MenuDivider {}, |
| 221 |
MenuItem { text:qsTr("View command line"); onTriggered: _launcher.viewCommandLine(); shortcut: "Ctrl+L"}, |
| 222 |
MenuItem { text:qsTr("Select data files location..."); onTriggered: _launcher.requestChangeDataPath(); }, |
| 223 |
MenuItem { text:qsTr("Restore default settings..."); onTriggered: _launcher.requestRestoreDefaults(); }, |
| 224 |
MenuDivider {}, |
| 225 |
MenuItem { text:qsTr("Quit"); shortcut: "Ctrl+Q"; onTriggered: _launcher.quit(); } |
| 226 |
] |
| 227 |
} |
| 228 |
|
| 229 |
Overlay { |
| 230 |
id: popupOverlay |
| 231 |
anchors.fill: parent |
| 232 |
z: 200 |
| 233 |
|
| 234 |
Component.onCompleted: { |
| 235 |
OverlayShared.globalOverlay = this |
| 236 |
} |
| 237 |
} |
| 238 |
} |