Warning, /libraries/kpublictransport/tests/VehicleLayoutPage.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.kpublictransport as KPublicTransport
0012 import org.kde.kpublictransport.ui
0013
0014 Kirigami.ScrollablePage {
0015 id: root
0016 title: "Vehicle Layout"
0017
0018 property alias publicTransportManager: vehicleModel.manager
0019 property var departure
0020
0021 onDepartureChanged: vehicleModel.request.stopover = root.departure;
0022
0023 KPublicTransport.VehicleLayoutQueryModel {
0024 id: vehicleModel
0025
0026 onContentChanged: {
0027 var offset = vehicleView.fullLength * vehicleModel.vehicle.platformPositionBegin;
0028 offset -= Kirigami.Units.iconSizes.small + Kirigami.Units.largeSpacing; // direction indicator
0029 root.flickable.contentY = offset;
0030 }
0031 }
0032
0033 header: Column {
0034 QQC2.Label {
0035 text: vehicleModel.stopover.stopPoint.name + " - " + vehicleModel.stopover.route.line.name + " - "
0036 + (vehicleModel.stopover.scheduledDepartureTime > 0 ? vehicleModel.stopover.scheduledDepartureTime : vehicleModel.stopover.scheduledArrivalTime)
0037 leftPadding: Kirigami.Units.largeSpacing
0038 topPadding: Kirigami.Units.largeSpacing
0039 }
0040 QQC2.Label {
0041 text: "Platform: " + vehicleModel.platform.name
0042 leftPadding: Kirigami.Units.largeSpacing
0043 }
0044 }
0045
0046 Item {
0047 width: parent.width
0048 height: childrenRect.height
0049
0050 Column {
0051 id: contentLayout
0052 width: parent.width
0053
0054 Repeater {
0055 id: vehicleView
0056 property real fullLength: 1600 // full length of the platform display
0057 property real sectionWidth: 48
0058
0059 model: vehicleModel.platform.sections
0060 delegate: Item {
0061 property var section: modelData
0062 width: parent.width
0063 height: (section.end - section.begin) * vehicleView.fullLength
0064
0065 Kirigami.Separator {
0066 visible: index == 0
0067 anchors { top: parent.top; left: parent.left; right: parent.right }
0068 }
0069 QQC2.Label {
0070 anchors.centerIn: parent
0071 text: section.name
0072 }
0073 Kirigami.Separator {
0074 anchors { bottom: parent.bottom; left: parent.left; right: parent.right }
0075 }
0076 }
0077 }
0078 }
0079
0080 Kirigami.Icon {
0081 visible: vehicleModel.vehicle.direction != KPublicTransport.Vehicle.UnknownDirection
0082 source: {
0083 if (vehicleModel.vehicle.direction == KPublicTransport.Vehicle.Forward)
0084 return "go-up";
0085 if (vehicleModel.vehicle.direction == KPublicTransport.Vehicle.Backward)
0086 return "go-down"
0087 return "";
0088 }
0089 width: Kirigami.Units.iconSizes.small
0090 height: width
0091 x: vehicleView.sectionWidth / 2 - width / 2
0092 y: vehicleModel.vehicle.platformPositionBegin * vehicleView.fullLength - height - Kirigami.Units.largeSpacing
0093 }
0094
0095 Repeater {
0096 id: vehicleRepeater
0097 Layout.fillWidth: true
0098 model: vehicleModel
0099 delegate: VehicleSectionItem {
0100 section: model.vehicleSection
0101 y: section.platformPositionBegin * vehicleView.fullLength
0102 height: section.platformPositionEnd * vehicleView.fullLength - y
0103 width: vehicleView.sectionWidth
0104 textColor: Kirigami.Theme.textColor
0105 firstClassBackground: Kirigami.Theme.positiveTextColor
0106 secondClassBackground: Kirigami.Theme.focusColor
0107 inaccessibleBackground: Kirigami.Theme.disabledTextColor
0108 restaurantBackground: Kirigami.Theme.neutralTextColor
0109
0110 QQC2.Label {
0111 anchors.centerIn: parent
0112 text: section.name
0113 }
0114
0115 ColumnLayout {
0116 anchors.verticalCenter: parent.verticalCenter
0117 anchors.left: parent.right
0118 anchors.leftMargin: Kirigami.Units.largeSpacing
0119 spacing: Kirigami.Units.smallSpacing
0120
0121 RowLayout {
0122 spacing: Kirigami.Units.smallSpacing
0123 Repeater {
0124 model: section.featureList
0125 QQC2.Label {
0126 text: {
0127 switch (modelData) {
0128 case KPublicTransport.VehicleSection.AirConditioning: return "❄️";
0129 case KPublicTransport.VehicleSection.Restaurant: return "🍴";
0130 case KPublicTransport.VehicleSection.ToddlerArea: return "👶";
0131 case KPublicTransport.VehicleSection.WheelchairAccessible: return "♿";
0132 case KPublicTransport.VehicleSection.SilentArea: return "🔇";
0133 case KPublicTransport.VehicleSection.BikeStorage: return "🚲";
0134 }
0135 }
0136 }
0137 }
0138 }
0139 QQC2.Label {
0140 visible: section.classes != KPublicTransport.VehicleSection.UnknownClass
0141 text: {
0142 if (section.classes == KPublicTransport.VehicleSection.FirstClass)
0143 return "First class";
0144 if (section.classes == KPublicTransport.VehicleSection.SecondClass)
0145 return "Second class";
0146 if (section.classes == (KPublicTransport.VehicleSection.FirstClass | KPublicTransport.VehicleSection.SecondClass))
0147 return "First/second class";
0148 return "Unknown class";
0149 }
0150 }
0151 QQC2.Label {
0152 visible: section.type == KPublicTransport.VehicleSection.SleepingCar || section.type == KPublicTransport.VehicleSection.CouchetteCar
0153 text: section.type == KPublicTransport.VehicleSection.SleepingCar ? "Sleeping car" : "Couchette car"
0154 }
0155 }
0156 }
0157 }
0158
0159 Kirigami.Icon {
0160 visible: vehicleModel.vehicle.direction != KPublicTransport.Vehicle.UnknownDirection
0161 source: {
0162 if (vehicleModel.vehicle.direction == KPublicTransport.Vehicle.Forward)
0163 return "go-up";
0164 if (vehicleModel.vehicle.direction == KPublicTransport.Vehicle.Backward)
0165 return "go-down"
0166 return "";
0167 }
0168 width: Kirigami.Units.iconSizes.small
0169 height: width
0170 x: vehicleView.sectionWidth / 2 - width / 2
0171 y: vehicleModel.vehicle.platformPositionEnd * vehicleView.fullLength + Kirigami.Units.largeSpacing
0172 }
0173
0174 QQC2.BusyIndicator {
0175 anchors.centerIn: contentLayout
0176 running: vehicleModel.loading
0177 }
0178
0179 QQC2.Label {
0180 anchors.centerIn: contentLayout
0181 width: parent.width
0182 text: vehicleModel.errorMessage
0183 color: Kirigami.Theme.negativeTextColor
0184 wrapMode: Text.Wrap
0185 horizontalAlignment: Text.AlignHCenter
0186 }
0187
0188 QQC2.Label {
0189 anchors.centerIn: contentLayout
0190 width: parent.width
0191 visible: vehicleModel.errorMessage === "" && !vehicleModel.loading && vehicleRepeater.count === 0
0192 wrapMode: Text.Wrap
0193 horizontalAlignment: Text.AlignHCenter
0194 text: "No vehicle layout information available."
0195 }
0196 }
0197
0198 Component.onCompleted: contentItem.clip = true
0199 }