TimelinePage.qml 4.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
    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
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

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
import "." as App

Kirigami.ScrollablePage {
26 27 28
    id: root

    title: qsTr("My Itinerary")
29 30 31 32
    // context drawer content
    actions {
        contextualActions: [
            Kirigami.Action {
33
                text: qsTr("Today")
Volker Krause's avatar
Volker Krause committed
34
                iconName: "view-calendar-day"
35
                onTriggered: listView.positionViewAtIndex(_timelineModel.todayRow, ListView.Beginning);
36 37 38 39 40
            }
        ]
    }

    // page content
41 42
    Component {
        id: flightDelegate
43 44 45 46 47
        App.FlightDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
48 49 50
    }
    Component {
        id: hotelDelegate
51 52 53 54 55
        App.HotelDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
56
    }
Volker Krause's avatar
Volker Krause committed
57 58
    Component {
        id: trainDelegate
59 60 61 62 63
        App.TrainDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
Volker Krause's avatar
Volker Krause committed
64
    }
Volker Krause's avatar
Volker Krause committed
65 66
    Component {
        id: busDelegate
67 68 69 70 71
        App.BusDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
Volker Krause's avatar
Volker Krause committed
72
    }
73 74
    Component {
        id: restaurantDelegate
75 76 77 78 79
        App.RestaurantDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
80
    }
81 82 83 84 85 86 87 88
    Component {
        id: touristAttractionDelegate
        App.TouristAttractionDelegate {
            reservation: modelData.reservation
            passId: modelData.passId
            rangeType: modelData.rangeType
        }
    }
89 90 91 92
    Component {
        id: todayDelegate
        Item {
            implicitHeight: visible ? label.implicitHeight : 0
93
            visible: modelData.isTodayEmpty
94 95 96 97 98 99 100 101 102
            QQC2.Label {
                id: label
                anchors.fill: parent
                text: qsTr("Nothing on the itinerary for today.");
                color: Kirigami.Theme.textColor
                horizontalAlignment: Qt.AlignHCenter
            }
        }
    }
103 104 105 106 107 108
    Component {
        id: countryInfoDelegate
        App.CountryInfoDelegate {
            countryInfo: modelData.countryInformation
        }
    }
109

110
    Kirigami.CardsListView {
111
        id: listView
112
        model: _timelineModel
113 114 115

        delegate: Loader {
            property var modelData: model
116
            height: item ? item.implicitHeight : 0
117
            sourceComponent: {
118 119
                if (!modelData)
                    return;
120 121 122
                switch (modelData.type) {
                    case TimelineModel.Flight: return flightDelegate;
                    case TimelineModel.Hotel: return hotelDelegate;
Volker Krause's avatar
Volker Krause committed
123
                    case TimelineModel.TrainTrip: return trainDelegate;
Volker Krause's avatar
Volker Krause committed
124
                    case TimelineModel.BusTrip: return busDelegate;
125
                    case TimelineModel.Restaurant: return restaurantDelegate;
126
                    case TimelineModel.TouristAttraction: return touristAttractionDelegate;
127
                    case TimelineModel.TodayMarker: return todayDelegate;
128
                    case TimelineModel.CountryInfo: return countryInfoDelegate;
129 130
                }
            }
131
        }
132

133
        section.property: "sectionHeader"
134 135
        section.delegate: Item {
            implicitHeight: headerItem.implicitHeight + Kirigami.Units.largeSpacing*2
136 137 138 139
            implicitWidth: ListView.view.width
            Kirigami.BasicListItem {
                id: headerItem
                label: section
140
                backgroundColor: Kirigami.Theme.backgroundColor
141 142 143 144 145
                icon: "view-calendar-day"
            }
        }
        section.criteria: ViewSection.FullString
        section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
146
    }
147 148

    Component.onCompleted: listView.positionViewAtIndex(_timelineModel.todayRow, ListView.Beginning);
149
}