KOSMIndoorMap

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

KDE's Doxygen guidelines are available online.