Warning, /pim/itinerary/src/app/IndoorMapInfoSheetOpeningHoursDelegate.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003
0004 SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kopeninghours
0012 import org.kde.itinerary
0013
0014 ColumnLayout {
0015 id: root
0016 property var model
0017 property var mapData
0018
0019 property var oh: {
0020 var v = OpeningHoursParser.parse(model.value);
0021 v.region = root.mapData.regionCode;
0022 v.timeZone = root.mapData.timeZone;
0023 v.setLocation(root.mapData.center.y, root.mapData.center.x);
0024 if (v.error != OpeningHours.NoError) {
0025 console.log("Opening hours parsing error:", v.error, root.mapData.region, root.mapData.timeZone)
0026 }
0027 return v;
0028 }
0029
0030 QQC2.Label {
0031 property var currentInterval: root.oh.interval(new Date())
0032
0033 id: currentState
0034 text: intervalModel.currentState // TODO we could update this every minute
0035 color: {
0036 switch (currentInterval.state) {
0037 case Interval.Open: return Kirigami.Theme.positiveTextColor;
0038 case Interval.Closed: return Kirigami.Theme.negativeTextColor;
0039 default: return Kirigami.Theme.textColor;
0040 }
0041 }
0042 visible: text !== ""
0043 }
0044
0045 Component {
0046 id: intervalDelegate
0047 Item {
0048 id: delegateRoot
0049 property var dayData: model
0050 implicitHeight: row.implicitHeight
0051 Row {
0052 id: row
0053 QQC2.Label {
0054 text: dayData.shortDayName
0055 width: delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
0056 Component.onCompleted: delegateRoot.ListView.view.labelWidth = Math.max(delegateRoot.ListView.view.labelWidth, implicitWidth)
0057 font.bold: dayData.isToday
0058 }
0059 Repeater {
0060 model: dayData.intervals
0061 Rectangle {
0062 id: intervalBox
0063 property var interval: modelData
0064 property var closeColor: Kirigami.Theme.negativeBackgroundColor;
0065 color: {
0066 switch (interval.state) {
0067 case Interval.Open: return Kirigami.Theme.positiveBackgroundColor;
0068 case Interval.Closed: return intervalBox.closeColor;
0069 case Interval.Unknown: return Kirigami.Theme.neutralBackgroundColor;
0070 }
0071 return "transparent";
0072 }
0073 width: {
0074 var ratio = (interval.estimatedEnd - interval.begin + interval.dstOffset * 1000) / (24 * 60 * 60 * 1000);
0075 return ratio * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing);
0076 }
0077 height: Kirigami.Units.gridUnit
0078 gradient: Gradient {
0079 orientation: Gradient.Horizontal
0080 GradientStop { position: 0.0; color: intervalBox.color }
0081 GradientStop { position: (interval.end - interval.begin) / (interval.estimatedEnd - interval.begin); color: intervalBox.color }
0082 GradientStop { position: 1.0; color: interval.hasOpenEndTime ? intervalBox.closeColor : intervalBox.color }
0083 }
0084
0085 QQC2.Label {
0086 id: commentLabel
0087 text: interval.comment
0088 anchors.centerIn: parent
0089 visible: commentLabel.implicitWidth < intervalBox.width
0090 font.italic: true
0091 }
0092 }
0093 }
0094 }
0095 Rectangle {
0096 id: nowMarker
0097 property double position: (Date.now() - dayData.dayBegin) / (24 * 60 * 60 * 1000)
0098 visible: position >= 0.0 && position < 1.0
0099 color: Kirigami.Theme.textColor
0100 width: 2
0101 height: Kirigami.Units.gridUnit
0102 x: position * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing)
0103 + delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
0104 }
0105 }
0106 }
0107
0108 IntervalModel {
0109 id: intervalModel
0110 openingHours: root.oh
0111 // TODO we could use the layover time here, if available and in the future
0112 beginDate: intervalModel.beginOfWeek(new Date())
0113 endDate: new Date(intervalModel.beginDate.getTime() + 7 * 24 * 3600 * 1000)
0114 }
0115
0116 FontMetrics {
0117 id: fm
0118 }
0119
0120 ListView {
0121 id: intervalView
0122 width: parent.width
0123 height: contentHeight
0124 boundsBehavior: Flickable.StopAtBounds
0125 visible: root.oh.error == OpeningHours.NoError
0126 model: intervalModel
0127 delegate: intervalDelegate
0128 property int labelWidth: 0
0129 spacing: Kirigami.Units.smallSpacing
0130 clip: true
0131 header: Row {
0132 id: intervalHeader
0133 property int colCount: (intervalView.width - Kirigami.Units.smallSpacing - intervalView.labelWidth) / fm.advanceWidth(intervalModel.formatTimeColumnHeader(12, 59)) < 8 ? 4 : 8
0134 property int itemWidth: (intervalHeader.ListView.view.width - intervalHeader.ListView.view.labelWidth - Kirigami.Units.smallSpacing) / colCount
0135 x: intervalHeader.ListView.view.labelWidth + Kirigami.Units.smallSpacing + intervalHeader.itemWidth/2
0136 Repeater {
0137 // TODO we might need to use less when space constrained horizontally
0138 model: colCount - 1
0139 QQC2.Label {
0140 text: intervalModel.formatTimeColumnHeader((modelData + 1) * 24/colCount, 0)
0141 width: intervalHeader.itemWidth
0142 horizontalAlignment: Qt.AlignHCenter
0143 }
0144 }
0145 }
0146 }
0147
0148 QQC2.Label {
0149 id: fallbackLabel
0150 visible: !intervalView.visible
0151 text: model.value.replace(/;\s*/g, "\n")
0152 }
0153 }