KOSMIndoorMap

IndoorMap.qml
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 import QtQuick 2.12
8 import QtQuick.Layouts 1.12
9 import org.kde.kosmindoormap 1.0
10 import QtQuick.Controls 2.12 as QQC2
11 
12 /** QML item for displaying a train station or airport map. */
13 Item {
14  id: mapRoot
15 
16  /** Access to map loading status and progress. */
17  property alias mapLoader: map.loader
18  /** Path to a MapCSS style sheet used for rendering the map. */
19  property alias styleSheet: map.styleSheet
20  /** Floor level model. */
21  property alias floorLevels: map.floorLevels
22  /** Access to the view transformation and floor level selection. */
23  property alias view: map.view
24  /** There is something preventing displaying a map. */
25  property alias hasError: map.hasError
26  /** Access to the map data, for feeding into content-specific models. */
27  property alias mapData: map.mapData
28  /** Access to overlay sources. */
29  property alias overlaySources: map.overlaySources
30  /** ISO 3166-1/2 country or region code for opening hours interpretation. */
31  property alias region: map.region
32  /** IANA timezone id for opening hours interpretation. */
33  property alias timeZone: map.timeZone
34 
35  /** Emitted when a map element has been picked by clicking/tapping on it. */
36  signal elementPicked(var element);
37  /** Emitted when a map element has been long-pressed. */
38  signal elementLongPressed(var element);
39 
40  MapItemImpl {
41  id: map
42  anchors.fill: parent
43 
44  }
45 
46  Flickable {
47  id: flickable
48  boundsBehavior: Flickable.StopAtBounds
49  clip: true
50  contentX: map.view.panX
51  contentY: map.view.panY
52  contentWidth: map.view.panWidth
53  contentHeight: map.view.panHeight
54  anchors.fill: parent
55 
56  onContentXChanged: {
57  if (moving) {
58  map.view.panTopLeft(flickable.contentX, flickable.contentY);
59  map.update();
60  }
61  }
62  onContentYChanged: {
63  if (moving) {
64  map.view.panTopLeft(flickable.contentX, flickable.contentY);
65  map.update();
66  }
67  }
68 
69  QQC2.ScrollBar.vertical: QQC2.ScrollBar {}
70  QQC2.ScrollBar.horizontal: QQC2.ScrollBar {}
71 
72  TapHandler {
73  id: tapHandler
74  acceptedButtons: Qt.LeftButton
75  onTapped: function(eventPoint) {
76  var root = parent;
77  while (root.parent) { root = root.parent; }
78  var localPos = map.mapFromItem(root, eventPoint.scenePosition.x, eventPoint.scenePosition.y);
79  var element = map.elementAt(localPos.x, localPos.y);
80  if (!element.isNull) {
81  elementPicked(element);
82  }
83  }
84  onLongPressed: function() {
85  var root = parent;
86  while (root.parent) { root = root.parent; }
87  var localPos = map.mapFromItem(root, tapHandler.point.scenePosition.x, tapHandler.point.scenePosition.y);
88  var element = map.elementAt(localPos.x, localPos.y);
89  if (!element.isNull) {
90  elementLongPressed(element);
91  }
92  }
93  }
94  PinchHandler {
95  id: pinchHandler
96  target: null
97  property double initialZoom
98  onActiveChanged: {
99  initialZoom = map.view.zoomLevel
100  }
101  onActiveScaleChanged: {
102  map.view.setZoomLevel(pinchHandler.initialZoom + Math.log2(pinchHandler.activeScale), pinchHandler.centroid.pressPosition);
103  }
104  xAxis.enabled: false
105  yAxis.enabled: false
106  minimumRotation: 0.0
107  maximumRotation: 0.0
108  }
109  }
110 
111  Connections {
112  target: map.view
113  function onTransformationChanged() {
114  flickable.contentX = map.view.panX;
115  flickable.contentY = map.view.panY;
116  }
117  }
118 
119  MouseArea {
120  acceptedButtons: Qt.NoButton
121  anchors.fill: parent
122  onWheel: {
123  if (wheel.angleDelta.y > 0) {
124  map.view.zoomIn(Qt.point(wheel.x, wheel.y));
125  } else {
126  map.view.zoomOut(Qt.point(wheel.x, wheel.y));
127  }
128  wheel.accepted = true;
129  }
130  }
131 
132  QQC2.BusyIndicator {
133  anchors.centerIn: parent
134  running: map.loader.isLoading
135  }
136 
137  QQC2.Label {
138  anchors.fill: parent
139  text: map.errorMessage
140  visible: map.hasError
141  wrapMode: Text.WordWrap
142  horizontalAlignment: Qt.AlignHCenter
143  verticalAlignment: Qt.AlignVCenter
144  }
145 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.