diff --git a/src/map-quick/CMakeLists.txt b/src/map-quick/CMakeLists.txt index 6b54415..a821235 100644 --- a/src/map-quick/CMakeLists.txt +++ b/src/map-quick/CMakeLists.txt @@ -1,26 +1,27 @@ set(kosmindoormapquickplugin_SRC kosmindoormapquickplugin.cpp floorlevelmodel.cpp mapitem.cpp osmelement.cpp ) set(kosmindoormapquickplugin_qml qmldir IndoorMap.qml + IndoorMapScale.qml ) add_library(kosmindoormapquickplugin ${kosmindoormapquickplugin_SRC}) target_link_libraries(kosmindoormapquickplugin Qt5::Quick KOSMIndoorMap ) # make examples work without installation set_property(TARGET kosmindoormapquickplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/kosmindoormap) file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/kosmindoormap/) foreach(f IN LISTS kosmindoormapquickplugin_qml) file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/kosmindoormap/${f} SYMBOLIC) endforeach() # install(TARGETS kosmindoormapquickplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kosmindoormap) # install(FILES ${kosmindoormapquickplugin_qml} ${quick_SRC} DESTINATION ${QML_INSTALL_DIR}/org/kde/kosmindoormap) diff --git a/src/map-quick/IndoorMapScale.qml b/src/map-quick/IndoorMapScale.qml new file mode 100644 index 0000000..563c5d5 --- /dev/null +++ b/src/map-quick/IndoorMapScale.qml @@ -0,0 +1,68 @@ +/* + Copyright (C) 2020 Volker Krause + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 as QQC2 + +Item { + id: root + property var view + + implicitHeight: background.height + + property int __margin: 2 + + function updateScale() { + var d = map.view.mapScreenToMeters(background.width - 2 * __margin); + var s = d < 20 ? 5 : d < 100 ? 10 : 20; + d /= s; + d = Math.floor(d); + d *= s; + scaleLabel.text = d + "m"; // TODO i18n? + scale.width = map.view.mapMetersToScreen(d); + } + + Rectangle { + id: background + color: scaleLabel.palette.base + opacity: 0.5 + height: scaleLabel.implicitHeight + scale.height + 2 * __margin + width: root.width + } + + QQC2.Label { + id: scaleLabel + anchors.bottom: scale.top + anchors.horizontalCenter: scale.horizontalCenter + } + + Rectangle { + id: scale + anchors.bottom: root.bottom + anchors.left: root.left + anchors.margins: __margin + height: 4 + color: scaleLabel.color + } + + Component.onCompleted: root.updateScale() + + Connections { + target: root.view + onTransformationChanged: root.updateScale(); + } +} diff --git a/src/map-quick/qmldir b/src/map-quick/qmldir index 8598ca8..7c00125 100644 --- a/src/map-quick/qmldir +++ b/src/map-quick/qmldir @@ -1,4 +1,5 @@ module org.kde.kosmindoormap plugin kosmindoormapquickplugin classname KOSMIndoorMapQuickPlugin IndoorMap 1.0 IndoorMap.qml +IndoorMapScale 1.0 IndoorMapScale.qml diff --git a/tests/indoormap.qml b/tests/indoormap.qml index 86ee4d2..4f016cc 100644 --- a/tests/indoormap.qml +++ b/tests/indoormap.qml @@ -1,186 +1,153 @@ /* Copyright (C) 2020 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.12 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.kirigami 2.0 as Kirigami import org.kde.kosmindoormap 1.0 Kirigami.ApplicationWindow { title: "OSM Indoor Map QML Test" pageStack.initialPage: Kirigami.Page { title: "Indoor Map View" 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) } right: Kirigami.Action { iconName: "go-up-symbolic" enabled: map.floorLevels.hasFloorLevelAbove(map.view.floorLevel) onTriggered: map.view.floorLevel = map.floorLevels.floorLevelAbove(map.view.floorLevel) } contextualActions: [ Kirigami.Action { text: "Light Style" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/breeze-light.mapcss" }, Kirigami.Action { text: "Dark Style" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/breeze-dark.mapcss" }, Kirigami.Action { text: "Diagnostic View" onTriggered: map.styleSheet = ":/org.kde.kosmindoormap/assets/css/diagnostic.mapcss" } ] } header: RowLayout { QQC2.Label { text: "Floor Level:" } QQC2.ComboBox { id: floorLevelCombo model: map.floorLevels textRole: "display" Component.onCompleted: currentIndex = map.floorLevels.rowForLevel(map.view.floorLevel); onCurrentIndexChanged: if (currentIndex >= 0) { map.view.floorLevel = map.floorLevels.levelForRow(currentIndex); } } Connections { target: map.view onFloorLevelChanged: floorLevelCombo.currentIndex = map.floorLevels.rowForLevel(map.view.floorLevel); } QQC2.Label { text: "Coordinate:" } QQC2.TextField { id: coordInput placeholderText: "map coordinates" text: "49.44572, 11.08196" } QQC2.Button { text: "x" onClicked: coordInput.text = "" } QQC2.Button { text: ">" onClicked: { var c = coordInput.text.match(/(.*)[,;/ ]+(.*)/); var lat = c[1]; var lon = c[2]; map.mapLoader.loadForCoordinate(lat, lon); } } } Kirigami.OverlaySheet { id: elementDetailsSheet property var element header: Kirigami.Heading { text: elementDetailsSheet.element.name } ColumnLayout { QQC2.Label { visible: text != "" text: elementDetailsSheet.element.tagValue("description"); } QQC2.Label { visible: text != "" text: elementDetailsSheet.element.tagValue("amenity") + elementDetailsSheet.element.tagValue("shop") + elementDetailsSheet.element.tagValue("tourism") + elementDetailsSheet.element.tagValue("office") } QQC2.Label { visible: text != "" text: elementDetailsSheet.element.tagValue("opening_hours"); } QQC2.Label { visible: elementDetailsSheet.element.tagValue("website") != "" text: "" + elementDetailsSheet.element.tagValue("website") + "" onLinkActivated: Qt.openUrlExternally(link) } QQC2.Label { visible: elementDetailsSheet.element.wikipediaUrl != "" text: "Wikipedia" onLinkActivated: Qt.openUrlExternally(link) } QQC2.Label { text: elementDetailsSheet.element.tagValue("addr:street") + " " + elementDetailsSheet.element.tagValue("addr:housenumber") + "\n" + elementDetailsSheet.element.tagValue("addr:postcode") + " " + elementDetailsSheet.element.tagValue("addr:city") + "\n" + elementDetailsSheet.element.tagValue("addr:country"); } } } IndoorMap { id: map anchors.fill: parent styleSheet: ":/org.kde.kosmindoormap/assets/css/breeze-light.mapcss" - Component.onCompleted: { - map.mapLoader.loadForCoordinate(49.44572, 11.08196); - } - - Rectangle { - id: scaleBackground - color: Kirigami.Theme.backgroundColor - opacity: 0.5 + IndoorMapScale { + view: map.view anchors.left: map.left anchors.bottom: map.bottom - width: 0.3 * map.width; - height: 30 - - function updateScale() { - var d = map.view.mapScreenToMeters(scaleBackground.width); - var s = d < 20 ? 5 : d < 100 ? 10 : 20; - d /= s; - d = Math.floor(d); - d *= s; - scaleLabel.text = d + "m"; - scale.width = map.view.mapMetersToScreen(d); - } - - QQC2.Label { - id: scaleLabel - anchors.centerIn: parent - } - - Rectangle { - id: scale - anchors.bottom: parent.bottom - height: 4 - color: Kirigami.Theme.textColor - width: parent.width - } - - Component.onCompleted: scaleBackground.updateScale() + width: 0.3 * map.width + } - Connections { - target: map.view - onTransformationChanged: scaleBackground.updateScale(); - } + Component.onCompleted: { + map.mapLoader.loadForCoordinate(49.44572, 11.08196); } onElementPicked: { elementDetailsSheet.element = element; elementDetailsSheet.sheetOpen = true; } } } }