KOSMIndoorMap

IndoorMapPage.qml
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
11import org.kde.kosmindoormap
12import org.kde.kosmindoorrouting
13
14Kirigami.Page {
15 title: map.floorLevels.hasName(map.view.floorLevel) && isNaN(parseInt(map.floorLevels.name(map.view.floorLevel))) ? map.floorLevels.name(map.view.floorLevel) : ("Floor " + map.floorLevels.name(map.view.floorLevel));
16 property point coordinate
17 property alias map: map
18 property alias debug: infoModel.debug
19 property alias mapHoverEnabled: hoverHandler.enabled
20 property RoutingController routingController
21
22 topPadding: 0
23 bottomPadding: 0
24 leftPadding: 0
25 rightPadding: 0
26
27 // prevent swipe to the right changing pages, we want to pan the map instead
28 // TODO in theory we could make this conditional to having panned the map all the way to the right
29 Kirigami.ColumnView.preventStealing: true
30
31 actions: [
32 Kirigami.Action {
33 icon.name: "go-down-symbolic"
34 enabled: map.floorLevels.hasFloorLevelBelow(map.view.floorLevel)
35 onTriggered: map.view.floorLevel = map.floorLevels.floorLevelBelow(map.view.floorLevel)
36 shortcut: "PgDown"
37 },
38 Kirigami.Action {
39 icon.name: "go-up-symbolic"
40 enabled: map.floorLevels.hasFloorLevelAbove(map.view.floorLevel)
41 onTriggered: map.view.floorLevel = map.floorLevels.floorLevelAbove(map.view.floorLevel)
42 shortcut: "PgUp"
43 }
44 ]
45
46 OSMElementInformationModel {
47 id: infoModel
48 allowOnlineContent: true
49 debug: true
50 }
51
52 IndoorMapInfoSheet {
53 id: elementDetailsSheet
54 model: infoModel
55 regionCode: page.map.mapData.regionCode
56 timeZone: page.map.mapData.timeZone
57 }
58
59 FloorLevelChangeModel {
60 id: floorLevelChangeModel
61 currentFloorLevel: map.view.floorLevel
62 floorLevelModel: map.floorLevels
63 }
64
65 FloorLevelSelector {
66 id: elevatorSheet
67 model: floorLevelChangeModel
68 onFloorLevelSelected: (level) => { map.view.floorLevel = level; }
69 }
70
71 IndoorMap {
72 id: map
73 anchors.fill: parent
74 hoveredElement: map.elementAt(map.mapEventPointToScreen(hoverHandler.point))
75
76 IndoorMapScale {
77 map: map
78 anchors.left: map.left
79 anchors.bottom: map.bottom
80 width: 0.3 * map.width
81 }
82
83 IndoorMapAttributionLabel {
84 anchors.right: map.right
85 anchors.bottom: map.bottom
86 }
87
88 QQC2.Menu {
89 id: contextMenu
90 property mapPointerEvent ev
91 QQC2.MenuItem {
92 text: i18n("Navigate from here")
93 icon.name: "go-next"
94 onTriggered: {
95 routingController.setStartPosition(contextMenu.ev.geoPosition.y, contextMenu.ev.geoPosition.x, map.view.floorLevel);
96 routingController.searchRoute();
97 }
98 }
99 QQC2.MenuItem {
100 text: i18n("Navigate to here")
101 icon.name: "map-symbolic"
102 onTriggered: {
103 routingController.setEndPosition(contextMenu.ev.geoPosition.y, contextMenu.ev.geoPosition.x, map.view.floorLevel);
104 routingController.searchRoute();
105 }
106 }
107 QQC2.MenuItem {
108 id: contextMenuInfoAction
109 // enabled: !ev.element.isNull && (infoModel.name !== "" || infoModel.debug)
110 text: i18n("Show information")
111 icon.name: "documentinfo"
112 onTriggered: elementDetailsSheet.open()
113 }
114 }
115
116 function showContextMenu(ev) {
117 infoModel.element = ev.element;
118 contextMenuInfoAction.enabled = !ev.element.isNull && (infoModel.name !== "" || infoModel.debug);
119 contextMenu.ev = ev;
120 contextMenu.popup(map, ev.screenPosition);
121 }
122
123 onTapped: (ev) => {
124 // left click on element: floor level change if applicable, otherwise info dialog
125 // (button === is finger on touch screen)
126 if (!ev.element.isNull && (ev.button === Qt.LeftButton || ev.button === 0)) {
127 floorLevelChangeModel.element = ev.element;
128 if (floorLevelChangeModel.hasSingleLevelChange) {
129 showPassiveNotification("Switched to floor " + floorLevelChangeModel.destinationLevelName, "short");
130 map.view.floorLevel = floorLevelChangeModel.destinationLevel;
131 return;
132 } else if (floorLevelChangeModel.hasMultipleLevelChanges) {
133 elevatorSheet.open();
134 return;
135 }
136
137 infoModel.element = ev.element;
138 if (infoModel.name != "" || infoModel.debug) {
139 elementDetailsSheet.open();
140 }
141 }
142
143 // right click: context menu, with info action if clicked on an element
144 if (ev.button === Qt.RightButton) {
145 showContextMenu(ev);
146 }
147 }
148
149 onLongPressed: (ev) => {
150 showContextMenu(ev);
151 }
152
153 HoverHandler {
154 id: hoverHandler
155 enabled: false
156 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
157 }
158 }
159
160 onCoordinateChanged: map.mapLoader.loadForCoordinate(coordinate.y, coordinate.x);
161}
QML item for displaying a train station or airport map.
Definition IndoorMap.qml:10
QString i18n(const char *text, const TYPE &arg...)
QStringView level(QStringView ifopt)
const QList< QKeySequence > & shortcut(StandardShortcut id)
bool isNull() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:55:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.