From 6e1b7cc727f12f9bd436cd4aa79fc6a2a845985f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Tue, 19 Aug 2014 05:24:28 +0200 Subject: [PATCH] Show previews for URLs in clipboard items We create a Listview inside the delegate which shows previews of the images. This is pretty rough right now, but able to show previews. Needs more polishing, specifically: - limit preview items (4?) - nicer image painting, probably cropping - proper height for delegates (through childrenRect) - icons for non-image filetypes --- .../contents/ui/ClipboardItemDelegate.qml | 79 ++++++++++++++++++- applets/clipboard/contents/ui/clipboard.qml | 2 +- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml index 8eecb80cf..ed5818535 100644 --- a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml +++ b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml @@ -56,17 +56,94 @@ PlasmaComponents.ListItem { PlasmaComponents.Label { height: implicitHeight width: parent.width + maximumLineCount: 3 text: DisplayRole - visible: TypeRole != 1 // TypeRole: 0: Text, 1: Image, 2: Url + visible: TypeRole == 0 // TypeRole: 0: Text, 1: Image, 2: Url textFormat: Text.PlainText } KQuickControlsAddons.QPixmapItem { + id: previewPixmap width: parent.width height: width * (nativeHeight/nativeWidth) pixmap: DecorationRole visible: TypeRole == 1 fillMode: KQuickControlsAddons.QPixmapItem.PreserveAspectFit } + Item { + visible: TypeRole == 2 + + height: units.gridUnit * 4 + width: parent.width + + Component.onCompleted: { + if (TypeRole == 2) { + print("DisplayRole: " + DisplayRole); + print(" sliced: " + DisplayRole.slice(7, DisplayRole.length)); + var urls = DisplayRole.slice(7, DisplayRole.length).split("file://"); + print("Model data inside delegate: " + urls); + for (var k in urls) { + print("_____________ KEY: " + k + " " + urls[k]); + } + previewList.model = urls + } + } + GridView { + id: previewList +// model: DisplayRole.split(" ") + + property int itemWidth: units.gridUnit * 4 + //orientation: Qt.Horizontal + anchors.fill: parent + //columns: parent.width / itemWidth + cellWidth: itemWidth + cellHeight: itemHeight + + + delegate: KQuickControlsAddons.QPixmapItem { + id: previewPixmap +// width: parent.width +// height: width * (nativeHeight/nativeWidth) + //pixmap: DecorationRole + width: previewList.itemWidth + height: previewList.itemWidth + //visible: TypeRole == 1 || TypeRole == 2 + fillMode: KQuickControlsAddons.QPixmapItem.PreserveAspectFit + Component.onCompleted: { + var service = clipboardSource.serviceForSource(UuidRole) + var operation = "preview"; + + function result(job) { + //print("result!.."); + if (!job.error) { + print("Cool!"); + print(" res: " + job.result["url"]); + pixmap = job.result["preview"]; + } else { + print("Job failed"); + } + //spixmap = job.result; + + //print("ServiceJob error: " + job.error + " result: " + job.result + " op: " + job.operationName); + } + + var operation = service.operationDescription(operation); + operation.urls = modelData; + //operation.password = password; + var serviceJob = service.startOperationCall(operation); + serviceJob.finished.connect(result); + print("JOb started: " + modelData); + + } + Rectangle { + border.width: 2 + border.color: "black" + color: "transparent" + anchors.fill: parent + } + } + } + + } } RowLayout { diff --git a/applets/clipboard/contents/ui/clipboard.qml b/applets/clipboard/contents/ui/clipboard.qml index ac784d2a4..788f9b854 100644 --- a/applets/clipboard/contents/ui/clipboard.qml +++ b/applets/clipboard/contents/ui/clipboard.qml @@ -65,7 +65,7 @@ Item { Plasmoid.fullRepresentation: Item { id: dialogItem Layout.minimumWidth: units.iconSizes.medium * 9 - Layout.minimumHeight: units.gridUnit * 13 + Layout.minimumHeight: units.gridUnit * 26 focus: true