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

Handle new KPublicTransport journey section modes

Also de-duplicate the mode icon QML logic while at it.
parent 65e449ac
......@@ -72,18 +72,7 @@ Kirigami.AbstractListItem {
Kirigami.Icon {
id: modeIcon
anchors.centerIn: parent
source: {
switch (modelData.mode) {
case JourneySection.PublicTransport:
return PublicTransport.lineIcon(modelData.route.line);
case JourneySection.Walking: return "qrc:///images/walk.svg";
case JourneySection.Waiting: return "qrc:///images/wait.svg";
case JourneySection.Transfer: return "qrc:///images/transfer.svg";
case JourneySection.RentedVehicle:
return PublicTransport.rentalVehicleIcon(modelData.rentalVehicle);
default: return "question";
}
}
source: PublicTransport.journeySectionIcon(modelData)
color: modelData.route.line.hasTextColor ? modelData.route.line.textColor : Kirigami.Theme.textColor
width: !isMask ? implicitWidth : height
height: parent.height
......@@ -113,6 +102,8 @@ Kirigami.AbstractListItem {
return i18n("Wait (%1)", Localizer.formatDuration(modelData.duration))
case JourneySection.RentedVehicle:
return i18n("%1 (%2)", modelData.rentalVehicle.network, Localizer.formatDuration(modelData.duration));
case JourneySection.IndividualTransport:
return i18n("Drive %1 (%2)", Localizer.formatDistance(modelData.distance), Localizer.formatDuration(modelData.duration));
return "???";
}}
color: PublicTransport.warnAboutSection(modelData) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.textColor
......
......@@ -40,18 +40,7 @@ RowLayout {
Repeater {
model: journey.sections
delegate: Kirigami.Icon {
source: {
switch (modelData.mode) {
case JourneySection.PublicTransport:
return PublicTransport.lineIcon(modelData.route.line);
case JourneySection.Walking: return "qrc:///images/walk.svg";
case JourneySection.Waiting: return "qrc:///images/wait.svg";
case JourneySection.Transfer: return "qrc:///images/transfer.svg";
case JourneySection.RentedVehicle:
return PublicTransport.rentalVehicleIcon(modelData.rentalVehicle);
default: return "question";
}
}
source: PublicTransport.journeySectionIcon(modelData)
color: PublicTransport.warnAboutSection(modelData) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.textColor
width: isMask ? height : implicitWidth
height: Kirigami.Units.iconSizes.small
......
......@@ -162,6 +162,45 @@ QString PublicTransport::rentalVehicleIcon(const KPublicTransport::RentalVehicle
return QStringLiteral("question");
}
static QString individualTransportIcon(const KPublicTransport::IndividualTransport &it)
{
using namespace KPublicTransport;
switch (it.mode()) {
case IndividualTransport::Bike:
return QStringLiteral("qrc:///images/bike.svg");
case IndividualTransport::Car:
return QStringLiteral("qrc:///images/car.svg");
case IndividualTransport::Walk:
return QStringLiteral("qrc:///images/walk.svg");
}
return QStringLiteral("question");
}
QString PublicTransport::journeySectionIcon(const KPublicTransport::JourneySection &journeySection) const
{
using namespace KPublicTransport;
switch (journeySection.mode()) {
case JourneySection::Invalid:
break;
case JourneySection::PublicTransport:
return lineIcon(journeySection.route().line());
case JourneySection::Walking:
return QStringLiteral("qrc:///images/walk.svg");
case JourneySection::Waiting:
return QStringLiteral("qrc:///images/wait.svg");
case JourneySection::Transfer:
return QStringLiteral("qrc:///images/transfer.svg");
case JourneySection::RentedVehicle:
return rentalVehicleIcon(journeySection.rentalVehicle());
case JourneySection::IndividualTransport:
return individualTransportIcon(journeySection.individualTransport());
}
return QStringLiteral("question");
}
static KItinerary::Ticket clearSeat(KItinerary::Ticket ticket)
{
auto seat = ticket.ticketedSeat();
......@@ -368,6 +407,17 @@ bool PublicTransport::warnAboutSection(const KPublicTransport::JourneySection &s
case RentalVehicle::Car:
return false; // ???
}
break;
case JourneySection::IndividualTransport:
switch (section.individualTransport().mode()) {
case IndividualTransport::Walk:
return section.duration() > 20*60 || section.distance() > 1000;
case IndividualTransport::Bike:
return section.duration() > 60*60 || section.distance() > 20000;
case IndividualTransport::Car:
return false;
}
break;
}
return false;
......
......@@ -86,6 +86,9 @@ public:
/** Provides an icon for a rental vehicle type. */
Q_INVOKABLE QString rentalVehicleIcon(const KPublicTransport::RentalVehicle &vehicle) const;
/** Provide an icon source for usage in Kirigami.Icon that represents @p journeySection. */
Q_INVOKABLE QString journeySectionIcon(const KPublicTransport::JourneySection &journeySection) const;
/** Create a KPublicTransport::StopoverRequest for the given KItinerary place. */
Q_INVOKABLE KPublicTransport::StopoverRequest stopoverRequestForPlace(const QVariant &place, const QDateTime &dt) const;
......
Supports Markdown
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