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
7pragma ComponentBehavior: Bound
8
9import QtQuick
10import QtQuick.Controls as QQC2
11import QtQuick.Layouts
12
13import org.kde.kirigami as Kirigami
14import org.kde.prison as Prison
15
16ColumnLayout {
17 id: root
18
19 property list<string> urls
20
21 spacing: Kirigami.Units.smallSpacing
22
23 Item {
24 Layout.fillWidth: true
25 Layout.fillHeight: true
26 Layout.preferredWidth: Kirigami.Units.gridUnit * 10
27 Layout.preferredHeight: Kirigami.Units.gridUnit * 10
28
30 id: barcodeItem
31 readonly property bool valid: implicitWidth > 0 && implicitHeight > 0 && implicitWidth <= width && implicitHeight <= height
32 anchors.fill: parent
33 barcodeType: Prison.Barcode.QRCode
34 // Cannot set visible to false as we need it to re-render when changing its size
35 opacity: valid ? 1 : 0
36 content: textField.text
37 }
38
39 QQC2.Label {
40 anchors.fill: parent
41 horizontalAlignment: Text.AlignHCenter
42 verticalAlignment: Text.AlignVCenter
43 text: {
44 if (textField.length === 0) {
45 return i18nd("purpose6_barcode", "Type a URL or some text to generate a QR code");
46 } else if (textField.length > 0 && barcodeItem.implicitWidth === 0 && barcodeItem.implicitHeight === 0) {
47 return i18nd("purpose6_barcode", "Creating QR code failed");
48 } else if (textField.length > 0 && (barcodeItem.implicitWidth > barcodeItem.width || barcodeItem.implicitHeight > barcodeItem.height)) {
49 return i18nd("purpose6_barcode", "The QR code is too large to be displayed");
50 } else {
51 return "";
52 }
53 }
54 wrapMode: Text.Wrap
55 }
56 }
57
58 QQC2.TextField {
59 id: textField
60 Layout.fillWidth: true
61 text: root.urls[0]
62 // Random limit so it doesn't get too large
63 maximumLength: 250
64 placeholderText: i18nd("purpose6_barcode", "Type a URL or some text…")
65 Component.onCompleted: forceActiveFocus()
66 }
67}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.