Warning, /libraries/kpublictransport/src/quick/VehicleSectionItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020-2022 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.5
0008 import org.kde.kpublictransport 1.0
0009 import org.kde.kpublictransport.ui 1.0
0010 
0011 /** Displays a single vehicle section. */
0012 StyledFrameSvgItem {
0013     /** The vehicle section to show. */
0014     property var section
0015 
0016     /** Color to use for the outline/text. */
0017     property color textColor: "black"
0018     /** Background color to use in first class sections. */
0019     property color firstClassBackground: "green"
0020     /** Background color to use in second class sections. */
0021     property color secondClassBackground: "blue"
0022     /** Background color for inaccessible sections (engines, power cars, etc). */
0023     property color inaccessibleBackground: "gray"
0024     /** Background color for restaurant cars. */
0025     property color restaurantBackground: "orange"
0026 
0027     source: {
0028         var svgName = "passengercar";
0029         switch (section.type) {
0030             case VehicleSection.ControlCar:
0031             case VehicleSection.PowerCar:
0032                 svgName = "controlcar";
0033                 break;
0034             case VehicleSection.Engine:
0035                 svgName = "engine";
0036                 break;
0037         }
0038 
0039         switch (section.type) {
0040             case VehicleSection.PowerCar:
0041             case VehicleSection.ControlCar:
0042                 if (section.connectedSides == VehicleSection.Front) {
0043                     svgName += "-back";
0044                 } else {
0045                     svgName += "-front";
0046                 }
0047                 break;
0048         }
0049 
0050         if (section.deckCount > 1) {
0051             switch (section.type) {
0052                 case VehicleSection.PassengerCar:
0053                 case VehicleSection.RestaurantCar:
0054                 case VehicleSection.ControlCar:
0055                 case VehicleSection.SleepingCar:
0056                 case VehicleSection.CouchetteCar:
0057                 case VehicleSection.CarTransportCar:
0058                     svgName += "-double-deck";
0059                     break;
0060             }
0061         }
0062         return ":/org.kde.kpublictransport/ui/assets/" + svgName + ".svg";
0063     }
0064 
0065     backgroundColor: {
0066         switch (section.type) {
0067             case VehicleSection.Engine:
0068             case VehicleSection.PowerCar:
0069             case VehicleSection.CarTransportCar:
0070                 return inaccessibleBackground;
0071             case VehicleSection.RestaurantCar:
0072                 return restaurantBackground;
0073             case VehicleSection.PassengerCar:
0074             case VehicleSection.ControlCar:
0075             case VehicleSection.SleepingCar:
0076             case VehicleSection.CouchetteCar:
0077                 if (section.classes == VehicleSection.FirstClass)
0078                     return firstClassBackground;
0079                 else if (section.classes & VehicleSection.FirstClass)
0080                     return Qt.tint(secondClassBackground, Qt.rgba(firstClassBackground.r, firstClassBackground.g, firstClassBackground.b, 0.5));
0081         }
0082         return secondClassBackground;
0083     }
0084     lineColor: textColor
0085 
0086     borderTop: {
0087         switch (section.type) {
0088             case VehicleSection.PowerCar:
0089             case VehicleSection.ControlCar:
0090                 return section.connectedSides == VehicleSection.Front ? 12 : 36
0091             case VehicleSection.Engine:
0092                 return 22;
0093         }
0094         return 36;
0095     }
0096     borderBottom: 48 - borderTop - 2
0097 }