Commit 7df1ed9f authored by Volker Krause's avatar Volker Krause

Move line mode icon mapping to C++ and use it in the timeline too

parent a78da929
......@@ -78,28 +78,7 @@ Kirigami.ScrollablePage {
source: {
switch (modelData.mode) {
case JourneySection.PublicTransport:
{
switch (modelData.route.line.mode) {
case Line.Air: return "qrc:///images/flight.svg";
case Line.Boat: return "qrc:///images/ferry.svg";
case Line.Bus: return "qrc:///images/bus.svg";
case Line.BusRapidTransit: return "qrc:///images/coach.svg";
case Line.Coach: return "qrc:///images/coach.svg";
case Line.Ferry: return "qrc:///images/ferry.svg";
case Line.Funicular: return "qrc:///images/Funicular.svg";
case Line.LocalTrain: return "qrc:///images/train.svg";
case Line.LongDistanceTrain: return "qrc:///images/longdistancetrain.svg";
case Line.Metro: return "qrc:///images/subway.svg";
case Line.RailShuttle: return "qrc:///images/rapidtransit.svg";
case Line.RapidTransit: return "qrc:///images/rapidtransit.svg";
case Line.Shuttle: return "qrc:///images/shuttle.svg";
case Line.Taxi: return "qrc:///images/taxi.svg";
case Line.Train: return "qrc:///images/train.svg";
case Line.Tramway: return "qrc:///images/tramway.svg";
default: return "question";
}
break;
}
return PublicTransport.lineModeIcon(modelData.route.line.mode);
case JourneySection.Walking: return "qrc:///images/walk.svg";
case JourneySection.Waiting: return "qrc:///images/wait.svg";
case JourneySection.Transfer: return "qrc:///images/transfer.svg";
......
......@@ -19,6 +19,7 @@ import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kpublictransport 1.0
import org.kde.itinerary 1.0
import "." as App
......@@ -27,7 +28,7 @@ App.TimelineDelegate {
property var arrival: _liveDataManager.arrival(batchId)
property var departure: _liveDataManager.departure(batchId)
headerIconSource: "qrc:///images/train.svg"
headerIconSource: departure.route.line.mode == Line.Unknown ? "qrc:///images/train.svg" : PublicTransport.lineModeIcon(departure.route.line.mode)
headerItem: RowLayout {
QQC2.Label {
text: {
......
......@@ -25,9 +25,11 @@
#include "journeyquerymodel.h"
#include "livedatamanager.h"
#include "localizer.h"
#include "lockmanager.h"
#include "pkpassmanager.h"
#include "timelinemodel.h"
#include "pkpassimageprovider.h"
#include "publictransport.h"
#include "reservationmanager.h"
#include "settings.h"
#include "tickettokenmodel.h"
......@@ -36,7 +38,6 @@
#include "tripgroupproxymodel.h"
#include "util.h"
#include "weatherforecastmodel.h"
#include "lockmanager.h"
#include <weatherforecastmanager.h>
......@@ -217,6 +218,9 @@ int main(int argc, char **argv)
return new Util;
});
qmlRegisterType<WeatherForecastModel>("org.kde.itinerary", 1, 0, "WeatherForecastModel");
qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "PublicTransport", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
return engine->toScriptValue(PublicTransportUtil());
});
QQmlApplicationEngine engine;
engine.addImageProvider(QStringLiteral("org.kde.pkpass"), new PkPassImageProvider(&passMgr));
......
......@@ -19,6 +19,7 @@
#include <KItinerary/Place>
#include <KPublicTransport/Line>
#include <KPublicTransport/Location>
KPublicTransport::Location PublicTransport::locationFromStation(const KItinerary::TrainStation& station)
......@@ -44,3 +45,40 @@ KPublicTransport::Location PublicTransport::locationFromStation(const KItinerary
loc.setCoordinate(busStop.geo().latitude(), busStop.geo().longitude());
return loc;
}
QString PublicTransportUtil::lineModeIcon(int lineMode)
{
using namespace KPublicTransport;
switch (lineMode) {
case Line::Air:
return QStringLiteral("qrc:///images/flight.svg");
case Line::Boat:
case Line::Ferry:
return QStringLiteral("qrc:///images/ferry.svg");
case Line::Bus:
return QStringLiteral("qrc:///images/bus.svg");
case Line::BusRapidTransit:
case Line::Coach:
return QStringLiteral("qrc:///images/coach.svg");
case Line::Funicular:
return QStringLiteral("qrc:///images/Funicular.svg");
case Line::LocalTrain:
case Line::Train:
return QStringLiteral("qrc:///images/train.svg");
case Line::LongDistanceTrain:
return QStringLiteral("qrc:///images/longdistancetrain.svg");
case Line::Metro:
return QStringLiteral("qrc:///images/subway.svg");
case Line::RailShuttle:
case Line::RapidTransit:
return QStringLiteral("qrc:///images/rapidtransit.svg");
case Line::Shuttle:
return QStringLiteral("qrc:///images/shuttle.svg");
case Line::Taxi:
return QStringLiteral("qrc:///images/taxi.svg");
case Line::Tramway:
return QStringLiteral("qrc:///images/tramway.svg");
}
return QStringLiteral("question");
}
......@@ -18,6 +18,8 @@
#ifndef PUBLICTRANSPORT_H
#define PUBLICTRANSPORT_H
#include <qobjectdefs.h>
namespace KItinerary {
class BusStation;
class TrainStation;
......@@ -36,4 +38,15 @@ namespace PublicTransport
KPublicTransport::Location locationFromStation(const KItinerary::BusStation &busStop);
}
/** Utility functions for interfacing with KPublicTransport from QML. */
class PublicTransportUtil
{
Q_GADGET
public:
/** Convert a KPublicTransport::Line::Mode enum value to an icon source or name
* for usage in Kirigami.Icon.
*/
Q_INVOKABLE QString lineModeIcon(int lineMode);
};
#endif // PUBLICTRANSPORT_H
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