KOSMIndoorMap

IndoorMapInfoSheetOpeningHoursDelegate.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.Layouts
9import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
11import org.kde.kopeninghours
12
13ColumnLayout {
14 id: root
15 property var model
16 property var mapData
17
18 property var oh: {
19 var v = OpeningHoursParser.parse(model.value);
20 v.region = root.mapData.regionCode;
21 v.timeZone = root.mapData.timeZone;
22 v.setLocation(root.mapData.center.y, root.mapData.center.x);
23 if (v.error != OpeningHours.NoError) {
24 console.log("Opening hours parsing error:", v.error, root.mapData.region, root.mapData.timeZone)
25 }
26 return v;
27 }
28
29 QQC2.Label {
30 property var currentInterval: root.oh.interval(new Date())
31
32 id: currentState
33 text: intervalModel.currentState // TODO we could update this every minute
34 color: {
35 switch (currentInterval.state) {
36 case Interval.Open: return Kirigami.Theme.positiveTextColor;
37 case Interval.Closed: return Kirigami.Theme.negativeTextColor;
38 default: return Kirigami.Theme.textColor;
39 }
40 }
41 visible: text !== ""
42 }
43
44 Component {
45 id: intervalDelegate
46 Item {
47 id: delegateRoot
48 property var dayData: model
49 implicitHeight: row.implicitHeight
50 Row {
51 id: row
52 QQC2.Label {
53 text: dayData.shortDayName
54 width: delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
55 Component.onCompleted: delegateRoot.ListView.view.labelWidth = Math.max(delegateRoot.ListView.view.labelWidth, implicitWidth)
56 font.bold: dayData.isToday
57 }
58 Repeater {
59 model: dayData.intervals
60 Rectangle {
61 id: intervalBox
62 property var interval: modelData
63 property var closeColor: Kirigami.Theme.negativeBackgroundColor;
64 color: {
65 switch (interval.state) {
66 case Interval.Open: return Kirigami.Theme.positiveBackgroundColor;
67 case Interval.Closed: return intervalBox.closeColor;
68 case Interval.Unknown: return Kirigami.Theme.neutralBackgroundColor;
69 }
70 return "transparent";
71 }
72 width: {
73 var ratio = (interval.estimatedEnd - interval.begin) / (24 * 60 * 60 * 1000);
74 return ratio * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing);
75 }
76 height: Kirigami.Units.gridUnit
77 gradient: Gradient {
78 orientation: Gradient.Horizontal
79 GradientStop { position: 0.0; color: intervalBox.color }
80 GradientStop { position: (interval.end - interval.begin) / (interval.estimatedEnd - interval.begin); color: intervalBox.color }
81 GradientStop { position: 1.0; color: interval.hasOpenEndTime ? intervalBox.closeColor : intervalBox.color }
82 }
83
84 QQC2.Label {
85 id: commentLabel
86 text: interval.comment
87 anchors.centerIn: parent
88 visible: commentLabel.implicitWidth < intervalBox.width
89 font.italic: true
90 }
91 }
92 }
93 }
94 Rectangle {
95 id: nowMarker
96 property double position: (Date.now() - dayData.dayBegin) / (24 * 60 * 60 * 1000)
97 visible: position >= 0.0 && position < 1.0
98 color: Kirigami.Theme.textColor
99 width: 2
100 height: Kirigami.Units.gridUnit
101 x: position * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing)
102 + delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
103 }
104 }
105 }
106
107 IntervalModel {
108 id: intervalModel
109 openingHours: root.oh
110 // TODO we could use the layover time here, if available and in the future
111 beginDate: intervalModel.beginOfWeek(new Date())
112 endDate: new Date(intervalModel.beginDate.getTime() + 7 * 24 * 3600 * 1000)
113 }
114
115 FontMetrics {
116 id: fm
117 }
118
119 ListView {
120 id: intervalView
121 width: parent.width
122 height: contentHeight
123 boundsBehavior: Flickable.StopAtBounds
124 visible: root.oh.error == OpeningHours.NoError
125 model: intervalModel
126 delegate: intervalDelegate
127 property int labelWidth: 0
128 spacing: Kirigami.Units.smallSpacing
129 clip: true
130 header: Row {
131 id: intervalHeader
132 property int colCount: (intervalView.width - Kirigami.Units.smallSpacing - intervalView.labelWidth) / fm.advanceWidth(intervalModel.formatTimeColumnHeader(12, 59)) < 8 ? 4 : 8
133 property int itemWidth: (intervalHeader.ListView.view.width - intervalHeader.ListView.view.labelWidth - Kirigami.Units.smallSpacing) / colCount
134 x: intervalHeader.ListView.view.labelWidth + Kirigami.Units.smallSpacing + intervalHeader.itemWidth/2
135 Repeater {
136 // TODO we might need to use less when space constrained horizontally
137 model: colCount - 1
138 QQC2.Label {
139 text: intervalModel.formatTimeColumnHeader((modelData + 1) * 24/colCount, 0)
140 width: intervalHeader.itemWidth
141 horizontalAlignment: Qt.AlignHCenter
142 }
143 }
144 }
145 }
146
147 QQC2.Label {
148 id: fallbackLabel
149 visible: !intervalView.visible
150 text: model.value.replace(/;\s*/g, "\n")
151 }
152}
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
const QList< QKeySequence > & replace()
AlignHCenter
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.