Warning, /pim/itinerary/src/app/DepartureQueryPage.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2019 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.kirigamiaddons.formcard as FormCard
0012 import org.kde.kpublictransport
0013 import org.kde.itinerary
0014
0015 Kirigami.ScrollablePage {
0016 id: root
0017
0018 property var stop
0019 property var dateTime
0020
0021 title: i18n("Departures")
0022 actions: [
0023 Kirigami.Action {
0024 text: i18n("Earlier")
0025 icon.name: "go-up-symbolic"
0026 onTriggered: departureModel.queryPrevious()
0027 enabled: departureModel.canQueryPrevious
0028 },
0029 Kirigami.Action {
0030 text: i18n("Later")
0031 icon.name: "go-down-symbolic"
0032 onTriggered: departureModel.queryNext()
0033 enabled: departureModel.canQueryNext
0034 },
0035
0036 Kirigami.Action { separator: true },
0037
0038 Kirigami.Action {
0039 id: longDistanceModeAction
0040 text: i18nc("journey query search constraint, title", "Long distance trains")
0041 icon.source: PublicTransport.lineModeIcon(Line.LongDistanceTrain)
0042 checkable: true
0043 checked: true
0044 },
0045 Kirigami.Action {
0046 id: localTrainModeAction
0047 text: i18nc("journey query search constraint, title", "Local trains")
0048 icon.source: PublicTransport.lineModeIcon(Line.LocalTrain)
0049 checkable: true
0050 checked: true
0051 },
0052 Kirigami.Action {
0053 id: rapidTransitModeAction
0054 text: i18nc("journey query search constraint, title", "Rapid transit")
0055 icon.source: PublicTransport.lineModeIcon(Line.Tramway)
0056 checkable: true
0057 checked: true
0058 },
0059 Kirigami.Action {
0060 id: busModeAction
0061 text: i18nc("journey query search constraint, title", "Bus")
0062 icon.source: PublicTransport.lineModeIcon(Line.Bus)
0063 checkable: true
0064 checked: true
0065 },
0066 Kirigami.Action {
0067 id: ferryModeAction
0068 text: i18nc("journey query search constraint, title", "Ferry")
0069 icon.source: PublicTransport.lineModeIcon(Line.Ferry)
0070 checkable: true
0071 checked: true
0072 }
0073 ]
0074
0075 function allLineModes()
0076 {
0077 for (const s of [longDistanceModeAction, localTrainModeAction, rapidTransitModeAction, busModeAction, ferryModeAction]) {
0078 if (!s.checked) {
0079 return false;
0080 }
0081 }
0082 return true;
0083 }
0084
0085 function stopoverRequest()
0086 {
0087 let req = PublicTransport.stopoverRequestForPlace(stop, dateTime);
0088 let lineModes = [];
0089 if (!allLineModes()) {
0090 if (longDistanceModeAction.checked)
0091 lineModes.push(Line.LongDistanceTrain, Line.Train);
0092 if (localTrainModeAction.checked)
0093 lineModes.push(Line.LocalTrain);
0094 if (rapidTransitModeAction.checked)
0095 lineModes.push(Line.RapidTransit, Line.Metro, Line.Tramway, Line.RailShuttle);
0096 if (busModeAction.checked)
0097 lineModes.push(Line.Bus, Line.Coach);
0098 if (ferryModeAction.checked)
0099 lineModes.push(Line.Ferry, Line.Boat);
0100 }
0101 req.lineModes = lineModes;
0102 return req;
0103 }
0104
0105 StopoverQueryModel {
0106 id: departureModel
0107 manager: LiveDataManager.publicTransportManager
0108 request: stopoverRequest();
0109 }
0110
0111 Component {
0112 id: departureDelegate
0113 FormCard.FormCard {
0114 id: top
0115 required property var departure
0116 width: ListView.view.width
0117
0118 FormCard.AbstractFormDelegate {
0119 contentItem: GridLayout {
0120 id: contentLayout
0121 columns: 2
0122
0123 // top row: departure time, departure location, departure platform
0124 RowLayout {
0125 QQC2.Label {
0126 text: Localizer.formatTime(departure, "scheduledDepartureTime")
0127 }
0128 QQC2.Label {
0129 text: {
0130 if (departure.disruption == Disruption.NoService)
0131 return i18nc("a train/bus journey canceled by its operator", "Canceled");
0132 return (departure.departureDelay >= 0 ? "+" : "") + departure.departureDelay;
0133 }
0134 color: {
0135 if (departure.departureDelay > 1 || departure.disruption == Disruption.NoService)
0136 return Kirigami.Theme.negativeTextColor;
0137 return Kirigami.Theme.positiveTextColor;
0138 }
0139 // Keeping it visible so the layout is more uniform
0140 opacity: (departure.hasExpectedDepartureTime || departure.disruption == Disruption.NoService) ? 1 : 0
0141 }
0142 }
0143 RowLayout {
0144 QQC2.Label {
0145 text: departure.stopPoint.name
0146 Layout.fillWidth: true
0147 elide: Text.ElideRight
0148 }
0149 QQC2.Label {
0150 text: departure.hasExpectedPlatform ? departure.expectedPlatform : departure.scheduledPlatform
0151 color: departure.departurePlatformChanged ? Kirigami.Theme.negativeTextColor
0152 : departure.hasExpectedPlatform ? Kirigami.Theme.positiveTextColor
0153 : Kirigami.Theme.textColor
0154 visible: departure.scheduledPlatform !== ""
0155 }
0156 }
0157
0158 // middle row: mode symbol, transport mode, duration
0159 Rectangle {
0160 color: (departure.route.line.hasColor && modeIcon.isMask) ? departure.route.line.color : "transparent"
0161 implicitHeight: Kirigami.Units.iconSizes.smallMedium
0162 implicitWidth: modeIcon.width
0163 Layout.alignment: Qt.AlignHCenter
0164
0165 Kirigami.Icon {
0166 id: modeIcon
0167 anchors.centerIn: parent
0168 source: PublicTransport.lineIcon(departure.route.line);
0169 color: departure.route.line.hasTextColor ? departure.route.line.textColor : Kirigami.Theme.textColor
0170 width: (departure.route.line.hasLogo || departure.route.line.hasModeLogo) ? implicitWidth : height
0171 height: parent.height
0172 isMask: !departure.route.line.hasLogo && !departure.route.line.hasModeLogo
0173 }
0174 }
0175 QQC2.Label {
0176 Layout.fillWidth: true
0177 text: departure.route.line.modeString + " " + departure.route.line.name;
0178 }
0179
0180 // last row: arrival information
0181 RowLayout {
0182 QQC2.Label {
0183 text: i18nc("destination", "To:")
0184 }
0185 }
0186 RowLayout {
0187 QQC2.Label {
0188 text: departure.route.direction
0189 Layout.fillWidth: true
0190 elide: Text.ElideRight
0191 }
0192 }
0193
0194 // optional bottom row: notes if present
0195 QQC2.Label {
0196 Layout.columnSpan: 2
0197 Layout.fillWidth: true
0198 text: departure.notes.join("<br/>")
0199 textFormat: Text.RichText
0200 wrapMode: Text.Wrap
0201 visible: departure.notes.length > 0
0202 font.italic: true
0203 onLinkActivated: Qt.openUrlExternally(link)
0204 }
0205 }
0206 }
0207 }
0208 }
0209
0210
0211 ListView {
0212 id: journeyView
0213 anchors.fill: parent
0214 clip: true
0215 delegate: departureDelegate
0216 model: departureModel
0217 spacing: Kirigami.Units.largeSpacing
0218
0219 header: VerticalNavigationButton {
0220 visible: departureModel.canQueryPrevious
0221 width: journeyView.width
0222 text: i18nc("@action:button", "Load earlier departures")
0223 iconName: "go-up-symbolic"
0224 onClicked: departureModel.queryPrevious()
0225 }
0226
0227 footer: VerticalNavigationButton {
0228 visible: departureModel.canQueryNext
0229 width: journeyView.width
0230 iconName: "go-down-symbolic"
0231 text: i18nc("@action:button", "Load later connections")
0232 onClicked: departureModel.queryNext()
0233
0234 FormCard.FormCard {
0235 visible: departureModel.attributions.length > 0
0236
0237 Layout.fillWidth: true
0238
0239 FormCard.FormTextDelegate {
0240 text: i18n("Data providers:")
0241 description: PublicTransport.attributionSummary(departureModel.attributions)
0242 onLinkActivated: Qt.openUrlExternally(link)
0243 }
0244 }
0245 }
0246
0247 QQC2.BusyIndicator {
0248 anchors.centerIn: parent
0249 running: departureModel.loading
0250 }
0251
0252 QQC2.Label {
0253 anchors.centerIn: parent
0254 width: parent.width
0255 text: departureModel.errorMessage
0256 color: Kirigami.Theme.negativeTextColor
0257 wrapMode: Text.Wrap
0258 }
0259 }
0260 }