Warning, /pim/itinerary/src/app/GenericPass.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2018-2022 Volker Krause <vkrause@kde.org>
0003 SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.pkpass as KPkPass
0011 import org.kde.itinerary
0012
0013 Rectangle {
0014 id: root
0015 property var pass: null
0016 property string passId
0017 implicitHeight: bodyBackground.implicitHeight
0018 implicitWidth: 332 //Math.max(topLayout.implicitWidth, 332)
0019
0020 color: Util.isValidColor(pass.backgroundColor) ? pass.backgroundColor : Kirigami.Theme.backgroundColor
0021 radius: 10
0022
0023 /** Double tap on the barcode to request scan mode. */
0024 signal scanModeToggled()
0025
0026 ColumnLayout {
0027 id: topLayout
0028 spacing: 10
0029 anchors.fill: parent
0030 anchors.margins: 6
0031 // HACK to break binding loop on implicitHeight
0032 onImplicitHeightChanged: root.implicitHeight = implicitHeight + 2 * topLayout.anchors.margins
0033
0034 // header
0035 GridLayout {
0036 id: headerLayout
0037 rows: 2
0038 columns: pass.headerFields.length + 2
0039 Layout.fillWidth: true
0040 Layout.maximumWidth: root.implicitWidth - 2 * topLayout.anchors.margins
0041
0042 Image {
0043 Layout.rowSpan: 2
0044 Layout.maximumHeight: 50
0045 Layout.maximumWidth: 160
0046 Layout.preferredWidth: paintedWidth
0047 fillMode: Image.PreserveAspectFit
0048 source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/logo" : ""
0049 sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
0050 }
0051
0052 QQC2.Label {
0053 Layout.rowSpan: 2
0054 Layout.fillWidth: pass ? true : false
0055 text: pass ? pass.logoText : ""
0056 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0057 }
0058
0059 Repeater {
0060 model: pass.headerFields
0061 delegate: QQC2.Label {
0062 text: modelData.label
0063 color: Util.isValidColor(pass.labelColor) ? pass.labelColor : Kirigami.Theme.textColor
0064 elide: Text.ElideRight
0065 Layout.fillWidth: true
0066 }
0067 }
0068 Repeater {
0069 model: pass.headerFields
0070 delegate: QQC2.Label {
0071 text: modelData.valueDisplayString
0072 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0073 elide: Text.ElideRight
0074 Layout.fillWidth: true
0075 }
0076 }
0077 }
0078
0079 // primary fields
0080 Kirigami.Separator {
0081 Layout.fillWidth: true
0082 }
0083 GridLayout {
0084 id: primaryFieldLayout
0085 rows: 2
0086 columns: pass.primaryFields.length + 1
0087 Layout.fillWidth: true
0088
0089 Repeater {
0090 model: pass.primaryFields
0091 delegate: QQC2.Label {
0092 Layout.fillWidth: true
0093 color: Util.isValidColor(pass.labelColor) ? pass.labelColor : Kirigami.Theme.textColor
0094 text: modelData.label
0095 horizontalAlignment: modelData.textAlignment
0096 }
0097 }
0098 Image {
0099 id: thumbnailImage
0100 Layout.rowSpan: 2
0101 source: "image://org.kde.pkpass/" + passId + "/thumbnail"
0102 sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
0103 Layout.alignment: Qt.AlignCenter
0104 Layout.preferredWidth: Math.min(90, thumbnailImage.implicitWidth); // 90x90 as per spec
0105 Layout.preferredHeight: (Layout.preferredWidth / thumbnailImage.implicitWidth) * thumbnailImage.implicitHeight
0106 fillMode: Image.PreserveAspectFit
0107 }
0108 Repeater {
0109 model: pass.primaryFields
0110 delegate: QQC2.Label {
0111 Layout.fillWidth: true
0112 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0113 text: modelData.valueDisplayString
0114 horizontalAlignment: modelData.textAlignment
0115 }
0116 }
0117 }
0118
0119 // secondary fields
0120 GridLayout {
0121 id: secFieldsLayout
0122 rows: 2
0123 columns: pass.secondaryFields.length
0124 Layout.fillWidth: true
0125
0126 Repeater {
0127 model: pass.secondaryFields
0128 delegate: QQC2.Label {
0129 Layout.fillWidth: true
0130 color: Util.isValidColor(pass.labelColor) ? pass.labelColor : Kirigami.Theme.textColor
0131 text: modelData.label
0132 horizontalAlignment: modelData.textAlignment
0133 }
0134 }
0135 Repeater {
0136 model: pass.secondaryFields
0137 delegate: QQC2.Label {
0138 Layout.fillWidth: true
0139 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0140 text: modelData.valueDisplayString
0141 horizontalAlignment: modelData.textAlignment
0142 }
0143 }
0144 }
0145
0146 // auxiliary fields
0147 GridLayout {
0148 id: auxFieldsLayout
0149 rows: 2
0150 columns: pass.auxiliaryFields.length
0151 Layout.fillWidth: true
0152
0153 Repeater {
0154 model: pass.auxiliaryFields
0155 delegate: QQC2.Label {
0156 Layout.fillWidth: true
0157 color: Util.isValidColor(pass.labelColor) ? pass.labelColor : Kirigami.Theme.textColor
0158 text: modelData.label
0159 horizontalAlignment: modelData.textAlignment
0160 }
0161 }
0162 Repeater {
0163 model: pass.auxiliaryFields
0164 delegate: QQC2.Label {
0165 Layout.fillWidth: true
0166 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0167 text: modelData.valueDisplayString
0168 horizontalAlignment: modelData.textAlignment
0169 }
0170 }
0171 }
0172
0173 // barcode
0174 PkPassBarcode {
0175 maximumWidth: root.implicitWidth * 0.8
0176 pass: root.pass
0177 TapHandler {
0178 onDoubleTapped: scanModeToggled()
0179 }
0180 }
0181
0182 // back fields
0183 Kirigami.Separator {
0184 Layout.fillWidth: true
0185 }
0186 Repeater {
0187 model: pass.backFields
0188 ColumnLayout {
0189 QQC2.Label {
0190 Layout.fillWidth: true
0191 color: Util.isValidColor(pass.labelColor) ? pass.labelColor : Kirigami.Theme.textColor
0192 text: modelData.label
0193 wrapMode: Text.WordWrap
0194 horizontalAlignment: modelData.textAlignment
0195 }
0196 QQC2.Label {
0197 Layout.fillWidth: true
0198 color: Util.isValidColor(pass.foregroundColor) ? pass.foregroundColor : Kirigami.Theme.textColor
0199 linkColor: color
0200 text: Util.textToHtml(modelData.valueDisplayString)
0201 textFormat: Util.isRichText(modelData.valueDisplayString) ? Text.StyledText : Text.AutoText
0202 wrapMode: Text.WordWrap
0203 horizontalAlignment: modelData.textAlignment
0204 onLinkActivated: Qt.openUrlExternally(link)
0205 }
0206 }
0207 }
0208 }
0209 }