BoardingPass.qml 8.17 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.pkpass 1.0 as KPkPass
23
import "." as App
24 25

Item {
26
    id: root
27 28
    property var pass: null
    property string passId
29
    //implicitHeight: frontLayout.implicitHeight
30 31 32 33 34 35
    implicitWidth: Math.max(frontLayout.implicitWidth, 332)

    ColumnLayout {
        id: frontLayout
        spacing: 0
        anchors.fill: parent
36 37
        // HACK to break binding loop on implicitHeight
        onImplicitHeightChanged: root.implicitHeight = implicitHeight
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

        Rectangle {
            id: headerBackground
            radius: 10
            color: pass.backgroundColor
            Layout.fillWidth: true
            implicitWidth: headerLayout.implicitWidth + 2 * headerLayout.anchors.margins
            implicitHeight: headerLayout.implicitHeight + 2 * headerLayout.anchors.margins

            GridLayout {
                id: headerLayout
                rows: 2
                columns: pass.headerFields.length + 2
                anchors.fill: parent
                anchors.margins: 10

                Image {
                    Layout.rowSpan: 2
56 57 58 59
                    Layout.maximumHeight: 60
                    Layout.maximumWidth: 150
                    Layout.preferredWidth: paintedWidth
                    fillMode: Image.PreserveAspectFit
Volker Krause's avatar
Volker Krause committed
60
                    source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/logo" : ""
61 62 63 64 65
                    sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
                }

                QQC2.Label {
                    Layout.rowSpan: 2
66 67
                    Layout.fillWidth: pass ? true : false
                    text: pass ? pass.logoText : ""
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                    color: pass.foregroundColor
                }

                Repeater {
                    model: pass.headerFields
                    delegate: QQC2.Label {
                        text: modelData.label
                        color: pass.labelColor
                    }
                }
                Repeater {
                    model: pass.headerFields
                    delegate: QQC2.Label {
                        text: modelData.value
                        color: pass.foregroundColor
                    }
                }
            }
        }

        Rectangle {
            id: bodyBackground
            radius: 10
            color: pass.backgroundColor
            Layout.fillWidth: true
            implicitHeight: bodyLayout.implicitHeight + 2 * bodyLayout.anchors.margins
            implicitWidth: bodyLayout.implicitWidth + 2 * bodyLayout.anchors.margins

            ColumnLayout {
                id: bodyLayout
                anchors.fill: parent
                anchors.margins: 10
                spacing: 10

                // primary fields
                GridLayout {
                    id: primaryFieldsLayout
                    rows: 2
                    columns: 3
                    flow: GridLayout.TopToBottom
                    Layout.fillWidth: true

                    QQC2.Label {
                        id: primaryLabel
                        Layout.fillWidth: true
                        Layout.preferredWidth: 1
                        text: pass.primaryFields[0].label
                        color: pass.labelColor
                    }
                    QQC2.Label {
                        id: primaryValue
                        text: pass.primaryFields[0].value
                        color: pass.foregroundColor
                        font.pointSize: 1.5 * primaryLabel.font.pointSize
                    }

124
                    Kirigami.Icon {
125 126
                        Layout.rowSpan: 2
                        Layout.alignment: Qt.AlignBottom
127 128 129 130 131 132 133
                        source: {
                            switch (pass.transitType) {
                                case KPkPass.BoardingPass.Air: return "qrc:///images/flight.svg"
                                case KPkPass.BoardingPass.Train: return "qrc:///images/train.svg"
                            }
                            return "go-next";
                        }
134 135
                        width: Kirigami.Units.iconSizes.smallMedium
                        height: width
136
                        color: pass.labelColor
137
                        isMask: true
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
                    }

                    QQC2.Label {
                        Layout.fillWidth: true
                        Layout.preferredWidth: 1
                        horizontalAlignment: Qt.AlignRight
                        text: pass.primaryFields[1].label
                        color: pass.labelColor
                    }
                    QQC2.Label {
                        Layout.alignment: Qt.AlignRight
                        text: pass.primaryFields[1].value
                        color: pass.foregroundColor
                        font.pointSize: primaryValue.font.pointSize
                    }
                }

                // auxiliary fields
                GridLayout {
                    id: auxFieldsLayout
                    rows: 2
                    columns: pass.auxiliaryFields.length
                    Layout.fillWidth: true

                    Repeater {
                        model: pass.auxiliaryFields
                        delegate: QQC2.Label {
165
                            Layout.fillWidth: true
166 167
                            color: pass.labelColor
                            text: modelData.label
168
                            horizontalAlignment: modelData.textAlignment
169 170 171 172 173 174 175 176
                        }
                    }
                    Repeater {
                        model: pass.auxiliaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.foregroundColor
                            text: modelData.value
177
                            horizontalAlignment: modelData.textAlignment
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                        }
                    }
                }

                // secondary fields
                GridLayout {
                    id: secFieldsLayout
                    rows: 2
                    columns: pass.secondaryFields.length
                    Layout.fillWidth: true

                    Repeater {
                        model: pass.secondaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.labelColor
                            text: modelData.label
195
                            horizontalAlignment: modelData.textAlignment
196 197 198 199 200
                        }
                    }
                    Repeater {
                        model: pass.secondaryFields
                        delegate: QQC2.Label {
201
                            Layout.fillWidth: true
202 203
                            color: pass.foregroundColor
                            text: modelData.value
204
                            horizontalAlignment: modelData.textAlignment
205 206 207 208
                        }
                    }
                }

Volker Krause's avatar
Volker Krause committed
209 210 211 212 213 214 215
                // footer
                Image {
                    source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/footer" : ""
                    sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
                    Layout.alignment: Qt.AlignCenter
                }

216
                // barcode
217
                App.PkPassBarcode { pass: root.pass }
218 219 220 221 222 223

                // TODO back fields
            }
        }
    }
}