Commit e7bbf134 authored by Nicolas Fella's avatar Nicolas Fella

Show trip length

parent c439503e
......@@ -5,6 +5,7 @@ set(ktrip_SRCS
querycontroller.cpp
locationquerymodel.cpp
locationcache.cpp
formatter.cpp
)
if (ANDROID)
......
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "formatter.h"
QString Formatter::formatDuration(int seconds)
{
const int minutes = seconds / 60;
const int hours = minutes / 60;
const int minutesRemainder = minutes % 60;
const QString minutesString = minutesRemainder > 9 ? QString::number(minutesRemainder) : QStringLiteral("0") + QString::number(minutesRemainder);
return QString::number(hours) + QStringLiteral(":") + minutesString;
}
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QObject>
class Formatter : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QString formatDuration(int seconds);
};
......@@ -22,6 +22,7 @@
#include "locationquerymodel.h"
#include "querycontroller.h"
#include "locationcache.h"
#include "formatter.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
......@@ -69,6 +70,9 @@ int main(int argc, char *argv[])
KPublicTransport::Manager manager;
engine.rootContext()->setContextProperty(QStringLiteral("_manager"), &manager);
Formatter formatter;
engine.rootContext()->setContextProperty(QStringLiteral("_formatter"), &formatter);
#ifdef Q_OS_ANDROID
engine.rootContext()->setContextProperty(QStringLiteral("_isAndroid"), true);
engine.rootContext()->setContextProperty(QStringLiteral("_androidUtils"), QVariant::fromValue(AndroidUtils::instance()));
......
......@@ -53,6 +53,10 @@ Kirigami.Page
RowLayout {
Label {
text: journey.sections[0].scheduledDepartureTime.toLocaleTimeString(Locale.ShortFormat) + " - " + journey.sections[journey.sections.length - 1].scheduledArrivalTime.toLocaleTimeString(Locale.ShortFormat)
}
Label {
text: "(" + _formatter.formatDuration(journey.duration) + ")"
Layout.fillWidth: !delayLabel.visible
}
......
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