Warning, /pim/itinerary/src/app/BoardingPass.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.pkpass as KPkPass
0012 import org.kde.itinerary
0013 
0014 Item {
0015     id: root
0016     property var pass: null
0017     property string passId
0018     property int __margin: 10
0019 
0020     implicitWidth: Math.max(bodyLayout.implicitWidth, 332)
0021 
0022     /** Double tap on the barcode to request scan mode. */
0023     signal scanModeToggled()
0024 
0025     ColumnLayout {
0026         id: topLayout
0027         spacing: 0
0028         width: parent.implicitWidth
0029         // HACK to break binding loop on implicitHeight
0030         onImplicitHeightChanged: root.implicitHeight = implicitHeight
0031 
0032         GridLayout {
0033             id: headerLayout
0034             rows: 2
0035             columns: pass.headerFields.length + 2
0036             Layout.fillWidth: true
0037             Layout.margins: __margin
0038 
0039             Image {
0040                 Layout.rowSpan: 2
0041                 Layout.maximumHeight: 60
0042                 Layout.maximumWidth: 150
0043                 Layout.preferredWidth: paintedWidth
0044                 fillMode: Image.PreserveAspectFit
0045                 source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/logo" : ""
0046                 sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
0047             }
0048 
0049             QQC2.Label {
0050                 Layout.rowSpan: 2
0051                 Layout.fillWidth: pass ? true : false
0052                 text: pass ? pass.logoText : ""
0053                 color: pass.foregroundColor
0054             }
0055 
0056             Repeater {
0057                 model: pass.headerFields
0058                 delegate: QQC2.Label {
0059                     text: modelData.label
0060                     color: pass.labelColor
0061                 }
0062             }
0063             Repeater {
0064                 model: pass.headerFields
0065                 delegate: QQC2.Label {
0066                     text: modelData.valueDisplayString
0067                     color: pass.foregroundColor
0068                 }
0069             }
0070         }
0071 
0072         ColumnLayout {
0073             id: bodyLayout
0074             Layout.margins: __margin
0075             spacing: __margin
0076 
0077             // primary fields
0078             GridLayout {
0079                 id: primaryFieldsLayout
0080                 rows: 2
0081                 columns: 3
0082                 flow: GridLayout.TopToBottom
0083                 Layout.fillWidth: true
0084 
0085                 QQC2.Label {
0086                     id: primaryLabel
0087                     Layout.fillWidth: true
0088                     Layout.preferredWidth: primaryFieldsLayout.width/2 - Kirigami.Units.iconSizes.smallMedium
0089                     text: pass.primaryFields[0].label
0090                     color: pass.labelColor
0091                     wrapMode: Text.WordWrap
0092                 }
0093                 QQC2.Label {
0094                     id: primaryValue
0095                     text: pass.primaryFields[0].valueDisplayString
0096                     color: pass.foregroundColor
0097                     font.pointSize: 1.5 * primaryLabel.font.pointSize
0098                 }
0099 
0100                 Kirigami.Icon {
0101                     Layout.rowSpan: 2
0102                     Layout.alignment: Qt.AlignBottom
0103                     source: {
0104                         switch (pass.transitType) {
0105                             case KPkPass.BoardingPass.Air: return "qrc:///images/flight.svg"
0106                             case KPkPass.BoardingPass.Train: return "qrc:///images/train.svg"
0107                         }
0108                         return "go-next-symbolic";
0109                     }
0110                     Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0111                     Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium
0112                     color: pass.labelColor
0113                     isMask: true
0114                 }
0115 
0116                 QQC2.Label {
0117                     Layout.fillWidth: true
0118                     Layout.preferredWidth: primaryFieldsLayout.width/2 - Kirigami.Units.iconSizes.smallMedium
0119                     horizontalAlignment: Qt.AlignRight
0120                     text: pass.primaryFields[1].label
0121                     color: pass.labelColor
0122                     wrapMode: Text.WordWrap
0123                 }
0124                 QQC2.Label {
0125                     Layout.alignment: Qt.AlignRight
0126                     text: pass.primaryFields[1].valueDisplayString
0127                     color: pass.foregroundColor
0128                     font.pointSize: primaryValue.font.pointSize
0129                 }
0130             }
0131 
0132             // auxiliary fields
0133             GridLayout {
0134                 id: auxFieldsLayout
0135                 rows: 2
0136                 columns: pass.auxiliaryFields.length
0137                 Layout.fillWidth: true
0138 
0139                 Repeater {
0140                     model: pass.auxiliaryFields
0141                     delegate: QQC2.Label {
0142                         Layout.fillWidth: true
0143                         color: pass.labelColor
0144                         text: modelData.label
0145                         horizontalAlignment: modelData.textAlignment
0146                     }
0147                 }
0148                 Repeater {
0149                     model: pass.auxiliaryFields
0150                     delegate: QQC2.Label {
0151                         Layout.fillWidth: true
0152                         color: pass.foregroundColor
0153                         text: modelData.valueDisplayString
0154                         horizontalAlignment: modelData.textAlignment
0155                     }
0156                 }
0157             }
0158 
0159             // secondary fields
0160             GridLayout {
0161                 id: secFieldsLayout
0162                 rows: 2
0163                 columns: pass.secondaryFields.length
0164                 Layout.fillWidth: true
0165 
0166                 Repeater {
0167                     model: pass.secondaryFields
0168                     delegate: QQC2.Label {
0169                         Layout.fillWidth: true
0170                         color: pass.labelColor
0171                         text: modelData.label
0172                         horizontalAlignment: modelData.textAlignment
0173                     }
0174                 }
0175                 Repeater {
0176                     model: pass.secondaryFields
0177                     delegate: QQC2.Label {
0178                         Layout.fillWidth: true
0179                         color: pass.foregroundColor
0180                         text: modelData.valueDisplayString
0181                         horizontalAlignment: modelData.textAlignment
0182                     }
0183                 }
0184             }
0185 
0186             // footer
0187             Image {
0188                 source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/footer" : ""
0189                 sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
0190                 Layout.alignment: Qt.AlignCenter
0191             }
0192         }
0193 
0194         // barcode
0195         PkPassBarcode {
0196             maximumWidth: root.implicitWidth * 0.8
0197             pass: root.pass
0198             TapHandler {
0199                 onDoubleTapped: root.scanModeToggled()
0200             }
0201         }
0202 
0203         ColumnLayout {
0204             id: backLayout
0205             Layout.margins: __margin
0206 
0207             Kirigami.Separator {
0208                 visible: pass.backFields.length > 0
0209                 Layout.fillWidth: true
0210             }
0211             Repeater {
0212                 model: pass.backFields
0213                 ColumnLayout {
0214                     QQC2.Label {
0215                         Layout.fillWidth: true
0216                         color: pass.labelColor
0217                         text: modelData.label
0218                         wrapMode: Text.WordWrap
0219                         horizontalAlignment: modelData.textAlignment
0220                     }
0221                     QQC2.Label {
0222                         Layout.fillWidth: true
0223                         color: pass.foregroundColor
0224                         linkColor: color
0225                         text: Util.textToHtml(modelData.valueDisplayString)
0226                         textFormat: Util.isRichText(modelData.valueDisplayString) ? Text.StyledText : Text.AutoText
0227                         wrapMode: Text.WordWrap
0228                         horizontalAlignment: modelData.textAlignment
0229                         onLinkActivated: Qt.openUrlExternally(link)
0230                     }
0231                 }
0232             }
0233         }
0234     }
0235 
0236     ColumnLayout {
0237         id: backgroundLayout
0238         anchors.fill: topLayout
0239         spacing: 0
0240         z: -1
0241 
0242         Rectangle {
0243             id: headerBackground
0244             radius: __margin
0245             color: pass.backgroundColor
0246             Layout.fillWidth: true
0247             implicitHeight: headerLayout.implicitHeight + 2 * __margin
0248         }
0249 
0250         Rectangle {
0251             id: bodyBackground
0252             radius: __margin
0253             color: pass.backgroundColor
0254             Layout.fillWidth: true
0255             Layout.fillHeight: true
0256         }
0257     }
0258 }