IndoorMapPage.qml 8.04 KB
Newer Older
Volker Krause's avatar
Volker Krause committed
1
/*
2
    SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
Volker Krause's avatar
Volker Krause committed
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
Volker Krause's avatar
Volker Krause committed
5
6
7
8
9
10
*/

import QtQuick 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.7 as Kirigami
11
import org.kde.kpublictransport 1.0 as PT
Volker Krause's avatar
Volker Krause committed
12
13
import org.kde.kosmindoormap 1.0
import org.kde.itinerary 1.0
14
import org.kde.kosmindoormap.kpublictransport 1.0
Volker Krause's avatar
Volker Krause committed
15
16

Kirigami.Page {
Volker Krause's avatar
Volker Krause committed
17
    id: root
Volker Krause's avatar
Volker Krause committed
18
19
20
21
22
23
24
25
26
27
28
29
    title: {
        if (map.mapLoader.isLoading || map.hasError)
            return placeName;
        if (map.floorLevels.hasName(map.view.floorLevel))
            return map.floorLevels.name(map.view.floorLevel);
        return i18n("Floor %1", map.floorLevels.name(map.view.floorLevel));
    }

    property point coordinate
    property string placeName
    property alias map: map

Volker Krause's avatar
Volker Krause committed
30
31
32
33
34
    property string arrivalGateName
    property string arrivalPlatformName
    property string departureGateName
    property string departurePlatformName

Volker Krause's avatar
Volker Krause committed
35
36
    property string region
    property string timeZone
37
38
39
    property date beginTime
    property date endTime

Volker Krause's avatar
Volker Krause committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    topPadding: 0
    bottomPadding: 0
    leftPadding: 0
    rightPadding: 0

    // prevent swipe to the right changing pages, we want to pan the map instead
    // TODO in theory we could make this conditional to having panned the map all the way to the right
    Kirigami.ColumnView.preventStealing: true

    actions {
        left: Kirigami.Action {
            iconName: "go-down-symbolic"
            enabled: map.floorLevels.hasFloorLevelBelow(map.view.floorLevel)
            onTriggered: map.view.floorLevel = map.floorLevels.floorLevelBelow(map.view.floorLevel)
54
            visible: map.floorLevels.hasFloorLevels
Volker Krause's avatar
Volker Krause committed
55
56
57
58
59
        }
        right: Kirigami.Action {
            iconName: "go-up-symbolic"
            enabled: map.floorLevels.hasFloorLevelAbove(map.view.floorLevel)
            onTriggered: map.view.floorLevel = map.floorLevels.floorLevelAbove(map.view.floorLevel)
60
            visible: map.floorLevels.hasFloorLevels
Volker Krause's avatar
Volker Krause committed
61
62
        }
    }
63
    contextualActions: [
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        Kirigami.Action {
            id: zoomInAction
            text: i18n("Zoom In")
            iconName: "zoom-in-symbolic"
            onTriggered: map.view.setZoomLevel(map.view.zoomLevel + 1, Qt.point(map.width / 2.0, map.height/ 2.0));
            enabled: map.view.zoomLevel < 21
        },
        Kirigami.Action {
            id: zoomOutAction
            text: i18n("Zoom Out")
            iconName: "zoom-out-symbolic"
            onTriggered: map.view.setZoomLevel(map.view.zoomLevel - 1, Qt.point(map.width / 2.0, map.height/ 2.0));
            enabled: map.view.zoomLevel > 14
        },
78
79
80
81
82
83
84
85
86
87
88
        Kirigami.Action {
            id: platformAction
            text: i18n("Find Platform")
            onTriggered: platformSheet.sheetOpen = true
            visible: !platformModel.isEmpty
        },
        Kirigami.Action {
            id: gateAction
            text: i18n("Find Gate")
            onTriggered: gateSheet.sheetOpen = true
            visible: !gateModel.isEmpty
89
        },
90
91
92
93
94
95
96
97
        Kirigami.Action { separator: true },
        Kirigami.Action {
            id: rentalVehicleAction
            text: i18n("Show Rental Vehicles")
            checkable: true
            enabled: !map.mapLoader.isLoading
            onTriggered: queryRentalVehicles();
        },
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        Kirigami.Action {
            id: lightStyleAction
            text: "Light Style"
            onTriggered: map.styleSheet = "breeze-light"
            visible: Settings.developmentMode
        },
        Kirigami.Action {
            id: darkStyleAction
            text: "Dark Style"
            onTriggered: map.styleSheet = "breeze-dark"
            visible: Settings.developmentMode
        },
        Kirigami.Action {
            id: diagnosticStyleAction
            text: "Diagnostic Style"
            onTriggered: map.styleSheet = "diagnostic"
            visible: Settings.developmentMode
115
116
        }
    ]
Volker Krause's avatar
Volker Krause committed
117
118
119

    OSMElementInformationModel {
        id: infoModel
Volker Krause's avatar
Volker Krause committed
120
        debug: Settings.developmentMode
Volker Krause's avatar
Volker Krause committed
121
122
    }

123
    IndoorMapInfoSheet {
Volker Krause's avatar
Volker Krause committed
124
        id: elementDetailsSheet
125
        model: infoModel
126
        mapData: map.mapData
Volker Krause's avatar
Volker Krause committed
127
128
    }

129
130
131
    PlatformModel {
        id: platformModel
        mapData: map.mapData
Volker Krause's avatar
Volker Krause committed
132
133
134
135
136
137
138
139
140

        onPlatformIndexChanged: {
            if (platformModel.departurePlatformRow >= 0) {
                var idx = platformModel.index(platformModel.departurePlatformRow, 0);
                map.view.floorLevel = platformModel.data(idx, PlatformModel.LevelRole)
                map.view.centerOnGeoCoordinate(platformModel.data(idx, PlatformModel.CoordinateRole));
                map.view.setZoomLevel(19, Qt.point(map.width / 2.0, map.height/ 2.0));
            }
        }
141
142
    }

143
    IndoorMapPlatformSheet {
144
        id: platformSheet
145
        model: platformModel
146
147
148
149
150
    }

    GateModel {
        id: gateModel
        mapData: map.mapData
Volker Krause's avatar
Volker Krause committed
151
152
153
154
155
156
157
158
159

        onGateIndexChanged: {
            if (gateModel.departureGateRow >= 0) {
                var idx = gateModel.index(gateModel.departureGateRow, 0);
                map.view.floorLevel = gateModel.data(idx, GateModel.LevelRole)
                map.view.centerOnGeoCoordinate(gateModel.data(idx, GateModel.CoordinateRole));
                map.view.setZoomLevel(18, Qt.point(map.width / 2.0, map.height/ 2.0));
            }
        }
160
161
    }

162
    IndoorMapGateSheet {
163
        id: gateSheet
164
        model: gateModel
165
166
    }

167
168
169
170
171
172
173
174
175
176
177
    FloorLevelChangeModel {
        id: floorLevelChangeModel
        currentFloorLevel: map.view.floorLevel
        floorLevelModel: map.floorLevels
    }

    IndoorMapElevatorSheet {
        id: elevatorSheet
        model: floorLevelChangeModel
    }

178
179
    LocationQueryOverlayProxyModel {
        id: locationModel
180
        sourceModel: PT.LocationQueryModel {
181
182
183
184
185
186
187
188
189
190
191
192
            id: locationQuery
            manager: LiveDataManager.publicTransportManager
        }
        mapData: map.mapData
    }

    function queryRentalVehicles()
    {
        if (rentalVehicleAction.checked) {
            locationQuery.request.latitude = map.mapData.center.y;
            locationQuery.request.longitude = map.mapData.center.x;
            locationQuery.request.maximumDistance = map.mapData.radius;
193
            locationQuery.request.types = PT.Location.RentedVehicleStation | PT.Location.RentedVehicle;
194
        } else {
195
            locationQuery.clear();
196
197
198
        }
    }

Volker Krause's avatar
Volker Krause committed
199
200
201
    IndoorMap {
        id: map
        anchors.fill: parent
202
        overlaySources: [ gateModel, platformModel, locationModel ]
Volker Krause's avatar
Volker Krause committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216

        IndoorMapScale {
            map: map
            anchors.left: map.left
            anchors.top: map.top
            width: 0.3 * map.width
        }

        IndoorMapAttributionLabel {
            anchors.right: map.right
            anchors.bottom: map.bottom
        }

        onElementPicked: {
217
218
219
220
221
222
223
224
225
226
            floorLevelChangeModel.element = element;
            if (floorLevelChangeModel.hasSingleLevelChange) {
                showPassiveNotification(i18n("Switched to floor %1", floorLevelChangeModel.destinationLevelName), "short");
                map.view.floorLevel = floorLevelChangeModel.destinationLevel;
                return;
            } else if (floorLevelChangeModel.hasMultipleLevelChanges) {
                elevatorSheet.sheetOpen = true;
                return;
            }

Volker Krause's avatar
Volker Krause committed
227
228
229
230
231
232
233
234
            infoModel.element = element;
            if (infoModel.name != "" || infoModel.debug) {
                elementDetailsSheet.sheetOpen = true;
            }
        }
    }

    onCoordinateChanged: map.mapLoader.loadForCoordinate(coordinate.y, coordinate.x);
Volker Krause's avatar
Volker Krause committed
235
236
237
238
239
240
241
242

    Connections {
        target: map.mapLoader
        function onDone() {
            platformModel.setArrivalPlatform(root.arrivalPlatformName, Platform.Rail);
            platformModel.setDeparturePlatform(root.departurePlatformName, Platform.Rail);
            gateModel.setArrivalGate(root.arrivalGateName);
            gateModel.setDepartureGate(root.departureGateName);
Volker Krause's avatar
Volker Krause committed
243
244
            map.region = root.region;
            map.timeZone = root.timeZone;
245
246
            map.view.beginTime = root.beginTime;
            map.view.endTime = root.endTime;
247
            queryRentalVehicles();
Volker Krause's avatar
Volker Krause committed
248
249
        }
    }
Volker Krause's avatar
Volker Krause committed
250
}