Commit aa81008a authored by Volker Krause's avatar Volker Krause
Browse files

Initial integration of KOpeningHours in the OSM element info sheet

This is conditional on its availability for now, as it still has to go
through review and has to be included in the release service.

There's also still some more work needed to properly localize everything
in there.
parent a2ecb644
......@@ -14,6 +14,7 @@ import org.kde.itinerary 1.0
Kirigami.OverlaySheet {
id: elementDetailsSheet
property var model
property var mapData
header: Column {
Kirigami.Heading {
......@@ -27,6 +28,7 @@ Kirigami.OverlaySheet {
}
ListView {
id: contentView
model: elementDetailsSheet.model
Component {
......@@ -73,11 +75,16 @@ Kirigami.OverlaySheet {
}
}
// TODO remove the conditional use once we can hard-depend on KOpeningHours
property bool hasOpeningHoursSupport: Qt.createQmlObject('import QtQml 2.0; import org.kde.kopeninghours 1.0; QtObject{}', contentView, "opening hour availability probe") != null
Component {
id: infoOpeningHoursDelegate
// TODO this is temporary until we have a proper parser and UI for this
QQC2.Label {
text: row.value.includes(";") ? row.keyLabel + ":\n " + row.value.replace(/;\s*/g, "\n ") : row.keyLabel + ": " + row.value
Loader {
source: "IndoorMapInfoSheetOpeningHoursDelegate.qml"
onLoaded: {
item.mapData = elementDetailsSheet.mapData;
item.model = row;
}
}
}
......@@ -104,7 +111,7 @@ Kirigami.OverlaySheet {
case OSMElementInformationModel.PostalAddress:
return infoAddressDelegate;
case OSMElementInformationModel.OpeningHoursType:
return infoOpeningHoursDelegate;
return contentView.hasOpeningHoursSupport ? infoOpeningHoursDelegate : infoStringDelegate;
case OSMElementInformationModel.String:
default:
return infoStringDelegate;
......
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.7 as Kirigami
import org.kde.kopeninghours 1.0
import org.kde.itinerary 1.0
Column {
id: root
property var model
property var mapData
property var oh: {
var v = OpeningHoursParser.parse(model.value);
v.region = root.mapData.regionCode;
v.timeZone = root.mapData.timeZone;
v.setLocation(root.mapData.center.y, root.mapData.center.x);
if (v.error != OpeningHours.NoError) {
console.log("Opening hours parsing error:", v.error, root.mapData.region, root.mapData.timeZone)
}
return v;
}
QQC2.Label {
property var currentInterval: root.oh.interval(new Date())
id: currentState
text: {
if (oh.error != OpeningHours.NoError) {
return "";
}
/* TODO if (i.end) Math.round((i.end - Date.now())/60000) + " more minutes."; */
switch (currentInterval.state) {
case Interval.Open:
return "Currently open";
break;
case Interval.Closed:
return "Currently closed";
break;
case Interval.Unknown:
case Interval.Invalid:
return "";
}
}
color: {
switch (currentInterval.state) {
case Interval.Open: return Kirigami.Theme.positiveTextColor;
case Interval.Closed: return Kirigami.Theme.negativeTextColor;
default: return Kirigami.Theme.textColor;
}
}
visible: text !== ""
}
Component {
id: intervalDelegate
Item {
id: delegateRoot
property var dayData: model
implicitHeight: row.implicitHeight
Row {
id: row
QQC2.Label {
text: dayData.display
width: delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
Component.onCompleted: delegateRoot.ListView.view.labelWidth = Math.max(delegateRoot.ListView.view.labelWidth, implicitWidth)
}
Repeater {
model: dayData.intervals
Rectangle {
id: intervalBox
property var interval: modelData
color: {
switch (interval.state) {
case Interval.Open: return Kirigami.Theme.positiveBackgroundColor;
case Interval.Closed: return Kirigami.Theme.negativeBackgroundColor;
case Interval.Unknown: return Kirigami.Theme.neutralBackgroundColor;
}
return "transparent";
}
width: {
var ratio = (interval.end - interval.begin) / (24 * 60 * 60 * 1000);
return ratio * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing);
}
height: Kirigami.Units.gridUnit
QQC2.Label {
id: commentLabel
text: interval.comment
anchors.centerIn: parent
visible: commentLabel.implicitWidth < intervalBox.width
font.italic: true
}
}
}
}
Rectangle {
id: nowMarker
property double position: (Date.now() - dayData.dayBegin) / (24 * 60 * 60 * 1000)
visible: position >= 0.0 && position < 1.0
color: Kirigami.Theme.textColor
width: 2
height: Kirigami.Units.gridUnit
x: position * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing)
+ delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
}
}
}
IntervalModel {
id: intervalModel
openingHours: root.oh
}
ListView {
id: intervalView
width: parent.width
height: contentHeight
boundsBehavior: Flickable.StopAtBounds
visible: root.oh.error == OpeningHours.NoError
model: intervalModel
delegate: intervalDelegate
property int labelWidth: 0
spacing: Kirigami.Units.smallSpacing
clip: true
header: Row {
id: intervalHeader
property int itemWidth: (intervalHeader.ListView.view.width - intervalHeader.ListView.view.labelWidth - Kirigami.Units.smallSpacing) / 8
x: intervalHeader.ListView.view.labelWidth + Kirigami.Units.smallSpacing + intervalHeader.itemWidth/2
Repeater {
model: [3, 6, 9, 12, 15, 18, 21]
QQC2.Label {
text: modelData + ":00" // TODO
width: intervalHeader.itemWidth
horizontalAlignment: Qt.AlignHCenter
}
}
}
}
QQC2.Label {
id: fallbackLabel
visible: !intervalView.visible
text: model.value.replace(/;\s*/g, "\n")
}
}
......@@ -123,6 +123,7 @@ Kirigami.Page {
IndoorMapInfoSheet {
id: elementDetailsSheet
model: infoModel
mapData: map.mapData
}
PlatformModel {
......
......@@ -34,6 +34,7 @@
<file>IndoorMapElevatorSheet.qml</file>
<file>IndoorMapGateSheet.qml</file>
<file>IndoorMapInfoSheet.qml</file>
<file>IndoorMapInfoSheetOpeningHoursDelegate.qml</file>
<file>IndoorMapPage.qml</file>
<file>IndoorMapPlatformSheet.qml</file>
<file>JourneyDelegateHeader.qml</file>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment