KOSMIndoorMap

AmenityListDelegate.qml
1/*
2 SPDX-FileCopyrightText: 2023 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 org.kde.kirigami as Kirigami
10import org.kde.kopeninghours
12/** Delegate for use on an AmenityModel. */
13QQC2.ItemDelegate {
14 id: root
15 required property string name
16 required property string typeName
17 required property string iconSource
18 required property string detailsLabel
19 required property string fallbackName
20 required property string openingHours
21 required property point coordinate
22 required property string timeZone
23 required property string regionCode
24
25 required property int index // for Kirigami
26
27 highlighted: false
28 width: ListView.view.width
29
30 property var oh: {
31 let v = OpeningHoursParser.parse(root.openingHours);
32 v.region = root.regionCode;
33 v.timeZone = root.timeZone;
34 v.setLocation(root.coordinate.y, root.coordinate.x);
35 if (v.error != OpeningHours.Null && v.error != OpeningHours.NoError) {
36 console.log("Opening hours parsing error:", root.openingHours, v.error, root.regionCode, root.timeZone)
37 }
38 return v;
39 }
40
41 contentItem: RowLayout {
42 spacing: Kirigami.Units.largeSpacing
43
44 Kirigami.Icon {
45 Layout.minimumHeight: Kirigami.Units.iconSizes.medium
46 Layout.maximumHeight: Kirigami.Units.iconSizes.medium
47 Layout.minimumWidth: Kirigami.Units.iconSizes.medium
48 Layout.maximumWidth: Kirigami.Units.iconSizes.medium
49 source: root.iconSource
50 isMask: true
51 }
52
53 ColumnLayout {
54 Layout.alignment: Qt.AlignVCenter
55 Layout.fillWidth: true
56 spacing: 0
57
58 QQC2.Label {
59 Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
60 Layout.fillWidth: true
61 text: root.name !== "" ? root.name : root.typeName
62 elide: Text.ElideRight
63 }
64
65 QQC2.Label {
66 Layout.alignment: Qt.AlignLeft | Qt.AlignTop
67 Layout.fillWidth: true
68 text: {
69 if (root.detailsLabel && root.name === "")
70 return root.detailsLabel;
71 if (root.detailsLabel)
72 return i18n("%1 (%2)", root.typeName, root.detailsLabel);
73 return root.name === "" && root.fallbackName !== "" ? root.fallbackName : root.typeName;
74 }
75 elide: Text.ElideRight
76 font: Kirigami.Theme.smallFont
77 opacity: 0.7
78 }
79
80 QQC2.Label {
81 Layout.fillWidth: true
82 text: Display.currentState(root.oh)
83 color: {
84 if (root.highlighted || root.checked || root.down)
85 return Kirigami.Theme.highlightedTextColor
86 const currentInterval = root.oh.interval(new Date());
87 switch (currentInterval.state) {
88 case Interval.Open: return Kirigami.Theme.positiveTextColor;
89 case Interval.Closed: return Kirigami.Theme.negativeTextColor;
90 default: return Kirigami.Theme.textColor;
91 }
92 }
93 elide: Text.ElideRight
94 font: Kirigami.Theme.smallFont
95 visible: text !== ""
96 }
97 }
98 }
99}
QString i18n(const char *text, const TYPE &arg...)
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.