KOSMIndoorMap

OSMElementInformationDialog.qml
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6import QtQuick
7import QtQuick.Layouts
8import QtQuick.Controls as QQC2
9import QtQuick.Templates as T
10import org.kde.kirigami as Kirigami
11import org.kde.kosmindoormap
12
13/** Dialog showing detailed information about a specific OSM element.
14 * Level of detail depends on what is tagged in the OSM data.
15 */
16Kirigami.Dialog {
17 id: root
18
19 /** OSMElementInformationModel instance for the element to show. */
20 required property var model
21 /** Fallback ISO 3166-1/2 region code for interpretting opening hours. */
22 required property string regionCode
23 /** Fallback IANA time zone id for interpretting opening hours. */
24 required property string timeZone
25
26 width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
27 height: Math.min(applicationWindow().height, Kirigami.Units.gridUnit * 32)
28
29 // see Kirigami.Dialog
30 header: T.Control {
31 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
32 implicitContentWidth + leftPadding + rightPadding)
33 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
34 implicitContentHeight + topPadding + bottomPadding)
35
36 padding: Kirigami.Units.largeSpacing
37 bottomPadding: verticalPadding + headerSeparator.implicitHeight // add space for bottom separator
38
39 Kirigami.Theme.colorSet: Kirigami.Theme.Header
40
41 contentItem: GridLayout {
42 rowSpacing: Kirigami.Units.smallSpacing
43 columnSpacing: Kirigami.Units.smallSpacing
44
45 Kirigami.Heading {
46 Layout.row: 0
47 Layout.column: 0
48 Layout.fillWidth: true
49 Layout.alignment: Qt.AlignVCenter
50 text: root.model.name
51 elide: Text.ElideRight
52
53 QQC2.ToolTip.visible: truncated && titleHoverHandler.hovered
54 QQC2.ToolTip.text: root.model.name
55 HoverHandler { id: titleHoverHandler }
56 }
57
58 Kirigami.Heading {
59 Layout.row: 1
60 Layout.column: 0
61 Layout.fillWidth: true
62 Layout.alignment: Qt.AlignVCenter
63 text: root.model.category
64 elide: Text.ElideRight
65 visible: root.model.category.length > 0
66 level: 4
67
68 QQC2.ToolTip.visible: truncated && subtitleHoverHandler.hovered
69 QQC2.ToolTip.text: root.model.category
70 HoverHandler { id: subtitleHoverHandler }
71 }
72
73 QQC2.ToolButton {
74 id: closeIcon
75 Layout.row: 0
76 Layout.column: 1
77 Layout.columnSpan: 2
78 Layout.alignment: Qt.AlignRight | Qt.AlignTop
79
80 visible: root.showCloseButton
81 icon.name: closeIcon.hovered ? "window-close" : "window-close-symbolic"
82 text: i18ndc("kosmindoormap", "@action:button close dialog", "Close")
83 onClicked: root.reject()
84 display: QQC2.AbstractButton.IconOnly
85 }
86 }
87
88 // header background
89 background: Item {
90 Kirigami.Separator {
91 id: headerSeparator
92 width: parent.width
93 anchors.bottom: parent.bottom
94 visible: contentControl.contentHeight > contentControl.implicitHeight
95 }
96 }
97 }
98
99 contentItem: ListView {
100 id: contentView
101 model: root.model
102 clip: true
103 Layout.preferredWidth: Kirigami.Units.gridUnit * 25
104
105 Kirigami.PlaceholderMessage {
106 visible: contentView.count === 0
107 text: i18nc("@info", "No information available")
108 anchors.centerIn: parent
109 }
110
111 Component {
112 id: infoStringDelegate
114 x: Kirigami.Units.largeSpacing
115 width: parent.ListView.view.width - 2 * x
116 keyLabel: row?.keyLabel ?? ""
117 value: row?.value ?? ""
118 category: row?.category ?? -1
119 }
120 }
121
122 Component {
123 id: infoLinkDelegate
125 x: Kirigami.Units.largeSpacing
126 width: parent.ListView.view.width - 2 * x
127 keyLabel: row?.keyLabel ?? ""
128 value: row?.value ?? ""
129 category: row?.category ?? -1
130 url: row?.url ?? ""
131 }
132 }
133
134 Component {
135 id: infoAddressDelegate
137 x: Kirigami.Units.largeSpacing
138 width: parent.ListView.view.width - 2 * x
139 address: row?.value ?? ""
140 }
141 }
142
143 Component {
144 id: infoOpeningHoursDelegate
146 x: Kirigami.Units.largeSpacing
147 width: parent.ListView.view.width - 2 * x
148 regionCode: root.regionCode
149 timeZoneId: root.timeZone
150 latitude: root.model.element?.center.y ?? NaN
151 longitude: root.model.element?.center.x ?? NaN
152 openingHours: row?.value ?? ""
153 }
154 }
155
156 Component {
157 id: infoImageDelegate
159 // logos needs margings, images can be shown full width
160 x: (row?.key === OSMElementInformationModel.Logo ?? false) ? Kirigami.Units.largeSpacing : 0
161 width: parent.ListView.view.width - 2 * x
162 source: row?.value ?? ""
163 url: row?.url ?? ""
164 maximumHeight: (row?.key === OSMElementInformationModel.Logo ?? false) ? Kirigami.Units.gridUnit * 6 : implicitHeight
165 topMargin: x
166 bottomMargin: x
167 }
168 }
169
170 section.property: "categoryLabel"
171 section.delegate: Kirigami.Heading {
172 x: Kirigami.Units.largeSpacing
173 level: 4
174 text: section
175 color: section == "Debug" ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
176 height: implicitHeight + Kirigami.Units.largeSpacing
177 verticalAlignment: Qt.AlignBottom
178 }
179 section.criteria: ViewSection.FullString
180 section.labelPositioning: ViewSection.InlineLabels
181
182 delegate: Loader {
183 property var row: model
184 sourceComponent: {
185 switch (row.type) {
186 case OSMElementInformationModel.Link:
187 return infoLinkDelegate;
188 case OSMElementInformationModel.PostalAddress:
189 return infoAddressDelegate;
190 case OSMElementInformationModel.OpeningHoursType:
191 return infoOpeningHoursDelegate;
192 case OSMElementInformationModel.ImageType:
193 return infoImageDelegate;
194 case OSMElementInformationModel.String:
195 default:
196 return infoStringDelegate;
197 }
198 }
199 }
200 }
201
202 onClosed: root.model.clear()
203}
OSM element info dialog delegate for graphically displaying link entries.
Delegate for showing images and logos in the OSM element information dialog.
OSM element info dialog delegate for graphically displaying link entries.
OSM element info dialog delegate for graphically displaying opening hours.
OSM element info dialog delegate for graphically displaying textual entries.
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
PostalAddress address(const QVariant &location)
QStringView level(QStringView ifopt)
Category category(StandardShortcut id)
AlignBottom
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.