[Clipboard Plasmoid] Port to Prison QML import

Which does the rendering and proper sizing for us, e.g. ensure integer scaling so the barcode remains scannable.
While at it, fix supportsBarcode (wasn't routed through to the delegate component when it was split out)
and add Code 128 which is in Prison now.
Also, show a label when the barcode would become too large to display (mostly for the 1D barcodes).
The Prison item does not use a thread for generating the barcode like the dataengine does but it's super fast.

Differential Revision: https://phabricator.kde.org/D29478
wilder-portage-prov
Kai Uwe Broulik 6 years ago
parent 281f44c79d
commit 7bd9bea072
  1. 123
      applets/clipboard/contents/ui/BarcodePage.qml
  2. 2
      applets/clipboard/contents/ui/ClipboardItemDelegate.qml
  3. 16
      applets/clipboard/contents/ui/ClipboardPage.qml
  4. 3
      applets/clipboard/contents/ui/DelegateToolButtons.qml
  5. 4
      applets/clipboard/contents/ui/Menu.qml

@ -23,29 +23,12 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.prison 1.0 as Prison
ColumnLayout { ColumnLayout {
id: barcodeView id: barcodeView
property var uuid: "" property alias text: barcodeItem.content
property int barcodeType: 0
function show(uuid) {
barcodeView.uuid = uuid;
barcodePreview.image = undefined;
barcodePreview.busy = true;
var service = clipboardSource.serviceForSource(uuid)
var operation = service.operationDescription("barcode");
operation.width = barcodePreview.width;
operation.height = barcodePreview.height;
operation.barcodeType = barcodeView.barcodeType;
var serviceJob = service.startOperationCall(operation);
serviceJob.finished.connect(function (job) {
if (!job.error) {
barcodePreview.image = job.result;
barcodePreview.busy = false;
}
});
}
property var header: PlasmaExtras.PlasmoidHeading { property var header: PlasmaExtras.PlasmoidHeading {
RowLayout { RowLayout {
@ -56,6 +39,12 @@ ColumnLayout {
text: i18n("Return to Clipboard") text: i18n("Return to Clipboard")
onClicked: stack.pop() onClicked: stack.pop()
} }
Component {
id: menuItemComponent
PlasmaComponents.MenuItem { }
}
PlasmaComponents.ContextMenu { PlasmaComponents.ContextMenu {
id: menu id: menu
visualParent: configureButton visualParent: configureButton
@ -66,40 +55,27 @@ ColumnLayout {
} }
} }
function change(type) { Component.onCompleted: {
barcodeView.barcodeType = type; [
barcodeView.show(barcodeView.uuid); {text: i18n("QR Code"), type: Prison.Barcode.QRCode},
} {text: i18n("Data Matrix"), type: Prison.Barcode.DataMatrix},
{text: i18nc("Aztec barcode", "Aztec"), type: Prison.Barcode.Aztec},
PlasmaComponents.MenuItem { {text: i18n("Code 39"), type: Prison.Barcode.Code39},
text: i18n("QR Code") {text: i18n("Code 93"), type: Prison.Barcode.Code93},
checkable: true {text: i18n("Code 128"), type: Prison.Barcode.Code128}
checked: barcodeView.barcodeType == 0 ].forEach((item) => {
onClicked: menu.change(0) let menuItem = menuItemComponent.createObject(menu, {
} text: item.text,
PlasmaComponents.MenuItem { checkable: true,
text: i18n("Data Matrix") checked: Qt.binding(() => {
checkable: true return barcodeItem.barcodeType === item.type;
checked: barcodeView.barcodeType == 1 })
onClicked: menu.change(1) });
} menuItem.clicked.connect(() => {
PlasmaComponents.MenuItem { barcodeItem.barcodeType = item.type;
text: i18nc("Aztec barcode", "Aztec") });
checkable: true menu.addMenuItem(menuItem);
checked: barcodeView.barcodeType == 4 });
onClicked: menu.change(4)
}
PlasmaComponents.MenuItem {
text: i18n("Code 39")
checkable: true
checked: barcodeView.barcodeType == 2
onClicked: menu.change(2)
}
PlasmaComponents.MenuItem {
text: i18n("Code 93")
checkable: true
checked: barcodeView.barcodeType == 3
onClicked: menu.change(3)
} }
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
@ -112,23 +88,36 @@ ColumnLayout {
} }
} }
QImageItem { Item {
id: barcodePreview Layout.fillWidth: parent
property alias busy: busyIndicator.visible Layout.fillHeight: parent
fillMode: QImageItem.PreserveAspectFit
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: units.smallSpacing Layout.topMargin: units.smallSpacing
onWidthChanged: barcodeView.show(barcodeView.uuid)
onHeightChanged: barcodeView.show(barcodeView.uuid) Prison.Barcode {
PlasmaComponents.BusyIndicator { id: barcodeItem
id: busyIndicator readonly property bool valid: implicitWidth > 0 && implicitHeight > 0 && implicitWidth <= width && implicitHeight <= height
anchors.centerIn: parent anchors.fill: parent
barcodeType: Prison.Barcode.QRCode
// Cannot set visible to false as we need it to re-render when changing its size
opacity: valid ? 1 : 0
} }
PlasmaComponents.Label { PlasmaComponents.Label {
anchors.centerIn: parent anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: i18n("Creating barcode failed") text: i18n("Creating barcode failed")
visible: !barcodePreview.busy && barcodePreview.null wrapMode: Text.WordWrap
visible: barcodeItem.implicitWidth === 0 && barcodeItem.implicitHeight === 0
}
PlasmaComponents.Label {
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: i18n("The barcode is too large to be displayed")
wrapMode: Text.WordWrap
visible: barcodeItem.implicitWidth > barcodeItem.width || barcodeItem.implicitHeight > barcodeItem.height
} }
} }
} }

@ -34,7 +34,7 @@ PlasmaComponents.ListItem {
signal itemSelected(string uuid) signal itemSelected(string uuid)
signal remove(string uuid) signal remove(string uuid)
signal edit(string uuid) signal edit(string uuid)
signal barcode(string uuid) signal barcode(string text)
signal action(string uuid) signal action(string uuid)
// the 1.6 comes from ToolButton's default height // the 1.6 comes from ToolButton's default height

@ -102,7 +102,16 @@ ColumnLayout {
filterRole: "DisplayRole" filterRole: "DisplayRole"
filterRegExp: filter.text filterRegExp: filter.text
} }
supportsBarcodes: clipboardSource.data["clipboard"]["supportsBarcodes"] supportsBarcodes: {
try {
let prisonTest = Qt.createQmlObject("import QtQml 2.0; import org.kde.prison 1.0; QtObject {}", this);
prisonTest.destroy();
} catch (e) {
console.log("Barcodes not supported:", e);
return false;
}
return true;
}
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.topMargin: units.smallSpacing Layout.topMargin: units.smallSpacing
@ -110,8 +119,9 @@ ColumnLayout {
onRemove: clipboardSource.service(uuid, "remove") onRemove: clipboardSource.service(uuid, "remove")
onEdit: clipboardSource.edit(uuid) onEdit: clipboardSource.edit(uuid)
onBarcode: { onBarcode: {
var page = stack.push(barcodePage); stack.push(barcodePage, {
page.show(uuid); text: text
});
} }
onAction: { onAction: {
clipboardSource.service(uuid, "action") clipboardSource.service(uuid, "action")

@ -36,7 +36,8 @@ Row {
id: barcodeToolButton id: barcodeToolButton
iconSource: "view-barcode-qr" iconSource: "view-barcode-qr"
tooltip: i18n("Show barcode") tooltip: i18n("Show barcode")
onClicked: menuItem.barcode(UuidRole) visible: supportsBarcodes
onClicked: menuItem.barcode(DisplayRole)
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
iconSource: "document-edit" iconSource: "document-edit"

@ -30,7 +30,7 @@ PlasmaExtras.ScrollArea {
signal itemSelected(string uuid) signal itemSelected(string uuid)
signal remove(string uuid) signal remove(string uuid)
signal edit(string uuid) signal edit(string uuid)
signal barcode(string uuid) signal barcode(string text)
signal action(string uuid) signal action(string uuid)
ListView { ListView {
@ -51,7 +51,7 @@ PlasmaExtras.ScrollArea {
onItemSelected: menu.itemSelected(uuid) onItemSelected: menu.itemSelected(uuid)
onRemove: menu.remove(uuid) onRemove: menu.remove(uuid)
onEdit: menu.edit(uuid) onEdit: menu.edit(uuid)
onBarcode: menu.barcode(uuid) onBarcode: menu.barcode(text)
onAction: menu.action(uuid) onAction: menu.action(uuid)
} }

Loading…
Cancel
Save