TimelinePage.qml 3.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
    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
import org.kde.kirigami 2.0 as Kirigami
22
import org.kde.itinerary 1.0
23 24 25
import "." as App

Kirigami.ScrollablePage {
26 27 28 29
    id: root
    signal showBoardingPass(var pass, string passId)

    title: qsTr("My Itinerary")
30 31 32 33 34 35 36 37 38 39 40 41
    // context drawer content
    actions {
        contextualActions: [
            Kirigami.Action {
                text: qsTr("Delete Pass")
                iconName: "edit-delete"
                onTriggered: print("TODO")
            }
        ]
    }

    // page content
42 43 44 45 46 47 48 49
    Component {
        id: flightDelegate
        App.FlightDelegate {}
    }
    Component {
        id: hotelDelegate
        App.HotelDelegate {}
    }
Volker Krause's avatar
Volker Krause committed
50 51 52 53
    Component {
        id: trainDelegate
        App.TrainDelegate {}
    }
Volker Krause's avatar
Volker Krause committed
54 55 56 57
    Component {
        id: busDelegate
        App.BusDelegate {}
    }
58 59 60 61 62 63 64 65 66 67 68 69 70
    Component {
        id: todayDelegate
        Item {
            implicitHeight: visible ? label.implicitHeight : 0
            QQC2.Label {
                id: label
                anchors.fill: parent
                text: qsTr("Nothing on the itinerary for today.");
                color: Kirigami.Theme.textColor
                horizontalAlignment: Qt.AlignHCenter
            }
        }
    }
71

72 73 74
    ListView {
        model: _timelineModel
        spacing: 5
75 76 77 78 79

        delegate: Loader {
            property var modelData: model

            height: item.implicitHeight
Volker Krause's avatar
Volker Krause committed
80 81
            anchors.left: parent.left
            anchors.right: parent.right
82 83 84 85
            sourceComponent: {
                switch (modelData.type) {
                    case TimelineModel.Flight: return flightDelegate;
                    case TimelineModel.Hotel: return hotelDelegate;
Volker Krause's avatar
Volker Krause committed
86
                    case TimelineModel.TrainTrip: return trainDelegate;
Volker Krause's avatar
Volker Krause committed
87
                    case TimelineModel.BusTrip: return busDelegate;
88
                    case TimelineModel.TodayMarker: return todayDelegate;
89 90 91 92
                }
            }

            onLoaded: {
93 94 95 96 97 98 99 100
                if (modelData.type != TimelineModel.TodayMarker) {
                    item.reservation = Qt.binding(function() { return modelData.reservation; });
                    item.passId = Qt.binding(function() { return modelData.passId; });
                    item.pass = Qt.binding(function() { return modelData.pass; });
                    item.showBoardingPass.connect(onShowBoardingPass);
                } else {
                    item.visible = modelData.isTodayEmpty;
                }
101 102 103
            }
            function onShowBoardingPass(pass, passId) {
                root.showBoardingPass(pass, passId)
104 105
            }
        }
106

107 108 109 110 111 112 113 114 115 116 117 118 119
        section.property: "sectionHeader"
        section.delegate: Rectangle {
            color: Kirigami.Theme.backgroundColor
            implicitHeight: headerItem.implicitHeight
            implicitWidth: ListView.view.width
            Kirigami.BasicListItem {
                id: headerItem
                label: section
                icon: "view-calendar-day"
            }
        }
        section.criteria: ViewSection.FullString
        section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
120 121
    }
}