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

Highlight current transfers and show progress as for reservations

parent aa8389d6
......@@ -83,6 +83,7 @@ target_sources(itinerary-app PRIVATE
notifyrc.qrc
settings.cpp
tickettokenmodel.cpp
transferdelegatecontroller.cpp
weatherforecastmodel.cpp
${qml_srcs}
)
......
......@@ -14,12 +14,15 @@ import "." as App
Kirigami.AbstractCard {
id: root
property var transfer
property alias transfer: _controller.transfer
property bool journeyDetailsExpanded: false
property QtObject controller: TransferDelegateController {
id: _controller
}
header: Rectangle {
id: headerBackground
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
Kirigami.Theme.colorSet: controller.isCurrent ? Kirigami.Theme.Selection : Kirigami.Theme.Complementary
Kirigami.Theme.inherit: false
color: transfer.isReachable ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeBackgroundColor
radius: Kirigami.Units.smallSpacing
......@@ -57,6 +60,16 @@ Kirigami.AbstractCard {
visible: transfer.state == Transfer.Selected && transfer.journey.hasExpectedDepartureTime
}
}
Rectangle {
id: progressBar
visible: controller.isCurrent
anchors.bottom: headerBackground.bottom
anchors.left: headerBackground.left
height: Kirigami.Units.smallSpacing
width: controller.progress * headerBackground.width
color: Kirigami.Theme.visitedLinkColor
}
}
contentItem: Column {
......
......@@ -31,6 +31,7 @@
#include "statisticstimerangemodel.h"
#include "tickettokenmodel.h"
#include "timelinedelegatecontroller.h"
#include "transferdelegatecontroller.h"
#include "transfermanager.h"
#include "tripgroupinfoprovider.h"
#include "tripgroupmanager.h"
......@@ -115,6 +116,7 @@ void registerApplicationTypes()
qmlRegisterType<StatisticsTimeRangeModel>("org.kde.itinerary", 1, 0, "StatisticsTimeRangeModel");
qmlRegisterType<TicketTokenModel>("org.kde.itinerary", 1, 0, "TicketTokenModel");
qmlRegisterType<TimelineDelegateController>("org.kde.itinerary", 1, 0, "TimelineDelegateController");
qmlRegisterType<TransferDelegateController>("org.kde.itinerary", 1, 0, "TransferDelegateController");
qmlRegisterType<WeatherForecastModel>("org.kde.itinerary", 1, 0, "WeatherForecastModel");
}
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "transferdelegatecontroller.h"
#include <QDebug>
TransferDelegateController::TransferDelegateController(QObject *parent)
: QObject(parent)
{
m_updateTrigger.setTimerType(Qt::VeryCoarseTimer);
connect(&m_updateTrigger, &QTimer::timeout, this, &TransferDelegateController::updated);
connect(&m_updateTrigger, &QTimer::timeout, this, &TransferDelegateController::scheduleTimer);
}
TransferDelegateController::~TransferDelegateController() = default;
Transfer TransferDelegateController::transfer() const
{
return m_transfer;
}
void TransferDelegateController::setTransfer(const Transfer &transfer)
{
m_transfer = transfer;
Q_EMIT transferChanged();
Q_EMIT updated();
if (transfer.state() != Transfer::Selected) {
m_updateTrigger.stop();
return;
}
scheduleTimer();
}
bool TransferDelegateController::isCurrent() const
{
const auto jny = m_transfer.journey();
const auto now = QDateTime::currentDateTime();
if ((jny.hasExpectedArrivalTime() && jny.expectedArrivalTime() < now) || jny.scheduledArrivalTime() < now) {
return false;
}
if ((jny.departureDelay() < 0 && now < jny.expectedDepartureTime()) || now < jny.scheduledDepartureTime()) {
return false;
}
return true;
}
float TransferDelegateController::progress() const
{
const auto jny = m_transfer.journey();
const auto startTime = jny.hasExpectedDepartureTime() ? jny.expectedDepartureTime() : jny.scheduledDepartureTime();
const auto endTime = jny.hasExpectedArrivalTime() ? jny.expectedArrivalTime() : jny.scheduledArrivalTime();
const auto tripLength = startTime.secsTo(endTime);
if (tripLength <= 0) {
return 0.0f;
}
const auto progress = startTime.secsTo(QDateTime::currentDateTime());
return std::min(std::max(0.0f, (float)progress / (float)tripLength), 1.0f);
}
void TransferDelegateController::scheduleTimer()
{
const auto jny = m_transfer.journey();
const auto now = QDateTime::currentDateTime();
if ((jny.hasExpectedArrivalTime() && jny.expectedArrivalTime() < now) || jny.scheduledArrivalTime() < now) { // already arrived
m_updateTrigger.stop();
return;
}
const auto depTime = jny.departureDelay() < 0 ? jny.expectedDepartureTime() : jny.scheduledDepartureTime();
if (now < depTime) {
m_updateTrigger.setInterval(now.secsTo(depTime) * 1000);
m_updateTrigger.start();
return;
}
m_updateTrigger.setInterval(std::chrono::minutes(1));
m_updateTrigger.start();
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef TRANSFERDELEGATECONTROLLER_H
#define TRANSFERDELEGATECONTROLLER_H
#include "transfer.h"
#include <QObject>
#include <QTimer>
/** Transfer delegate logic. */
class TransferDelegateController : public QObject
{
Q_OBJECT
Q_PROPERTY(Transfer transfer READ transfer WRITE setTransfer NOTIFY transferChanged)
Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY updated)
Q_PROPERTY(float progress READ progress NOTIFY updated)
public:
explicit TransferDelegateController(QObject *parent = nullptr);
~TransferDelegateController();
Transfer transfer() const;
void setTransfer(const Transfer &transfer);
bool isCurrent() const;
float progress() const;
Q_SIGNALS:
void transferChanged();
void updated();
private:
void scheduleTimer();
Transfer m_transfer;
QTimer m_updateTrigger;
};
#endif // TRANSFERDELEGATECONTROLLER_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