TrainDelegate.qml 4.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    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 Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
15
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20
*/

import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
21
import org.kde.kirigami 2.4 as Kirigami
22
import org.kde.itinerary 1.0
23 24 25 26
import "." as App

App.TimelineDelegate {
    id: root
27 28
    property var arrival: _liveDataManager.arrival(batchId)
    property var departure: _liveDataManager.departure(batchId)
29

30 31 32
    headerIconSource: "qrc:///images/train.svg"
    headerItem: RowLayout {
        QQC2.Label {
33 34 35 36 37 38
            text: {
                if (reservationFor.trainName || reservationFor.trainNumber) {
                    return reservationFor.trainName + " " + reservationFor.trainNumber
                }
                return i18n("%1 to %2", reservationFor.departureStation.name, reservationFor.arrivalStation.name);
            }
39 40 41 42 43 44 45 46
            color: Kirigami.Theme.textColor
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * root.headerFontScale
            Layout.fillWidth: true
        }
        QQC2.Label {
            text: Localizer.formatTime(reservationFor, "departureTime")
            color: Kirigami.Theme.textColor
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * root.headerFontScale
47
        }
48
        QQC2.Label {
49 50 51
            text: (departure.departureDelay >= 0 ? "+" : "") + departure.departureDelay
            color: (departure.departureDelay > 1) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
            visible: departure.hasExpectedDepartureTime
52
        }
53 54 55 56
    }

    contentItem: ColumnLayout {
        id: topLayout
57 58

        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
59
            text: i18n("Departure from %1 on platform %2",
60
                reservationFor.departureStation.name,
61
                departure.hasExpectedPlatform ? departure.expectedPlatform :
62
                reservationFor.departurePlatform ? reservationFor.departurePlatform : "-")
63
            color: Kirigami.Theme.textColor
64 65
            wrapMode: Text.WordWrap
            Layout.fillWidth: true
66
        }
Volker Krause's avatar
Volker Krause committed
67
        App.PlaceDelegate {
68
            place: reservationFor.departureStation
Volker Krause's avatar
Volker Krause committed
69 70 71
            Layout.fillWidth: true
        }
        // TODO reserved seat
72 73 74 75

        Kirigami.Separator {
            Layout.fillWidth: true
        }
76
        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
77
            text: i18n("Arrival at %1 on platform %2",
78
                reservationFor.arrivalStation.name,
79
                arrival.hasExpectedPlatform ? arrival.expectedPlatform :
80
                reservationFor.arrivalPlatform ? reservationFor.arrivalPlatform : "-")
81
            color: Kirigami.Theme.textColor
82 83
            wrapMode: Text.WordWrap
            Layout.fillWidth: true
84
        }
85
        RowLayout {
86
            Layout.fillWidth: true
87 88 89 90 91 92 93 94
            QQC2.Label {
                text: i18n("Arrival time: %1", Localizer.formatDateTime(reservationFor, "arrivalTime"))
                color: Kirigami.Theme.textColor
                wrapMode: Text.WordWrap
            }
            QQC2.Label {
                text: (arrival.arrivalDelay >= 0 ? "+" : "") + arrival.arrivalDelay
                color: (arrival.arrivalDelay > 1) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
95
                visible: arrival.hasExpectedArrivalTime
96
            }
97
        }
Volker Krause's avatar
Volker Krause committed
98
        App.PlaceDelegate {
99
            place: reservationFor.arrivalStation
Volker Krause's avatar
Volker Krause committed
100 101
            Layout.fillWidth: true
        }
102
    }
103 104 105 106

    Component {
        id: detailsComponent
        App.TrainPage {
107
            batchId: root.batchId
108 109 110 111
        }
    }

    onClicked: applicationWindow().pageStack.push(detailsComponent);
112
}