Warning, /libraries/kosmindoormap/src/map-quick/IndoorMapScale.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 
0010 Item {
0011     id: root
0012     property var map
0013 
0014     implicitHeight: background.height
0015     visible: !map.mapLoader.isLoading && !map.hasError
0016 
0017     property int __margin: 2
0018 
0019     function updateScale() {
0020         var d = map.view.mapScreenToMeters(background.width - 2 * __margin);
0021         var s = d < 5 ? 1 : d < 20 ? 5 : d < 100 ? 10 : 20;
0022         d /= s;
0023         d = Math.floor(d);
0024         d *= s;
0025         scaleLabel.text = i18ndc("kosmindoormap", "length in meters", "%1 m", d)
0026         scale.width = map.view.mapMetersToScreen(d);
0027     }
0028 
0029     Rectangle {
0030         id: background
0031         color: scaleLabel.palette.base
0032         opacity: 0.5
0033         height: scaleLabel.implicitHeight + scale.height + 2 * root.__margin
0034         width: root.width
0035     }
0036 
0037     QQC2.Label {
0038         id: scaleLabel
0039         anchors.bottom: scale.top
0040         anchors.horizontalCenter: scale.horizontalCenter
0041     }
0042 
0043     Rectangle {
0044         id: scale
0045         anchors.bottom: root.bottom
0046         anchors.left: root.left
0047         anchors.margins: root.__margin
0048         height: 4
0049         color: scaleLabel.color
0050     }
0051 
0052     Component.onCompleted: root.updateScale()
0053 
0054     Connections {
0055         target: root.map.view
0056         function onTransformationChanged() { root.updateScale(); }
0057     }
0058     Connections {
0059         target: root
0060         function onWidthChanged() { root.updateScale(); }
0061     }
0062 }