EventTicket.qml 8.29 KB
Newer Older
1
/*
2
    SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
9
10
*/

import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import QtGraphicalEffects 1.0 as Effects
11
import org.kde.kirigami 2.17 as Kirigami
12
import org.kde.pkpass 1.0 as KPkPass
13
import org.kde.itinerary 1.0
14
import "." as App
15
16

Item {
Volker Krause's avatar
Volker Krause committed
17
    id: root
18
19
    property var pass: null
    property string passId
Volker Krause's avatar
Volker Krause committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    implicitHeight: bodyBackground.implicitHeight
    implicitWidth: 332 //Math.max(topLayout.implicitWidth, 332)

    Rectangle {
        id: bodyBackground
        color: pass.backgroundColor
        //implicitHeight: topLayout.implicitHeight + 2 * topLayout.anchors.margins
        width: parent.width

        Image {
            id: backgroundImage
            source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/background" : ""
            fillMode: Image.PreserveAspectFit
            x: -(implicitWidth - bodyBackground.width) / 2
            y: 0
            visible: false
        }
        Effects.FastBlur {
            anchors.fill: backgroundImage
            source: backgroundImage
            radius: 32
        }
42

Volker Krause's avatar
Volker Krause committed
43
44
45
46
        ColumnLayout {
            id: topLayout
            spacing: 10
            anchors.fill: parent
47
            anchors.margins: 6
Volker Krause's avatar
Volker Krause committed
48
49
            // HACK to break binding loop on implicitHeight
            onImplicitHeightChanged: bodyBackground.implicitHeight = implicitHeight + 2 * topLayout.anchors.margins
50

51

52
53
54
55
56
57
58
59
60
61
62
63
64
            ColumnLayout {
                id: bodyLayout
                spacing: 10

                // header
                GridLayout {
                    id: headerLayout
                    rows: 2
                    columns: pass.headerFields.length + 2
                    Layout.fillWidth: true

                    Image {
                        Layout.rowSpan: 2
Volker Krause's avatar
Volker Krause committed
65
66
67
68
                        Layout.maximumHeight: 60
                        Layout.maximumWidth: 150
                        Layout.preferredWidth: paintedWidth
                        fillMode: Image.PreserveAspectFit
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
                        source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/logo" : ""
                        sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
                    }

                    QQC2.Label {
                        Layout.rowSpan: 2
                        Layout.fillWidth: pass ? true : false
                        text: pass ? pass.logoText : ""
                        color: pass.foregroundColor
                    }

                    Repeater {
                        model: pass.headerFields
                        delegate: QQC2.Label {
                            text: modelData.label
                            color: pass.labelColor
                        }
                    }
                    Repeater {
                        model: pass.headerFields
                        delegate: QQC2.Label {
90
                            text: modelData.valueDisplayString
91
92
93
94
95
96
97
                            color: pass.foregroundColor
                        }
                    }
                }

                // strip image
                Image {
98
                    id: stripImage
99
100
101
                    source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/strip" : ""
                    sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
                    Layout.alignment: Qt.AlignCenter
102
                    Layout.preferredWidth: Math.min(320, stripImage.implicitWidth); // 320 as per spec
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
                }

                // primary fields
                 GridLayout {
                    id: primaryFieldLayout
                    rows: 2
                    columns: pass.primaryFields.length
                    Layout.fillWidth: true

                    Repeater {
                        model: pass.primaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.labelColor
                            text: modelData.label
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                    Repeater {
                        model: pass.primaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.foregroundColor
126
                            text: modelData.valueDisplayString
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                }

                // 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
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                    Repeater {
                        model: pass.secondaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.foregroundColor
153
                            text: modelData.valueDisplayString
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                }

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

                    Repeater {
                        model: pass.auxiliaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.labelColor
                            text: modelData.label
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                    Repeater {
                        model: pass.auxiliaryFields
                        delegate: QQC2.Label {
                            Layout.fillWidth: true
                            color: pass.foregroundColor
180
                            text: modelData.valueDisplayString
181
182
183
184
                            horizontalAlignment: modelData.textAlignment
                        }
                    }
                }
Volker Krause's avatar
Volker Krause committed
185
            }
186

Volker Krause's avatar
Volker Krause committed
187
188
            // barcode
            App.PkPassBarcode { pass: root.pass }
189

Volker Krause's avatar
Volker Krause committed
190
191
192
193
194
195
            // footer
            Image {
                source: passId !== "" ? "image://org.kde.pkpass/" + passId + "/footer" : ""
                sourceSize.height: 1 // ??? seems necessary to trigger high dpi scaling...
                Layout.alignment: Qt.AlignCenter
            }
196

Volker Krause's avatar
Volker Krause committed
197
198
199
200
201
202
203
204
205
206
207
208
            // back fields
            Kirigami.Separator {
                Layout.fillWidth: true
            }
            Repeater {
                model: pass.backFields
                ColumnLayout {
                    QQC2.Label {
                        Layout.fillWidth: true
                        color: pass.labelColor
                        text: modelData.label
                        wrapMode: Text.WordWrap
209
                        horizontalAlignment: modelData.textAlignment
Volker Krause's avatar
Volker Krause committed
210
211
212
213
                    }
                    QQC2.Label {
                        Layout.fillWidth: true
                        color: pass.foregroundColor
214
                        text: Util.textToHtml(modelData.valueDisplayString)
Volker Krause's avatar
Volker Krause committed
215
                        wrapMode: Text.WordWrap
216
                        horizontalAlignment: modelData.textAlignment
217
                        onLinkActivated: Qt.openUrlExternally(link)
Volker Krause's avatar
Volker Krause committed
218
219
                    }
                }
220
221
222
223
            }
        }

        Rectangle {
224
            id: notchMask
225
226
227
            width: parent.width / 4
            height: width
            radius: width / 2
228
            color: Kirigami.Theme.backgroundColor
229
230
231
232
233
234
            x: parent.width/2 - radius
            y: -radius * 1.5
        }
    }
}