FlightDelegate.qml 3.93 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 27
import "." as App

App.TimelineDelegate {
    id: root

Volker Krause's avatar
Volker Krause committed
28 29
    function airportDisplayString(airport)
    {
30 31 32 33 34 35
        return airport.name ? airport.name : airport.iataCode;
    }

    function airportDisplayCode(airport)
    {
        return airport.iataCode ? airport.iataCode : airport.name;
Volker Krause's avatar
Volker Krause committed
36 37
    }

38 39 40 41 42 43 44 45 46 47 48 49
    function seatString() {
        var s = new Array();
        for (var i = 0; i < root.resIds.length; ++i) {
            var res = _reservationManager.reservation(root.resIds[i]);
            if (res.airplaneSeat)
                s.push(res.airplaneSeat);
        }
        if (s.length === 0)
            return "-";
        return s.join(", ");
    }

50 51 52 53 54
    headerIconSource: "qrc:///images/flight.svg"
    headerItem: RowLayout {
        QQC2.Label {
            text: i18n("%1 %2 → %3",
                reservationFor.airline.iataCode + " " + reservationFor.flightNumber,
55 56
                airportDisplayCode(reservationFor.departureAirport),
                airportDisplayCode(reservationFor.arrivalAirport))
57 58 59 60 61 62 63 64 65 66
            color: Kirigami.Theme.textColor
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * root.headerFontScale
            Layout.fillWidth: true
        }
        QQC2.Label {
            text: isNaN(reservationFor.boardingTime.getTime()) ?
                Localizer.formatTime(reservationFor, "departureTime") :
                Localizer.formatTime(reservationFor, "boardingTime")
            color: Kirigami.Theme.textColor
            font.pointSize: Kirigami.Theme.defaultFont.pointSize * root.headerFontScale
67
        }
68 69
    }

70
    contentItem: ColumnLayout {
71
        id: topLayout
72

Volker Krause's avatar
Volker Krause committed
73
        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
74
            text: i18n("Departure from %1: %2",
75 76
                airportDisplayString(reservationFor.departureAirport),
                Localizer.formatTime(reservationFor, "departureTime") + " ")
Volker Krause's avatar
Volker Krause committed
77 78
            color: Kirigami.Theme.textColor
            wrapMode: Text.WordWrap
79
            Layout.fillWidth: true
Volker Krause's avatar
Volker Krause committed
80 81
        }
        App.PlaceDelegate {
82
            place: reservationFor.departureAirport
Volker Krause's avatar
Volker Krause committed
83 84
            Layout.fillWidth: true
        }
85
        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
86
            text: i18n("Terminal: %1  Gate: %2  Seat: %3",
87
                reservationFor.departureTerminal ? reservationFor.departureTerminal : "-",
88
                reservationFor.departureGate ? reservationFor.departureGate : "-", seatString())
89 90 91
            color: Kirigami.Theme.textColor
        }

92 93
        Kirigami.Separator {
            Layout.fillWidth: true
94
        }
Volker Krause's avatar
Volker Krause committed
95

96
        QQC2.Label {
Volker Krause's avatar
Volker Krause committed
97
            text: i18n("Arrival at %1: %2",
98 99
                airportDisplayString(reservationFor.arrivalAirport),
                Localizer.formatDateTime(reservationFor, "arrivalTime") + " ")
100
            color: Kirigami.Theme.textColor
Volker Krause's avatar
Volker Krause committed
101
            wrapMode: Text.WordWrap
102
            Layout.fillWidth: true
Volker Krause's avatar
Volker Krause committed
103 104
        }
        App.PlaceDelegate {
105
            place: reservationFor.arrivalAirport
Volker Krause's avatar
Volker Krause committed
106
            Layout.fillWidth: true
107 108
        }
    }
109 110 111 112

    Component {
        id: detailsComponent
        App.FlightPage {
113
            batchId: root.batchId
114 115 116 117
        }
    }

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