KOSMIndoorMap

IndoorMapScale.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.Controls as QQC2
9
10Item {
11 id: root
12 property var map
13
14 implicitHeight: background.height
15 visible: !map.mapLoader.isLoading && !map.hasError
16
17 property int __margin: 2
18
19 function updateScale() {
20 var d = map.view.mapScreenToMeters(background.width - 2 * __margin);
21 var s = d < 5 ? 1 : d < 20 ? 5 : d < 100 ? 10 : 20;
22 d /= s;
23 d = Math.floor(d);
24 d *= s;
25 scaleLabel.text = i18ndc("kosmindoormap", "length in meters", "%1 m", d)
26 scale.width = map.view.mapMetersToScreen(d);
27 }
28
29 Rectangle {
30 id: background
31 color: scaleLabel.palette.base
32 opacity: 0.5
33 height: scaleLabel.implicitHeight + scale.height + 2 * root.__margin
34 width: root.width
35 }
36
37 QQC2.Label {
38 id: scaleLabel
39 anchors.bottom: scale.top
40 anchors.horizontalCenter: scale.horizontalCenter
41 }
42
43 Rectangle {
44 id: scale
45 anchors.bottom: root.bottom
46 anchors.left: root.left
47 anchors.margins: root.__margin
48 height: 4
49 color: scaleLabel.color
50 }
51
52 Component.onCompleted: root.updateScale()
53
54 Connections {
55 target: root.map.view
56 function onTransformationChanged() { root.updateScale(); }
57 }
58 Connections {
59 target: root
60 function onWidthChanged() { root.updateScale(); }
61 }
62}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
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 Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.