diff --git a/applets/clipboard/contents/ui/BarcodePage.qml b/applets/clipboard/contents/ui/BarcodePage.qml index 6a987d3b2..485cecf8d 100644 --- a/applets/clipboard/contents/ui/BarcodePage.qml +++ b/applets/clipboard/contents/ui/BarcodePage.qml @@ -1,134 +1,123 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2015 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.prison 1.0 as Prison + ColumnLayout { id: barcodeView - property var uuid: "" - 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 alias text: barcodeItem.content property var header: PlasmaExtras.PlasmoidHeading { RowLayout { anchors.fill: parent PlasmaComponents.Button { Layout.fillWidth: true iconSource: "go-previous-view" text: i18n("Return to Clipboard") onClicked: stack.pop() } + + Component { + id: menuItemComponent + PlasmaComponents.MenuItem { } + } + PlasmaComponents.ContextMenu { id: menu visualParent: configureButton placement: PlasmaCore.Types.BottomPosedLeftAlignedPopup onStatusChanged: { if (status == PlasmaComponents.DialogStatus.Closed) { configureButton.checked = false; } } - function change(type) { - barcodeView.barcodeType = type; - barcodeView.show(barcodeView.uuid); - } - - PlasmaComponents.MenuItem { - text: i18n("QR Code") - checkable: true - checked: barcodeView.barcodeType == 0 - onClicked: menu.change(0) - } - PlasmaComponents.MenuItem { - text: i18n("Data Matrix") - checkable: true - checked: barcodeView.barcodeType == 1 - onClicked: menu.change(1) - } - PlasmaComponents.MenuItem { - text: i18nc("Aztec barcode", "Aztec") - checkable: true - 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) + Component.onCompleted: { + [ + {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}, + {text: i18n("Code 39"), type: Prison.Barcode.Code39}, + {text: i18n("Code 93"), type: Prison.Barcode.Code93}, + {text: i18n("Code 128"), type: Prison.Barcode.Code128} + ].forEach((item) => { + let menuItem = menuItemComponent.createObject(menu, { + text: item.text, + checkable: true, + checked: Qt.binding(() => { + return barcodeItem.barcodeType === item.type; + }) + }); + menuItem.clicked.connect(() => { + barcodeItem.barcodeType = item.type; + }); + menu.addMenuItem(menuItem); + }); } } PlasmaComponents.ToolButton { id: configureButton checkable: true iconSource: "configure" tooltip: i18n("Change the barcode type") onClicked: menu.openRelative() } } } - QImageItem { - id: barcodePreview - property alias busy: busyIndicator.visible - fillMode: QImageItem.PreserveAspectFit - Layout.fillWidth: true - Layout.fillHeight: true + Item { + Layout.fillWidth: parent + Layout.fillHeight: parent Layout.topMargin: units.smallSpacing - onWidthChanged: barcodeView.show(barcodeView.uuid) - onHeightChanged: barcodeView.show(barcodeView.uuid) - PlasmaComponents.BusyIndicator { - id: busyIndicator - anchors.centerIn: parent + + Prison.Barcode { + id: barcodeItem + readonly property bool valid: implicitWidth > 0 && implicitHeight > 0 && implicitWidth <= width && implicitHeight <= height + 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 { - anchors.centerIn: parent + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter 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 } } } diff --git a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml index 4a80290ee..e365d1923 100644 --- a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml +++ b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml @@ -1,125 +1,125 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright 2014 Sebastian Kügler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.0 import QtQuick.Layouts 1.1 import QtGraphicalEffects 1.0 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons PlasmaComponents.ListItem { id: menuItem property bool supportsBarcodes property int maximumNumberOfPreviews: Math.floor(width / (units.gridUnit * 4 + units.smallSpacing)) readonly property real gradientThreshold: (label.width - toolButtonsLoader.width) / label.width signal itemSelected(string uuid) signal remove(string uuid) signal edit(string uuid) - signal barcode(string uuid) + signal barcode(string text) signal action(string uuid) // the 1.6 comes from ToolButton's default height height: Math.max(label.height, Math.round(units.gridUnit * 1.6)) + 2 * units.smallSpacing enabled: true onClicked: { menuItem.itemSelected(UuidRole); if (plasmoid.hideOnWindowDeactivate) plasmoid.expanded = false; } onContainsMouseChanged: { if (containsMouse) { menuListView.currentIndex = index } else { menuListView.currentIndex = -1 } } ListView.onIsCurrentItemChanged: { if (ListView.isCurrentItem) { labelMask.source = label // calculate on demand } } // this stuff here is used so we can fade out the text behind the tool buttons Item { id: labelMaskSource anchors.fill: label visible: false Rectangle { anchors.centerIn: parent rotation: LayoutMirroring.enabled ? 90 : -90 // you cannot even rotate gradients without QtGraphicalEffects width: parent.height height: parent.width gradient: Gradient { GradientStop { position: 0.0; color: "white" } GradientStop { position: gradientThreshold - 0.25; color: "white"} GradientStop { position: gradientThreshold; color: "transparent"} GradientStop { position: 1; color: "transparent"} } } } OpacityMask { id: labelMask anchors.fill: label cached: true maskSource: labelMaskSource visible: !!source && menuItem.ListView.isCurrentItem } Item { id: label height: childrenRect.height visible: !menuItem.ListView.isCurrentItem anchors { left: parent.left leftMargin: units.gridUnit / 2 - listMargins.left right: parent.right verticalCenter: parent.verticalCenter } Loader { width: parent.width source: ["Text", "Image", "Url"][TypeRole] + "ItemDelegate.qml" } } Loader { id: toolButtonsLoader anchors { right: label.right verticalCenter: parent.verticalCenter } source: "DelegateToolButtons.qml" active: menuItem.ListView.isCurrentItem onActiveChanged: { if (active) { // break binding, once it was loaded, never unload active = true; } } } } diff --git a/applets/clipboard/contents/ui/ClipboardPage.qml b/applets/clipboard/contents/ui/ClipboardPage.qml index e60ec80b6..592d7ed6d 100644 --- a/applets/clipboard/contents/ui/ClipboardPage.qml +++ b/applets/clipboard/contents/ui/ClipboardPage.qml @@ -1,121 +1,131 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright (C) 2014 Kai Uwe Broulik This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.4 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras ColumnLayout { Keys.onPressed: { switch(event.key) { case Qt.Key_Up: { clipboardMenu.view.decrementCurrentIndex(); event.accepted = true; break; } case Qt.Key_Down: { clipboardMenu.view.incrementCurrentIndex(); event.accepted = true; break; } case Qt.Key_Enter: case Qt.Key_Return: { if (clipboardMenu.view.currentIndex >= 0) { var uuid = clipboardMenu.model.get(clipboardMenu.view.currentIndex).UuidRole if (uuid) { clipboardSource.service(uuid, "select") clipboardMenu.view.currentIndex = 0 } } break; } case Qt.Key_Escape: { if (filter.text != "") { filter.text = ""; event.accepted = true; } break; } default: { // forward key to filter // filter.text += event.text wil break if the key is backspace if (event.key === Qt.Key_Backspace && filter.text == "") { return; } if (event.text !== "" && !filter.activeFocus) { clipboardMenu.view.currentIndex = -1 if (event.matches(StandardKey.Paste)) { filter.paste(); } else { filter.text = ""; filter.text += event.text; } filter.forceActiveFocus(); event.accepted = true; } } } } property var header: PlasmaExtras.PlasmoidHeading { RowLayout { anchors.fill: parent enabled: clipboardMenu.model.count > 0 PlasmaComponents.TextField { id: filter placeholderText: i18n("Search...") clearButtonShown: true Layout.fillWidth: true } PlasmaComponents.ToolButton { iconSource: "edit-clear-history" tooltip: i18n("Clear history") onClicked: clipboardSource.service("", "clearHistory") } } } Menu { id: clipboardMenu model: PlasmaCore.SortFilterModel { sourceModel: clipboardSource.models.clipboard filterRole: "DisplayRole" 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.fillHeight: true Layout.topMargin: units.smallSpacing onItemSelected: clipboardSource.service(uuid, "select") onRemove: clipboardSource.service(uuid, "remove") onEdit: clipboardSource.edit(uuid) onBarcode: { - var page = stack.push(barcodePage); - page.show(uuid); + stack.push(barcodePage, { + text: text + }); } onAction: { clipboardSource.service(uuid, "action") clipboardMenu.view.currentIndex = 0 } } } diff --git a/applets/clipboard/contents/ui/DelegateToolButtons.qml b/applets/clipboard/contents/ui/DelegateToolButtons.qml index 0a5e6a70c..cee5e8bcb 100644 --- a/applets/clipboard/contents/ui/DelegateToolButtons.qml +++ b/applets/clipboard/contents/ui/DelegateToolButtons.qml @@ -1,53 +1,54 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin Copyright 2014 Sebastian Kügler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents Row { id: toolButtonsLayout visible: menuItem.ListView.isCurrentItem PlasmaComponents.ToolButton { // TODO: only show for items supporting actions? iconSource: "system-run" tooltip: i18n("Invoke action") onClicked: menuItem.action(UuidRole) } PlasmaComponents.ToolButton { id: barcodeToolButton iconSource: "view-barcode-qr" tooltip: i18n("Show barcode") - onClicked: menuItem.barcode(UuidRole) + visible: supportsBarcodes + onClicked: menuItem.barcode(DisplayRole) } PlasmaComponents.ToolButton { iconSource: "document-edit" enabled: !clipboardSource.editing visible: TypeRole === 0 tooltip: i18n("Edit contents") onClicked: menuItem.edit(UuidRole) } PlasmaComponents.ToolButton { iconSource: "edit-delete" tooltip: i18n("Remove from history") onClicked: menuItem.remove(UuidRole) } } diff --git a/applets/clipboard/contents/ui/Menu.qml b/applets/clipboard/contents/ui/Menu.qml index 42fd6b61c..0bd6064a5 100644 --- a/applets/clipboard/contents/ui/Menu.qml +++ b/applets/clipboard/contents/ui/Menu.qml @@ -1,68 +1,68 @@ /******************************************************************** This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.0 import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kirigami 2.12 as Kirigami PlasmaExtras.ScrollArea { id: menu property alias view: menuListView property alias model: menuListView.model property bool supportsBarcodes signal itemSelected(string uuid) signal remove(string uuid) signal edit(string uuid) - signal barcode(string uuid) + signal barcode(string text) signal action(string uuid) ListView { id: menuListView focus: true boundsBehavior: Flickable.StopAtBounds interactive: contentHeight > height highlight: PlasmaComponents.Highlight { } highlightMoveDuration: 0 highlightResizeDuration: 0 currentIndex: -1 delegate: ClipboardItemDelegate { width: menuListView.width supportsBarcodes: menu.supportsBarcodes onItemSelected: menu.itemSelected(uuid) onRemove: menu.remove(uuid) onEdit: menu.edit(uuid) - onBarcode: menu.barcode(uuid) + onBarcode: menu.barcode(text) onAction: menu.action(uuid) } Kirigami.PlaceholderMessage { id: emptyHint anchors.centerIn: parent width: parent.width - (units.largeSpacing * 4) visible: menuListView.count === 0 text: i18n("Clipboard is empty") } } }