Warning, /utilities/kirogi/src/ui/Vehicle.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 0025 import org.kde.kirigami 2.6 as Kirigami 0026 0027 import org.kde.kirogi 0.1 as Kirogi 0028 0029 Kirigami.Page { 0030 id: page 0031 0032 leftPadding: 0 0033 rightPadding: 0 0034 topPadding: 0 0035 bottomPadding: 0 0036 0037 Image { 0038 anchors.left: parent.left 0039 anchors.leftMargin: (((LayoutMirroring.enabled ? (parent.width - flightChecklist.x - flightChecklist.width) : flightChecklist.x) / 2) - (width / 2)) 0040 anchors.verticalCenter: parent.verticalCenter 0041 0042 width: height 0043 height: Math.min(parent.height, LayoutMirroring.enabled ? (parent.width - flightChecklist.x - flightChecklist.width) : flightChecklist.x) * 0.94 0044 0045 fillMode: Image.PreserveAspectFit 0046 smooth: true 0047 0048 source: "goose.webp" 0049 0050 asynchronous: true 0051 } 0052 0053 Component { 0054 id: pluginItemComponent 0055 0056 Kirigami.BasicListItem { 0057 id: pluginItem 0058 0059 height: Math.max(implicitHeight, Kirigami.Units.iconSizes.medium) 0060 0061 supportsMouseEvents: model.status == Kirogi.VehicleSupportPluginModel.PluginNotLoaded 0062 0063 reserveSpaceForIcon: kirogi.currentPlugin 0064 icon: model.status == Kirogi.VehicleSupportPluginModel.PluginLoaded ? "emblem-default-symbolic" : "" 0065 0066 label: model.display 0067 0068 onClicked: { 0069 pluginSheet.sheetOpen = false; 0070 pluginModel.unloadAllPlugins(); 0071 pluginModel.loadPluginByIndex(index); 0072 } 0073 } 0074 } 0075 0076 Kirigami.OverlaySheet { 0077 id: pluginSheet 0078 0079 parent: kirogi 0080 0081 topPadding: 0 0082 leftPadding: 0 0083 rightPadding: 0 0084 bottomPadding: 0 0085 0086 header: Kirigami.Heading { text: i18nc("@title:window", "Select Model") } 0087 0088 ListView { 0089 id: pluginList 0090 0091 implicitWidth: 18 * Kirigami.Units.gridUnit 0092 0093 model: pluginSheet.sheetOpen ? pluginModel : null 0094 0095 delegate: Kirigami.DelegateRecycler { 0096 width: parent.width 0097 0098 sourceComponent: pluginItemComponent 0099 } 0100 } 0101 } 0102 0103 Kirigami.AbstractCard { 0104 id: flightChecklist 0105 0106 width: (page.width / 3) + (Kirigami.Units.gridUnit * 2) 0107 0108 implicitHeight: height // FIXME TODO Silence Kirigami warning. 0109 0110 anchors.right: parent.right 0111 anchors.rightMargin: Kirigami.Units.gridUnit 0112 anchors.top: parent.top 0113 anchors.topMargin: Kirigami.Units.gridUnit 0114 anchors.bottom: parent.bottom 0115 anchors.bottomMargin: Kirigami.Units.gridUnit 0116 0117 topPadding: Kirigami.Settings.isMobile ? header.height * 0.5 : header.height 0118 0119 header: Kirigami.Heading { 0120 text: i18n("Flight Checklist") 0121 level: 1 0122 horizontalAlignment: Text.AlignHCenter 0123 elide: Text.ElideRight 0124 } 0125 0126 contentItem: QQC2.ScrollView { 0127 id: checksList 0128 0129 clip: true 0130 0131 property int scrollBarWidth: QQC2.ScrollBar.vertical && QQC2.ScrollBar.vertical.visible 0132 ? QQC2.ScrollBar.vertical.width : 0 0133 0134 Column { 0135 id: col 0136 0137 width: checksList.width - checksList.scrollBarWidth 0138 height: implicitHeight 0139 0140 Kirigami.BasicListItem { 0141 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0142 0143 supportsMouseEvents: false 0144 separatorVisible: !Kirigami.Settings.isMobile 0145 0146 contentItem: RowLayout { 0147 Kirigami.Icon { 0148 Layout.alignment: Qt.AlignVCenter 0149 0150 width: Kirigami.Units.iconSizes.medium 0151 height: width 0152 0153 source: kirogi.currentPlugin ? "emblem-default-symbolic" : "emblem-important-symbolic" 0154 color: kirogi.currentPlugin ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.negativeTextColor 0155 } 0156 0157 QQC2.Label { 0158 Layout.fillWidth: true 0159 0160 Layout.alignment: Qt.AlignVCenter 0161 0162 text: i18n("<b>Model:</b> %1", kirogi.currentPlugin ? kirogi.currentPluginName : i18n("Select now")) 0163 color: kirogi.currentPlugin ? Kirigami.Theme.textColor : Kirigami.Theme.negativeTextColor 0164 0165 elide: Text.ElideRight 0166 } 0167 0168 QQC2.ToolButton { 0169 Layout.alignment: Qt.AlignVCenter 0170 0171 implicitWidth: Kirigami.Units.iconSizes.medium 0172 implicitHeight: implicitWidth 0173 0174 icon.name: "configure" 0175 0176 onClicked: pluginSheet.sheetOpen = !pluginSheet.sheetOpen 0177 0178 QQC2.ToolTip.visible: modelButtonHoverHandler.hovered 0179 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0180 QQC2.ToolTip.text: i18n("Select Model") 0181 0182 HoverHandler { 0183 id: modelButtonHoverHandler 0184 } 0185 } 0186 } 0187 } 0188 0189 Kirigami.BasicListItem { 0190 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0191 0192 supportsMouseEvents: false 0193 separatorVisible: !Kirigami.Settings.isMobile 0194 0195 contentItem: RowLayout { 0196 Kirigami.Icon { 0197 visible: !kirogi.currentPlugin || kirogi.currentPlugin && kirogi.currentVehicle 0198 0199 Layout.alignment: Qt.AlignVCenter 0200 0201 width: Kirigami.Units.iconSizes.medium 0202 height: width 0203 0204 source: kirogi.currentVehicle ? "emblem-default-symbolic" : "question" 0205 color: kirogi.currentVehicle ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.disabledTextColor 0206 } 0207 0208 QQC2.BusyIndicator { 0209 visible: kirogi.currentPlugin && !kirogi.currentVehicle 0210 0211 Layout.alignment: Qt.AlignVCenter 0212 0213 implicitWidth: Kirigami.Units.iconSizes.medium 0214 implicitHeight: implicitWidth 0215 0216 topPadding: 0 0217 bottomPadding: 0 0218 leftPadding: 0 0219 rightPadding: 0 0220 0221 running: visible 0222 } 0223 0224 QQC2.Label { 0225 Layout.fillWidth: true 0226 0227 Layout.alignment: Qt.AlignVCenter 0228 0229 text: { 0230 var state = i18n("N/A"); 0231 0232 if (kirogi.currentPlugin) { 0233 state = i18n("Searching ..."); 0234 } 0235 0236 return i18n("<b>Drone:</b> %1", kirogi.currentVehicle ? kirogi.currentVehicle.name : state); 0237 } 0238 0239 color: kirogi.currentPlugin ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0240 0241 elide: Text.ElideRight 0242 } 0243 } 0244 } 0245 0246 Kirigami.BasicListItem { 0247 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0248 0249 supportsMouseEvents: false 0250 separatorVisible: !Kirigami.Settings.isMobile 0251 0252 contentItem: RowLayout { 0253 Kirigami.Icon { 0254 visible: !kirogi.currentVehicle || kirogi.ready 0255 0256 Layout.alignment: Qt.AlignVCenter 0257 0258 width: Kirigami.Units.iconSizes.medium 0259 height: width 0260 0261 source: kirogi.currentVehicle ? "emblem-default-symbolic" : "question" 0262 color: kirogi.currentVehicle ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.disabledTextColor 0263 } 0264 0265 QQC2.BusyIndicator { 0266 visible: kirogi.currentVehicle && !kirogi.ready 0267 0268 Layout.alignment: Qt.AlignVCenter 0269 0270 implicitWidth: Kirigami.Units.iconSizes.medium 0271 implicitHeight: implicitWidth 0272 0273 topPadding: 0 0274 bottomPadding: 0 0275 leftPadding: 0 0276 rightPadding: 0 0277 0278 running: visible 0279 } 0280 0281 QQC2.Label { 0282 Layout.fillWidth: true 0283 0284 Layout.alignment: Qt.AlignVCenter 0285 0286 text: { 0287 var state = "N/A"; 0288 0289 if (kirogi.flying) { 0290 state = i18n("Flying"); 0291 } else if (kirogi.ready) { 0292 state = i18n("Ready"); 0293 } else if (kirogi.connected) { 0294 state = i18n("Preparing ..."); 0295 } else if (kirogi.currentVehicle && (kirogi.currentVehicle.connectionState == Kirogi.AbstractVehicle.Connecting 0296 || kirogi.currentVehicle.connectionState == Kirogi.AbstractVehicle.Disconnected)) { 0297 state = i18n("Connecting ..."); 0298 } 0299 0300 i18n("<b>Status:</b> %1", state); 0301 } 0302 0303 color: kirogi.currentVehicle ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0304 0305 elide: Text.ElideRight 0306 } 0307 } 0308 } 0309 0310 Kirigami.BasicListItem { 0311 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0312 0313 supportsMouseEvents: false 0314 separatorVisible: !Kirigami.Settings.isMobile 0315 0316 contentItem: RowLayout { 0317 Kirigami.Icon { 0318 Layout.alignment: Qt.AlignVCenter 0319 0320 width: Kirigami.Units.iconSizes.medium 0321 height: width 0322 0323 source: { 0324 if (kirogi.currentVehicle) { 0325 if (kirogi.currentVehicle.signalStrength === 0) { 0326 return "network-wireless-connected-00"; 0327 } else if (kirogi.currentVehicle.signalStrength < 25) { 0328 return "network-wireless-connected-25"; 0329 } else if (kirogi.currentVehicle.signalStrength < 50) { 0330 return "network-wireless-connected-50"; 0331 } else if (kirogi.currentVehicle.signalStrength < 75) { 0332 return "network-wireless-connected-75"; 0333 } else if (kirogi.currentVehicle.signalStrength <= 100) { 0334 return "network-wireless-connected-100"; 0335 } 0336 } 0337 0338 if (kirogi.connected) { 0339 return "network-wireless-acquiring"; 0340 } 0341 0342 return "network-wireless-disconnected"; 0343 } 0344 0345 color: kirogi.currentVehicle ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0346 } 0347 0348 QQC2.Label { 0349 Layout.fillWidth: true 0350 0351 Layout.alignment: Qt.AlignVCenter 0352 0353 text: { 0354 var state = kirogi.currentVehicle ? i18n("%1%", kirogi.currentVehicle.signalStrength) : i18n("N/A"); 0355 return i18n("<b>Signal:</b> %1", state); 0356 } 0357 0358 color: kirogi.connected ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0359 0360 elide: Text.ElideRight 0361 } 0362 } 0363 } 0364 0365 Kirigami.BasicListItem { 0366 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0367 0368 supportsMouseEvents: false 0369 separatorVisible: !Kirigami.Settings.isMobile 0370 0371 contentItem: RowLayout { 0372 Kirigami.Icon { 0373 Layout.alignment: Qt.AlignVCenter 0374 0375 width: Kirigami.Units.iconSizes.medium 0376 height: width 0377 0378 source: { 0379 if (kirogi.currentVehicle) { 0380 var roundedBatteryLevel = Math.round(kirogi.currentVehicle.batteryLevel / 10); 0381 return "battery-" + roundedBatteryLevel.toString().padStart(2, "0") + "0"; 0382 } 0383 0384 return "battery-missing"; 0385 } 0386 0387 color: kirogi.currentVehicle ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0388 } 0389 0390 QQC2.Label { 0391 Layout.fillWidth: true 0392 0393 Layout.alignment: Qt.AlignVCenter 0394 0395 text: { 0396 var state = kirogi.currentVehicle ? i18n("%1%", kirogi.currentVehicle.batteryLevel) : i18n("N/A"); 0397 return i18n("<b>Battery:</b> %1", state); 0398 } 0399 0400 color: kirogi.connected ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0401 0402 elide: Text.ElideRight 0403 } 0404 } 0405 } 0406 0407 Kirigami.BasicListItem { 0408 implicitHeight: Kirigami.Units.iconSizes.medium + (Kirigami.Units.smallSpacing * 2) 0409 0410 supportsMouseEvents: false 0411 separatorVisible: !Kirigami.Settings.isMobile 0412 0413 contentItem: RowLayout { 0414 Kirigami.Icon { 0415 Layout.alignment: Qt.AlignVCenter 0416 0417 width: Kirigami.Units.iconSizes.medium 0418 height: width 0419 0420 source: "gps" 0421 0422 color: { 0423 if (kirogi.connected) { 0424 if (kirogi.currentVehicle.gpsFix) { 0425 return Kirigami.Theme.positiveTextColor; 0426 } else if (kirogi.currentVehicle.gpsSupported) { 0427 return Kirigami.Theme.negativeTextColor; 0428 } 0429 } 0430 0431 return Kirigami.Theme.disabledTextColor; 0432 } 0433 } 0434 0435 QQC2.Label { 0436 Layout.fillWidth: true 0437 0438 Layout.alignment: Qt.AlignVCenter 0439 0440 text: { 0441 var state = i18n("N/A"); 0442 0443 if (kirogi.currentVehicle) { 0444 if (kirogi.currentVehicle.gpsFix) { 0445 state = i18n("Got fix"); 0446 } else if (kirogi.currentVehicle.gpsSupported) { 0447 state = i18n("No fix"); 0448 } else { 0449 state = i18n("Not supported"); 0450 } 0451 } 0452 0453 return i18n("<b>GPS:</b> %1", state) 0454 } 0455 0456 color: { 0457 if (kirogi.connected) { 0458 if (kirogi.currentVehicle.gpsFix) { 0459 return Kirigami.Theme.positiveTextColor; 0460 } else if (kirogi.currentVehicle.gpsSupported) { 0461 return Kirigami.Theme.textColor; 0462 } 0463 } 0464 0465 return Kirigami.Theme.disabledTextColor; 0466 } 0467 0468 elide: Text.ElideRight 0469 } 0470 } 0471 } 0472 } 0473 } 0474 0475 footer: QQC2.Button { 0476 text: { 0477 if (!kirogi.currentPlugin) { 0478 return i18n("Select Model"); 0479 } else if (kirogi.ready) { 0480 return i18n("Go to Flight Controls"); 0481 } 0482 0483 return i18n("Try Flight Controls"); 0484 } 0485 0486 onClicked: { 0487 if (!kirogi.currentPlugin) { 0488 pluginSheet.sheetOpen = !pluginSheet.sheetOpen; 0489 0490 return; 0491 } 0492 0493 switchApplicationPage(flightControlsPage); 0494 } 0495 } 0496 } 0497 }