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