Warning, /utilities/kirogi/src/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2019 Eike Hein <hein@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public License as 0006 * published by the Free Software Foundation; either version 2 of 0007 * the License or (at your option) version 3 or any later version 0008 * accepted by the membership of KDE e.V. (or its successor approved 0009 * by the membership of KDE e.V.), which shall act as a proxy 0010 * defined in Section 14 of version 3 of the license. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 import QtQuick 2.12 0022 import QtQuick.Layouts 1.12 0023 import QtQuick.Controls 2.12 as QQC2 0024 import QtPositioning 5.12 0025 0026 import org.kde.kirigami 2.20 as Kirigami 0027 import org.kde.kirigamiaddons.formcard 1.0 as FormCard 0028 0029 import org.kde.kirogi 0.1 as Kirogi 0030 0031 Kirigami.ApplicationWindow { 0032 id: kirogi 0033 0034 width: 800 0035 height: 450 0036 0037 property QtObject currentVehicle: null 0038 readonly property bool connected: currentVehicle && currentVehicle.connected 0039 readonly property bool ready: currentVehicle && currentVehicle.ready 0040 readonly property bool flying: currentVehicle && currentVehicle.flying 0041 0042 property var currentPage: pageStack.currentItem 0043 property alias currentPlugin: pluginModel.currentPlugin 0044 property alias currentPluginName: pluginModel.currentPluginName 0045 0046 readonly property var position: Kirogi.PositionSource.coordinate 0047 readonly property real distance: { 0048 if (!position || !position.isValid) { 0049 return 0.0; 0050 } 0051 0052 // If currentVehicle is null or there is no valid position 0053 // set distance to zero. 0054 if (!currentVehicle || !currentVehicle.gpsPosition.isValid) { 0055 return 0.0; 0056 } 0057 0058 return position.distanceTo(currentVehicle.gpsPosition); 0059 } 0060 0061 onPositionChanged: { 0062 // Position via internet IP does not provide a valid altitude. 0063 if (position.isValid && currentVehicle) { 0064 currentVehicle.setControllerGpsPosition(position) 0065 } 0066 } 0067 0068 pageStack.interactive: false 0069 pageStack.defaultColumnWidth: width 0070 pageStack.globalToolBar.style: Kirigami.ApplicationHeaderStyle.None 0071 0072 globalDrawer: Kirigami.GlobalDrawer { 0073 title: i18n("Kirogi") 0074 titleIcon: "kirogi" 0075 0076 width: Kirigami.Units.gridUnit * 14 0077 0078 actions: [ 0079 Kirigami.Action { 0080 id: vehiclePageAction 0081 0082 checked: currentPage == vehiclePage 0083 0084 iconName: "uav-quadcopter" 0085 text: i18n("Drone") 0086 0087 tooltip: "Alt+1" 0088 shortcut: tooltip 0089 0090 onTriggered: switchApplicationPage(vehiclePage) 0091 }, 0092 Kirigami.Action { 0093 id: flightControlsPageAction 0094 0095 checked: currentPage == flightControlsPage 0096 0097 iconName: "transform-move" 0098 text: i18n("Flight Controls") 0099 0100 tooltip: "Alt+2" 0101 shortcut: tooltip 0102 0103 onTriggered: switchApplicationPage(flightControlsPage) 0104 }, 0105 Kirigami.Action { 0106 id: navigationMapPageAction 0107 0108 checked: currentPage == navigationMapPage 0109 0110 iconName: "map-flat" 0111 text: i18n("Navigation Map") 0112 0113 tooltip: "Alt+3" 0114 shortcut: tooltip 0115 0116 onTriggered: switchApplicationPage(navigationMapPage) 0117 }, 0118 Kirigami.Action { 0119 id: settingsPageAction 0120 0121 checked: currentPage == settingsPage 0122 0123 iconName: "configure" 0124 text: i18n("Settings") 0125 0126 tooltip: "Alt+4" 0127 shortcut: tooltip 0128 0129 onTriggered: switchApplicationPage(settingsPage) 0130 }, 0131 Kirigami.Action { 0132 id: aboutPageAction 0133 0134 checked: currentPage == aboutPage 0135 0136 iconName: "help-about" 0137 text: i18n("About") 0138 0139 tooltip: "Alt+5" 0140 shortcut: tooltip 0141 0142 onTriggered: pageStack.pushDialogLayer(aboutPage) 0143 } 0144 ] 0145 } 0146 0147 onConnectedChanged: { 0148 if (connected && kirogiSettings.allowLocationRequests && !locationPermissions.granted) { 0149 locationPermissions.request(); 0150 } 0151 } 0152 0153 onFlyingChanged: { 0154 kirogiSettings.flying = flying; 0155 } 0156 0157 function switchApplicationPage(page) { 0158 if (!page || currentPage == page) { 0159 return; 0160 } 0161 0162 pageStack.removePage(page); 0163 pageStack.push(page); 0164 page.forceActiveFocus(); 0165 } 0166 0167 Kirogi.VehicleSupportPluginModel { 0168 id: pluginModel 0169 0170 property QtObject currentPlugin: null 0171 property string currentPluginName: "" 0172 0173 onPluginLoaded: { 0174 kirogiSettings.lastPlugin = pluginId; 0175 currentPluginName = name; 0176 currentPlugin = plugin; 0177 } 0178 0179 Component.onCompleted: { 0180 if (kirogiSettings.lastPlugin) { 0181 loadPluginById(kirogiSettings.lastPlugin); 0182 } 0183 } 0184 } 0185 0186 Connections { 0187 target: currentPlugin 0188 0189 onVehicleAdded: { 0190 currentVehicle = vehicle; 0191 } 0192 } 0193 0194 FontMetrics { 0195 id: fontMetrics 0196 } 0197 0198 Vehicle { 0199 id: vehiclePage 0200 0201 enabled: currentPage == vehiclePage 0202 visible: enabled 0203 } 0204 0205 FlightControls { 0206 id: flightControlsPage 0207 0208 enabled: currentPage == flightControlsPage 0209 visible: enabled 0210 } 0211 0212 NavigationMap { 0213 id: navigationMapPage 0214 0215 enabled: currentPage == navigationMapPage 0216 visible: enabled 0217 } 0218 0219 Settings { 0220 id: settingsPage 0221 0222 enabled: currentPage == settingsPage 0223 visible: enabled 0224 } 0225 0226 Component { 0227 id: aboutPage 0228 FormCard.AboutPage { 0229 id: aboutPage 0230 aboutData: kirogiAboutData 0231 } 0232 } 0233 0234 Timer { 0235 id: resetPersistentFlyingStateTimer 0236 0237 interval: 3000 0238 repeat: false 0239 0240 onTriggered: { 0241 kirogiSettings.flying = flying; 0242 } 0243 } 0244 0245 Component.onCompleted: { 0246 switchApplicationPage(kirogiSettings.flying ? flightControlsPage : vehiclePage); 0247 resetPersistentFlyingStateTimer.start(); 0248 Kirogi.PositionSource.enabled = Qt.binding(function() { return kirogiSettings.allowLocationRequests && locationPermissions.granted }); 0249 } 0250 }