JourneySectionDelegate.qml 7.32 KB
Newer Older
1
/*
2
    SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
9
*/

import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
Volker Krause's avatar
Volker Krause committed
10
import org.kde.kirigami 2.12 as Kirigami
11
12
import org.kde.kpublictransport 1.0
import org.kde.itinerary 1.0
13
import "." as App
14
15
16

Kirigami.AbstractListItem {
    highlighted: false
17
18
19
20
21
22
23

    onClicked: {
        if (modelData.mode == JourneySection.PublicTransport) {
            applicationWindow().pageStack.push(journeySectionPage, {"journeySection": modelData});
        }
    }

24
25
26
27
28
29
30
31
32
33
34
35
    GridLayout {
        columns: 2

        // top row: departure time, departure location, departure platform
        RowLayout {
            visible: modelData.mode != JourneySection.Waiting
            QQC2.Label {
                text: Localizer.formatTime(modelData, "scheduledDepartureTime")
            }
            QQC2.Label {
                text: {
                    if (modelData.disruption == Disruption.NoService)
36
                        return i18nc("a train/bus journey canceled by its operator", "Canceled");
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
                    return (modelData.departureDelay >= 0 ? "+" : "") + modelData.departureDelay;
                }
                color: {
                    if (modelData.departureDelay > 1 || modelData.disruption == Disruption.NoService)
                        return Kirigami.Theme.negativeTextColor;
                    return Kirigami.Theme.positiveTextColor;
                }
                visible: modelData.hasExpectedDepartureTime || modelData.disruption == Disruption.NoService
            }
        }
        RowLayout {
            visible: modelData.mode != JourneySection.Waiting
            QQC2.Label {
                text: modelData.from.name
                Layout.fillWidth: true
                elide: Text.ElideRight
            }
            QQC2.Label {
                text: modelData.hasExpectedDeparturePlatform ? modelData.expectedDeparturePlatform : modelData.scheduledDeparturePlatform
                color: modelData.departurePlatformChanged ? Kirigami.Theme.negativeTextColor
                    : modelData.hasExpectedDeparturePlatform ? Kirigami.Theme.positiveTextColor
                    : Kirigami.Theme.textColor
                visible: modelData.scheduledDeparturePlatform !== ""
            }
        }

        // middle row: mode symbol, transport mode, duration
        Rectangle {
65
            color: (modelData.route.line.hasColor && !modelData.route.line.hasLogo && !modelData.route.line.hasModeLogo) ? modelData.route.line.color : "transparent"
66
            implicitHeight: Kirigami.Units.iconSizes.smallMedium
67
68
69
70
71
72
73
74
75
            implicitWidth: modeIcon.width
            Layout.alignment: Qt.AlignHCenter

            Kirigami.Icon {
                id: modeIcon
                anchors.centerIn: parent
                source: {
                    switch (modelData.mode) {
                        case JourneySection.PublicTransport:
76
                            return PublicTransport.lineIcon(modelData.route.line);
77
78
79
                        case JourneySection.Walking: return "qrc:///images/walk.svg";
                        case JourneySection.Waiting: return "qrc:///images/wait.svg";
                        case JourneySection.Transfer: return "qrc:///images/transfer.svg";
80
81
                        case JourneySection.RentedVehicle:
                            return PublicTransport.rentalVehicleIcon(modelData.rentalVehicle);
82
83
84
85
                        default: return "question";
                    }
                }
                color: modelData.route.line.hasTextColor ? modelData.route.line.textColor : Kirigami.Theme.textColor
86
                width: !isMask ? implicitWidth : height
87
                height: parent.height
88
                isMask: modelData.mode != JourneySection.PublicTransport || (!modelData.route.line.hasLogo && !modelData.route.line.hasModeLogo)
89
90
            }
        }
91
        RowLayout {
92
            Layout.fillWidth: true
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
            QQC2.Label {
                Layout.fillWidth: true
                text: {
                    switch (modelData.mode) {
                    case JourneySection.PublicTransport:
                    {
                        var l = modelData.route.line.modeString + " " + modelData.route.line.name;
                        if (modelData.route.direction)
                            return i18n("%1 to %2 (%3)", l, modelData.route.direction, Localizer.formatDuration(modelData.duration));
                        return i18n("%1 (%2)", l, Localizer.formatDuration(modelData.duration));
                    }
                    case JourneySection.Walking:
                        if (modelData.distance == 0)
                            return i18n("Walk (%1)", Localizer.formatDuration(modelData.duration));
                        return i18n("Walk %1 (%2)", Localizer.formatDistance(modelData.distance), Localizer.formatDuration(modelData.duration));
                    case JourneySection.Transfer:
                        return i18n("Transfer (%1)", Localizer.formatDuration(modelData.duration))
                    case JourneySection.Waiting:
                        return i18n("Wait (%1)", Localizer.formatDuration(modelData.duration))
112
113
                    case JourneySection.RentedVehicle:
                        return i18n("%1 (%2)", modelData.rentalVehicle.network, Localizer.formatDuration(modelData.duration));
114
115
116
117
118
119
120
121
                    return "???";
                }}
                color: PublicTransport.warnAboutSection(modelData) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.textColor
                elide: Text.ElideMiddle
            }
            App.VehicleLoadIndicator {
                loadInformation: modelData.loadInformation
            }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        }

        // last row: arrival information
        RowLayout {
            visible: modelData.mode != JourneySection.Waiting
            QQC2.Label {
                text: Localizer.formatTime(modelData, "scheduledArrivalTime")
            }
            QQC2.Label {
                text: (modelData.arrivalDelay >= 0 ? "+" : "") + modelData.arrivalDelay
                color: modelData.arrivalDelay > 1 ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
                visible: modelData.hasExpectedArrivalTime
            }
        }
        RowLayout {
            visible: modelData.mode != JourneySection.Waiting
            QQC2.Label {
                text: modelData.to.name
                Layout.fillWidth: true
                elide: Text.ElideRight
            }
            QQC2.Label {
                text: modelData.hasExpectedArrivalPlatform ? modelData.expectedArrivalPlatform : modelData.scheduledArrivalPlatform
                color: modelData.arrivalPlatformChanged ? Kirigami.Theme.negativeTextColor
                    : modelData.hasExpectedArrivalPlatform ? Kirigami.Theme.positiveTextColor
                    : Kirigami.Theme.textColor
                visible: modelData.scheduledArrivalPlatform !== ""
            }
        }

        // optional bottom row: notes
        QQC2.Label {
            Layout.columnSpan: 2
155
            Layout.fillWidth: true
156
157
158
159
160
            text: modelData.notes.join("<br/>")
            textFormat: Text.RichText
            wrapMode: Text.Wrap
            visible: modelData.notes.length > 0
            font.italic: true
161
            onLinkActivated: Qt.openUrlExternally(link)
162
163
164
        }
    }
}