diff --git a/src/map-quick/mapitem.cpp b/src/map-quick/mapitem.cpp index 3152c93..0ed699f 100644 --- a/src/map-quick/mapitem.cpp +++ b/src/map-quick/mapitem.cpp @@ -1,120 +1,128 @@ /* 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 . */ #include "mapitem.h" #include #include #include +#include #include +#include using namespace KOSMIndoorMap; MapItem::MapItem(QQuickItem *parent) : QQuickPaintedItem(parent) , m_loader(new MapLoader(this)) , m_view(new View(this)) , m_floorLevelModel(new FloorLevelModel(this)) { connect(m_loader, &MapLoader::done, this, &MapItem::loaderDone); m_view->setScreenSize({100, 100}); // FIXME this breaks view when done too late! m_controller.setView(m_view); connect(m_view, &View::floorLevelChanged, this, [this]() { update(); }); + + if (QGuiApplication::palette().base().color().value() > 128) { + setStylesheetName(QStringLiteral(":/org.kde.kosmindoormap/assets/css/breeze-light.mapcss")); + } else { + setStylesheetName(QStringLiteral(":/org.kde.kosmindoormap/assets/css/breeze-dark.mapcss")); + } } MapItem::~MapItem() = default; void MapItem::paint(QPainter *painter) { m_controller.updateScene(m_sg); m_renderer.setPainter(painter); m_renderer.render(m_sg, m_view); } MapLoader* MapItem::loader() const { return m_loader; } View* MapItem::view() const { return m_view; } QString MapItem::styleSheetName() const { return m_styleSheetName; } void MapItem::setStylesheetName(const QString &styleSheet) { if (m_styleSheetName == styleSheet) { return; } m_styleSheetName = styleSheet; MapCSSParser cssParser; m_style = cssParser.parse(m_styleSheetName); m_style.compile(m_data.dataSet()); m_controller.setStyleSheet(&m_style); emit styleSheetChanged(); update(); } FloorLevelModel* MapItem::floorLevelModel() const { return m_floorLevelModel; } void MapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); m_view->setScreenSize(newGeometry.size().toSize()); qDebug() << newGeometry << m_view->zoomLevel(); } void MapItem::loaderDone() { m_floorLevelModel->setMapData(nullptr); m_sg.clear(); m_data = m_loader->takeData(); m_view->setSceneBoundingBox(m_data.boundingBox()); m_controller.setDataSet(&m_data); m_style.compile(m_data.dataSet()); m_controller.setStyleSheet(&m_style); m_view->setLevel(0); m_floorLevelModel->setMapData(&m_data); m_view->floorLevelChanged(); update(); } OSMElement MapItem::elementAt(double x, double y) const { HitDetector detector; const auto item = detector.itemAt(QPointF(x, y), m_sg, m_view); if (item) { qDebug() << item->element.url(); for (auto it = item->element.tagsBegin(); it != item->element.tagsEnd(); ++it) { qDebug() << " " << (*it).key.name() << (*it).value; } return OSMElement(item->element); } return {}; } diff --git a/tests/indoormap.qml b/tests/indoormap.qml index 4f016cc..c630619 100644 --- a/tests/indoormap.qml +++ b/tests/indoormap.qml @@ -1,153 +1,152 @@ /* 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" IndoorMapScale { view: map.view anchors.left: map.left anchors.bottom: map.bottom width: 0.3 * map.width } Component.onCompleted: { map.mapLoader.loadForCoordinate(49.44572, 11.08196); } onElementPicked: { elementDetailsSheet.element = element; elementDetailsSheet.sheetOpen = true; } } } }