Warning, /libraries/kpublictransport/tests/onboard.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import QtLocation as QtLocation
0010 import QtPositioning
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kpublictransport
0013 import org.kde.kpublictransport.onboard
0014 
0015 Kirigami.ApplicationWindow {
0016     title: "Onboard API Demo"
0017 
0018     width: 540
0019     height: 720
0020 
0021     pageStack.initialPage: onboardPage
0022 
0023     OnboardStatus {
0024         id: onboardStatus
0025         positionUpdateInterval: 10
0026         journeyUpdateInterval: 60
0027     }
0028 
0029     Component {
0030         id: onboardPage
0031 
0032         Kirigami.Page {
0033             QQC2.SwipeView {
0034                 id: swipeView
0035                 anchors.fill: parent
0036 
0037                 Kirigami.Page {
0038                     header: Kirigami.FormLayout {
0039                         QQC2.Label {
0040                             text: onboardStatus.status
0041                             Kirigami.FormData.label: "Status"
0042                         }
0043                         QQC2.Label {
0044                             text: onboardStatus.latitude + " x " + onboardStatus.longitude
0045                             Kirigami.FormData.label: "Position"
0046                         }
0047                         QQC2.Label {
0048                             text: onboardStatus.speed
0049                             Kirigami.FormData.label: "Speed"
0050                         }
0051                         QQC2.Label {
0052                             text: onboardStatus.heading
0053                             Kirigami.FormData.label: "Heading"
0054                         }
0055                     }
0056 
0057                     Kirigami.ColumnView.preventStealing: true
0058 
0059                     QtLocation.Plugin {
0060                         id: mapPlugin
0061                         name: "osm"
0062                         QtLocation.PluginParameter { name: "osm.useragent"; value: "KPublicTransport Onboard API demo" }
0063                         QtLocation.PluginParameter { name: "osm.mapping.providersrepository.address"; value: "https://autoconfig.kde.org/qtlocation/" }
0064                     }
0065 
0066                     QtLocation.Map {
0067                         id: map
0068                         anchors.fill: parent
0069                         center: QtPositioning.coordinate(onboardStatus.latitude, onboardStatus.longitude)
0070                         plugin: mapPlugin
0071                         zoomLevel: 14
0072 
0073                         PinchHandler {
0074                             id: pinch
0075                             target: null
0076                             onActiveChanged: if (active) {
0077                                 map.startCentroid = map.toCoordinate(pinch.centroid.position, false)
0078                             }
0079                             onScaleChanged: (delta) => {
0080                                 map.zoomLevel += Math.log2(delta)
0081                                 map.alignCoordinateToPoint(map.startCentroid, pinch.centroid.position)
0082                             }
0083                             onRotationChanged: (delta) => {
0084                                 map.bearing -= delta
0085                                 map.alignCoordinateToPoint(map.startCentroid, pinch.centroid.position)
0086                             }
0087                             grabPermissions: PointerHandler.TakeOverForbidden
0088                         }
0089                         WheelHandler {
0090                             id: wheel
0091                             rotationScale: 1/120
0092                             property: "zoomLevel"
0093                         }
0094                         DragHandler {
0095                             id: drag
0096                             target: null
0097                             onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y)
0098                         }
0099                         Shortcut {
0100                             enabled: map.zoomLevel < map.maximumZoomLevel
0101                             sequence: StandardKey.ZoomIn
0102                             onActivated: map.zoomLevel = Math.round(map.zoomLevel + 1)
0103                         }
0104                         Shortcut {
0105                             enabled: map.zoomLevel > map.minimumZoomLevel
0106                             sequence: StandardKey.ZoomOut
0107                             onActivated: map.zoomLevel = Math.round(map.zoomLevel - 1)
0108                         }
0109 
0110                         QtLocation.MapQuickItem {
0111                             coordinate: QtPositioning.coordinate(onboardStatus.latitude, onboardStatus.longitude)
0112                             anchorPoint { x: icon.width / 2; y: icon.height / 2 }
0113                             visible: onboardStatus.hasPosition
0114                             sourceItem: Kirigami.Icon {
0115                                 id: icon
0116                                 source: "go-up-symbolic"
0117                                 width: height
0118                                 height: Kirigami.Units.iconSizes.large
0119                                 color: Kirigami.Theme.negativeTextColor
0120                                 rotation: onboardStatus.hasHeading ? onboardStatus.heading : 0
0121                                 transformOrigin: Item.Center
0122                                 onTransformOriginChanged: icon.transformOrigin = Item.Center
0123                             }
0124                         }
0125                     }
0126                 }
0127 
0128                 JourneySectionPage {
0129                     journeySection: onboardStatus.journey.sections[0]
0130                 }
0131             }
0132 
0133             footer: Kirigami.NavigationTabBar {
0134                 actions: [
0135                     Kirigami.Action {
0136                         text: "Position"
0137                         icon.name: 'map-symbolic'
0138                         onTriggered: swipeView.currentIndex = 0
0139                         checked: swipeView.currentIndex === 0
0140                     },
0141                     Kirigami.Action {
0142                         text: "Journey"
0143                         icon.name: 'path-mode-polyline'
0144                         onTriggered: swipeView.currentIndex = 1;
0145                         checked: swipeView.currentIndex === 1
0146                     }
0147                 ]
0148             }
0149         }
0150     }
0151 }