Purpose

barcodeplugin_config.qml
1/*
2 SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick 2.7
8import QtQuick.Window 2.12
9import QtQuick.Layouts 1.1
10import QtQuick.Controls 2.12 as QQC2
11import org.kde.kirigami 2.12 as Kirigami
12
13import org.kde.prison 1.0 as Prison
14
15ColumnLayout {
16 id: root
17
18 property var urls: []
19 property string mimeType
20 property var dummy
21
22 Component.onCompleted: {
23 root.Window.window.minimumWidth = Qt.binding(function() {
24 return Math.min(Kirigami.Units.gridUnit * 30,
25 root.implicitWidth + Kirigami.Units.gridUnit * 2);
26 });
27 root.Window.window.minimumHeight = Qt.binding(function() {
28 return Math.min(Kirigami.Units.gridUnit * 30,
29 root.implicitHeight + Kirigami.Units.gridUnit * 4);
30 });
31 }
32
33 Item {
34 Layout.fillWidth: true
35 Layout.fillHeight: true
36 Layout.preferredWidth: barcodeItem.implicitWidth
37 Layout.preferredHeight: barcodeItem.implicitHeight
38
40 id: barcodeItem
41 readonly property bool valid: implicitWidth > 0 && implicitHeight > 0 && implicitWidth <= width && implicitHeight <= height
42 anchors.fill: parent
43 barcodeType: Prison.Barcode.QRCode
44 // Cannot set visible to false as we need it to re-render when changing its size
45 opacity: valid ? 1 : 0
46 content: textField.text
47 }
48
49 QQC2.Label {
50 anchors.fill: parent
51 horizontalAlignment: Text.AlignHCenter
52 verticalAlignment: Text.AlignVCenter
53 text: i18nd("purpose6_barcode", "Type a URL or some text to generate a QR code")
54 wrapMode: Text.WordWrap
55 visible: textField.length === 0
56 }
57
58 QQC2.Label {
59 anchors.fill: parent
60 horizontalAlignment: Text.AlignHCenter
61 verticalAlignment: Text.AlignVCenter
62 text: i18nd("purpose6_barcode", "Creating QR code failed")
63 wrapMode: Text.WordWrap
64 visible: textField.length > 0 && barcodeItem.implicitWidth === 0 && barcodeItem.implicitHeight === 0
65 }
66
67 QQC2.Label {
68 anchors.fill: parent
69 horizontalAlignment: Text.AlignHCenter
70 verticalAlignment: Text.AlignVCenter
71 text: i18nd("purpose6_barcode", "The QR code is too large to be displayed")
72 wrapMode: Text.WordWrap
73 visible: textField.length > 0 && (barcodeItem.implicitWidth > barcodeItem.width || barcodeItem.implicitHeight > barcodeItem.height)
74 }
75 }
76
77 QQC2.TextField {
78 id: textField
79 Layout.fillWidth: true
80 text: root.urls[0]
81 // Random limit so it doesn't get too large
82 maximumLength: 250
83 placeholderText: i18nd("purpose6_barcode", "Type a URL or some text...")
84 Component.onCompleted: forceActiveFocus()
85 }
86}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString & fill(QChar ch, qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:07:47 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.