Warning, /libraries/kosmindoormap/src/map-quick/IndoorMap.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import org.kde.kosmindoormap 0010 import QtQuick.Controls as QQC2 0011 0012 /** QML item for displaying a train station or airport map. */ 0013 Item { 0014 id: mapRoot 0015 0016 /** Access to map loading status and progress. */ 0017 property alias mapLoader: map.loader 0018 /** Path to a MapCSS style sheet used for rendering the map. */ 0019 property alias styleSheet: map.styleSheet 0020 /** Floor level model. */ 0021 property alias floorLevels: map.floorLevels 0022 /** Access to the view transformation and floor level selection. */ 0023 property alias view: map.view 0024 /** There is something preventing displaying a map. */ 0025 property alias hasError: map.hasError 0026 /** Access to the map data, for feeding into content-specific models. */ 0027 property alias mapData: map.mapData 0028 /** Access to overlay sources. */ 0029 property alias overlaySources: map.overlaySources 0030 /** ISO 3166-1/2 country or region code for opening hours interpretation. */ 0031 property alias region: map.region 0032 /** IANA timezone id for opening hours interpretation. */ 0033 property alias timeZone: map.timeZone 0034 /** Currently hovered element. */ 0035 property alias hoveredElement: map.hoveredElement 0036 0037 /** Emitted when a map element has been picked by clicking/tapping on it. */ 0038 signal elementPicked(var element); 0039 /** Emitted when a map element has been long-pressed. */ 0040 signal elementLongPressed(var element); 0041 0042 /** Map an event handler EventPoint to map screen coordinates. */ 0043 function mapEventPointToScreen(eventPoint) { 0044 let root = mapRoot.parent; 0045 while (root.parent) { root = root.parent; } 0046 return map.mapFromItem(root, eventPoint.scenePosition.x, eventPoint.scenePosition.y); 0047 } 0048 0049 /** Returns the OSM element at the given screen position, if any. */ 0050 function elementAt(screenPosition) { 0051 return map.elementAt(screenPosition.x, screenPosition.y); 0052 } 0053 0054 MapItemImpl { 0055 id: map 0056 anchors.fill: mapRoot 0057 } 0058 0059 Flickable { 0060 id: flickable 0061 boundsBehavior: Flickable.StopAtBounds 0062 clip: true 0063 interactive: !pinchHandler.active 0064 contentX: map.view.panX 0065 contentY: map.view.panY 0066 contentWidth: map.view.panWidth 0067 contentHeight: map.view.panHeight 0068 anchors.fill: parent 0069 0070 onContentXChanged: { 0071 if (moving) { 0072 map.view.panTopLeft(flickable.contentX, flickable.contentY); 0073 map.update(); 0074 } 0075 } 0076 onContentYChanged: { 0077 if (moving) { 0078 map.view.panTopLeft(flickable.contentX, flickable.contentY); 0079 map.update(); 0080 } 0081 } 0082 0083 QQC2.ScrollBar.vertical: QQC2.ScrollBar {} 0084 QQC2.ScrollBar.horizontal: QQC2.ScrollBar {} 0085 0086 TapHandler { 0087 id: tapHandler 0088 acceptedButtons: Qt.LeftButton 0089 onTapped: function(eventPoint) { 0090 const element = mapRoot.elementAt(mapRoot.mapEventPointToScreen(eventPoint)); 0091 if (!element.isNull) { 0092 elementPicked(element); 0093 } 0094 } 0095 onLongPressed: function() { 0096 const element = mapRoot.elementAt(mapRoot.mapEventPointToScreen(tapHandler.point)); 0097 if (!element.isNull) { 0098 elementLongPressed(element); 0099 } 0100 } 0101 } 0102 PinchHandler { 0103 id: pinchHandler 0104 target: null 0105 property double initialZoom 0106 onActiveChanged: { 0107 initialZoom = map.view.zoomLevel 0108 } 0109 onActiveScaleChanged: { 0110 map.view.setZoomLevel(pinchHandler.initialZoom + Math.log2(pinchHandler.activeScale), 0111 Qt.point(pinchHandler.centroid.position.x - flickable.contentX, pinchHandler.centroid.position.y - flickable.contentY)); 0112 } 0113 xAxis.enabled: false 0114 yAxis.enabled: false 0115 minimumRotation: 0.0 0116 maximumRotation: 0.0 0117 } 0118 WheelHandler { 0119 id: wheelHandler 0120 target: null 0121 orientation: Qt.Vertical 0122 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad 0123 property double initialZoom: 0.0 0124 onActiveChanged: { 0125 wheelHandler.initialZoom = map.view.zoomLevel 0126 wheelHandler.rotation = 0; 0127 } 0128 onRotationChanged: { 0129 // same scale as in qquickmapgestrurearea.cpp 0130 map.view.setZoomLevel(wheelHandler.initialZoom + 0.05 * wheelHandler.rotation, 0131 Qt.point(wheelHandler.point.position.x - flickable.contentX, wheelHandler.point.position.y - flickable.contentY)); 0132 } 0133 } 0134 } 0135 0136 Connections { 0137 target: map.view 0138 function onTransformationChanged() { 0139 flickable.contentX = map.view.panX; 0140 flickable.contentY = map.view.panY; 0141 } 0142 } 0143 0144 QQC2.BusyIndicator { 0145 anchors.centerIn: parent 0146 running: map.loader.isLoading 0147 } 0148 0149 QQC2.Label { 0150 anchors.fill: parent 0151 text: map.errorMessage 0152 visible: map.hasError 0153 wrapMode: Text.WordWrap 0154 horizontalAlignment: Qt.AlignHCenter 0155 verticalAlignment: Qt.AlignVCenter 0156 } 0157 }