Warning, /plasma/plasma-workspace/applets/clipboard/contents/ui/BarcodePage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts 1.1
0009 import org.kde.plasma.components 3.0 as PlasmaComponents3
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.kquickcontrolsaddons 2.0
0012 import org.kde.plasma.extras 2.0 as PlasmaExtras
0013 import org.kde.kirigami 2.20 as Kirigami
0014 
0015 import org.kde.prison 1.0 as Prison
0016 
0017 ColumnLayout {
0018     id: barcodeView
0019 
0020     property alias text: barcodeItem.content
0021 
0022     readonly property var barcodeMap: [
0023         {text: i18n("QR Code"), type: Prison.Barcode.QRCode, code: "QRCode"},
0024         {text: i18n("Data Matrix"), type: Prison.Barcode.DataMatrix, code: "DataMatrix"},
0025         {text: i18nc("Aztec barcode", "Aztec"), type: Prison.Barcode.Aztec, code: "Aztec"},
0026         {text: i18n("Code 39"), type: Prison.Barcode.Code39, code: "Code39"},
0027         {text: i18n("Code 93"), type: Prison.Barcode.Code93, code: "Code93"},
0028         {text: i18n("Code 128"), type: Prison.Barcode.Code128, code: "Code128"}
0029     ]
0030 
0031     Keys.onPressed: event => {
0032         if (event.key == Qt.Key_Escape) {
0033             stack.pop()
0034             event.accepted = true;
0035         }
0036     }
0037 
0038     property PlasmaExtras.PlasmoidHeading header: PlasmaExtras.PlasmoidHeading {
0039         RowLayout {
0040             anchors.fill: parent
0041             PlasmaComponents3.Button {
0042                 Layout.fillWidth: true
0043                 icon.name: "go-previous-view"
0044                 text: i18n("Return to Clipboard")
0045                 onClicked: stack.pop()
0046             }
0047 
0048             PlasmaComponents3.Menu {
0049                 id: menu
0050             }
0051 
0052             Instantiator {
0053                 id: menuItemInstantiator
0054                 active: main.expanded && menu.opened
0055                 asynchronous: true
0056                 delegate: PlasmaComponents3.MenuItem {
0057                     text: modelData.text
0058                     checkable: true
0059                     autoExclusive: true
0060                     checked: barcodeItem.barcodeType === modelData.type
0061 
0062                     onClicked: {
0063                         barcodeItem.barcodeType = modelData.type;
0064                         Plasmoid.configuration.barcodeType = modelData.code;
0065                     }
0066                 }
0067                 model: barcodeView.barcodeMap
0068 
0069                 onObjectAdded: (index, object) => menu.insertItem(index, object)
0070             }
0071 
0072             PlasmaComponents3.ToolButton {
0073                 id: configureButton
0074                 checkable: true
0075                 checked: menu.opened
0076                 icon.name: "configure"
0077 
0078                 display: PlasmaComponents3.AbstractButton.IconOnly
0079                 text: i18n("Change the QR code type")
0080 
0081                 onClicked: menu.opened ? menu.close() : menu.popup()
0082 
0083                 PlasmaComponents3.ToolTip {
0084                     text: parent.text
0085                 }
0086             }
0087         }
0088     }
0089 
0090     Item {
0091         Layout.fillWidth: parent
0092         Layout.fillHeight: parent
0093         Layout.topMargin: Kirigami.Units.smallSpacing
0094 
0095         Prison.Barcode {
0096             id: barcodeItem
0097             readonly property bool valid: implicitWidth > 0 && implicitHeight > 0 && implicitWidth <= width && implicitHeight <= height
0098             anchors.fill: parent
0099             barcodeType: barcodeView.barcodeMap.find(data => data.code === Plasmoid.configuration.barcodeType)?.type ?? barcodeView.barcodeMap[0].type
0100             // Cannot set visible to false as we need it to re-render when changing its size
0101             opacity: valid ? 1 : 0
0102 
0103             Accessible.name: barcodeView.barcodeMap.find(data => data.type === barcodeItem.barcodeType)?.text ?? barcodeView.barcodeMap[0].text
0104             Accessible.role: Accessible.Graphic
0105             Drag.dragType: Drag.Automatic
0106             Drag.supportedActions: Qt.CopyAction
0107 
0108             HoverHandler {
0109                 enabled: barcodeItem.valid
0110                 cursorShape: Qt.OpenHandCursor
0111             }
0112 
0113             DragHandler {
0114                 id: dragHandler
0115                 enabled: barcodeItem.valid
0116 
0117                 onActiveChanged: {
0118                     if (active) {
0119                         barcodeItem.grabToImage((result) => {
0120                             barcodeItem.Drag.mimeData = {
0121                                 "image/png": result.image,
0122                             };
0123                             barcodeItem.Drag.active = dragHandler.active;
0124                         });
0125                     } else {
0126                         barcodeItem.Drag.active = false;
0127                     }
0128                 }
0129             }
0130         }
0131 
0132         PlasmaComponents3.Label {
0133             anchors.fill: parent
0134             horizontalAlignment: Text.AlignHCenter
0135             verticalAlignment: Text.AlignVCenter
0136             text: i18n("Creating QR code failed")
0137             textFormat: Text.PlainText
0138             wrapMode: Text.WordWrap
0139             visible: barcodeItem.implicitWidth === 0 && barcodeItem.implicitHeight === 0
0140         }
0141 
0142         PlasmaComponents3.Label {
0143             anchors.fill: parent
0144             leftPadding: Kirigami.Units.gridUnit * 2
0145             rightPadding: Kirigami.Units.gridUnit * 2
0146             horizontalAlignment: Text.AlignHCenter
0147             verticalAlignment: Text.AlignVCenter
0148             text: i18n("There is not enough space to display the QR code. Try resizing this applet.")
0149             textFormat: Text.PlainText
0150             wrapMode: Text.WordWrap
0151             visible: barcodeItem.implicitWidth > barcodeItem.width || barcodeItem.implicitHeight > barcodeItem.height
0152         }
0153     }
0154 }