Commit 0e3680ca authored by Volker Krause's avatar Volker Krause
Browse files

Bring the element info dialog in sync with KDE Itinerary

Most notably, this adds the opening hours display. We are missing localized
address formatting here though.
parent be5a8409
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.7 as Kirigami
import org.kde.kosmindoormap 1.0
Kirigami.OverlaySheet {
id: elementDetailsSheet
property var model
property var mapData
header: Column {
Kirigami.Heading {
text: elementDetailsSheet.model.name
}
Kirigami.Heading {
text: elementDetailsSheet.model.category
level: 4
visible: text != ""
}
}
ListView {
id: contentView
model: elementDetailsSheet.model
Component {
id: infoStringDelegate
RowLayout {
QQC2.Label {
visible: row && row.keyLabel != ""
text: row ? row.keyLabel + ":" : ""
color: (row && row.category == OSMElementInformationModel.DebugCategory) ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
Layout.alignment: Qt.AlignTop
}
QQC2.Label {
text: row ? row.value : ""
color: (row && row.category == OSMElementInformationModel.DebugCategory) ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
}
Component {
id: infoLinkDelegate
RowLayout {
QQC2.Label {
visible: row && row.keyLabel != ""
text: row ? row.keyLabel + ":" : ""
color: (row && row.category == OSMElementInformationModel.DebugCategory) ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
Layout.alignment: Qt.AlignTop
}
QQC2.Label {
text: row ? "<a href=\"" + row.url + "\">" + row.value + "</a>" : ""
color: (row && row.category == OSMElementInformationModel.DebugCategory) ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
onLinkActivated: Qt.openUrlExternally(link)
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
}
Component {
id: infoAddressDelegate
QQC2.Label {
text: (row.value.street + " " + row.value.houseNumber + "\n" + row.value.postalCode + " " + row.value.city + "\n" + row.value.country).trim()
}
}
Component {
id: infoOpeningHoursDelegate
IndoorMapInfoSheetOpeningHoursDelegate {
mapData: elementDetailsSheet.mapData
model: row
}
}
section.property: "categoryLabel"
section.delegate: Kirigami.Heading {
x: Kirigami.Units.largeSpacing
level: 4
text: section
color: section == "Debug" ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
height: implicitHeight + Kirigami.Units.largeSpacing
verticalAlignment: Qt.AlignBottom
}
section.criteria: ViewSection.FullString
section.labelPositioning: ViewSection.InlineLabels
delegate: Loader {
property var row: model
x: Kirigami.Units.largeSpacing
width: ListView.view.width - 2 * x
sourceComponent: {
switch (row.type) {
case OSMElementInformationModel.Link:
return infoLinkDelegate;
case OSMElementInformationModel.PostalAddress:
return infoAddressDelegate;
case OSMElementInformationModel.OpeningHoursType:
return infoOpeningHoursDelegate;
case OSMElementInformationModel.String:
default:
return infoStringDelegate;
}
}
}
}
onSheetOpenChanged: {
if (sheetOpen == false) {
elementDetailsSheet.model.clear()
}
}
}
/*
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
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: intervalModel.currentState // TODO we could update this every minute
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.shortDayName
width: delegateRoot.ListView.view.labelWidth + Kirigami.Units.smallSpacing
Component.onCompleted: delegateRoot.ListView.view.labelWidth = Math.max(delegateRoot.ListView.view.labelWidth, implicitWidth)
font.bold: dayData.isToday
}
Repeater {
model: dayData.intervals
Rectangle {
id: intervalBox
property var interval: modelData
property var closeColor: Kirigami.Theme.negativeBackgroundColor;
color: {
switch (interval.state) {
case Interval.Open: return Kirigami.Theme.positiveBackgroundColor;
case Interval.Closed: return intervalBox.closeColor;
case Interval.Unknown: return Kirigami.Theme.neutralBackgroundColor;
}
return "transparent";
}
width: {
var ratio = (interval.estimatedEnd - interval.begin) / (24 * 60 * 60 * 1000);
return ratio * (delegateRoot.ListView.view.width - delegateRoot.ListView.view.labelWidth - Kirigami.Units.smallSpacing);
}
height: Kirigami.Units.gridUnit
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 0.0; color: intervalBox.color }
GradientStop { position: (interval.end - interval.begin) / (interval.estimatedEnd - interval.begin); color: intervalBox.color }
GradientStop { position: 1.0; color: interval.hasOpenEndTime ? intervalBox.closeColor : intervalBox.color }
}
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
// TODO we could use the layover time here, if available and in the future
beginDate: intervalModel.beginOfWeek(new Date())
endDate: new Date(intervalModel.beginDate.getTime() + 7 * 24 * 3600 * 1000)
}
FontMetrics {
id: fm
}
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 colCount: (intervalView.width - Kirigami.Units.smallSpacing - intervalView.labelWidth) / fm.advanceWidth(intervalModel.formatTimeColumnHeader(12, 59)) < 8 ? 4 : 8
property int itemWidth: (intervalHeader.ListView.view.width - intervalHeader.ListView.view.labelWidth - Kirigami.Units.smallSpacing) / colCount
x: intervalHeader.ListView.view.labelWidth + Kirigami.Units.smallSpacing + intervalHeader.itemWidth/2
Repeater {
// TODO we might need to use less when space constrained horizontally
model: colCount - 1
QQC2.Label {
text: intervalModel.formatTimeColumnHeader((modelData + 1) * 24/colCount, 0)
width: intervalHeader.itemWidth
horizontalAlignment: Qt.AlignHCenter
}
}
}
}
QQC2.Label {
id: fallbackLabel
visible: !intervalView.visible
text: model.value.replace(/;\s*/g, "\n")
}
}
......@@ -43,94 +43,10 @@ Kirigami.Page {
debug: true
}
Component {
id: infoStringDelegate
Row {
QQC2.Label {
visible: row.keyLabel != ""
text: row.keyLabel + ": "
color: row.category == OSMElementInformationModel.DebugCategory ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
}
QQC2.Label {
text: row.value
color: row.category == OSMElementInformationModel.DebugCategory ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
}
}
}
Component {
id: infoLinkDelegate
Row {
QQC2.Label {
visible: row.keyLabel != ""
text: row.keyLabel + ": "
color: row.category == OSMElementInformationModel.DebugCategory ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
}
QQC2.Label {
text: "<a href=\"" + row.url + "\">" + row.value + "</a>"
color: row.category == OSMElementInformationModel.DebugCategory ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
onLinkActivated: Qt.openUrlExternally(link)
}
}
}
Component {
id: infoAddressDelegate
QQC2.Label {
text: (row.value.street + " " + row.value.houseNumber + "\n" + row.value.postalCode + " " + row.value.city + "\n" + row.value.country).trim()
}
}
Kirigami.OverlaySheet {
IndoorMapInfoSheet {
id: elementDetailsSheet
header: Column {
Kirigami.Heading {
text: infoModel.name
}
Kirigami.Heading {
text: infoModel.category
level: 4
visible: text != ""
}
}
ListView {
model: infoModel
section.property: "categoryLabel"
section.delegate: Kirigami.Heading {
x: Kirigami.Units.largeSpacing
level: 4
text: section
color: section == "Debug" ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
height: implicitHeight + Kirigami.Units.largeSpacing
verticalAlignment: Qt.AlignBottom
}
section.criteria: ViewSection.FullString
section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
delegate: Loader {
property var row: model
x: Kirigami.Units.largeSpacing
sourceComponent: {
switch (row.type) {
case OSMElementInformationModel.Link:
return infoLinkDelegate;
case OSMElementInformationModel.PostalAddress:
return infoAddressDelegate;
default:
return infoStringDelegate;
}
}
}
}
onSheetOpenChanged: {
if (sheetOpen == false) {
infoModel.clear()
}
}
model: infoModel
mapData: page.map.mapData
}
FloorLevelChangeModel {
......
......@@ -9,6 +9,8 @@
<file>indoormap.qml</file>
<file>AttributionPage.qml</file>
<file>ExampleLocationModel.qml</file>
<file>IndoorMapInfoSheet.qml</file>
<file>IndoorMapInfoSheetOpeningHoursDelegate.qml</file>
<file>IndoorMapPage.qml</file>
<file>SelectLocationSheet.qml</file>
</qresource>
......
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