Changeset View
Changeset View
Standalone View
Standalone View
applets/clipboard/contents/ui/UrlItemDelegate.qml
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | This file is part of the KDE project. | ||||
3 | | ||||
4 | Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org> | ||||
5 | Copyright 2014 Sebastian Kügler <sebas@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | import QtQuick 2.0 | ||||
22 | | ||||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
24 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | ||||
25 | | ||||
26 | Item { | ||||
27 | id: previewItem | ||||
28 | height: units.gridUnit * 4 + units.smallSpacing * 2 | ||||
29 | | ||||
30 | ListView { | ||||
31 | id: previewList | ||||
32 | model: DisplayRole.split(" ", maximumNumberOfPreviews) | ||||
33 | property int itemWidth: units.gridUnit * 4 | ||||
34 | property int itemHeight: units.gridUnit * 4 | ||||
35 | interactive: false | ||||
36 | | ||||
37 | spacing: units.smallSpacing | ||||
38 | orientation: Qt.Horizontal | ||||
39 | width: (itemWidth + spacing) * model.length | ||||
40 | anchors { | ||||
41 | top: parent.top | ||||
42 | left: parent.left | ||||
43 | bottom: parent.bottom | ||||
44 | } | ||||
45 | | ||||
46 | delegate: Item { | ||||
47 | width: previewList.itemWidth | ||||
48 | height: previewList.itemHeight | ||||
49 | y: Math.round((parent.height - previewList.itemHeight) / 2) | ||||
50 | clip: true | ||||
51 | | ||||
52 | KQuickControlsAddons.QPixmapItem { | ||||
53 | id: previewPixmap | ||||
54 | | ||||
55 | anchors.centerIn: parent | ||||
56 | | ||||
57 | Component.onCompleted: { | ||||
58 | function result(job) { | ||||
59 | if (!job.error) { | ||||
60 | pixmap = job.result.preview; | ||||
61 | previewPixmap.width = job.result.previewWidth | ||||
62 | previewPixmap.height = job.result.previewHeight | ||||
63 | } | ||||
64 | } | ||||
65 | var service = clipboardSource.serviceForSource(UuidRole) | ||||
66 | var operation = service.operationDescription("preview"); | ||||
67 | operation.url = modelData; | ||||
68 | // We request a bigger size and then clip out a square in the middle | ||||
69 | // so we get uniform delegate sizes without distortion | ||||
70 | operation.previewWidth = previewList.itemWidth * 2; | ||||
71 | operation.previewHeight = previewList.itemHeight * 2; | ||||
72 | var serviceJob = service.startOperationCall(operation); | ||||
73 | serviceJob.finished.connect(result); | ||||
74 | } | ||||
75 | } | ||||
76 | Rectangle { | ||||
77 | id: overlay | ||||
78 | color: theme.textColor | ||||
79 | opacity: 0.6 | ||||
80 | height: units.gridUnit | ||||
81 | anchors { | ||||
82 | left: parent.left | ||||
83 | right: parent.right | ||||
84 | bottom: parent.bottom | ||||
85 | } | ||||
86 | } | ||||
87 | PlasmaComponents.Label { | ||||
88 | font.pointSize: theme.smallestFont.pointSize | ||||
89 | color: theme.backgroundColor | ||||
90 | maximumLineCount: 1 | ||||
91 | anchors { | ||||
92 | verticalCenter: overlay.verticalCenter | ||||
93 | left: overlay.left | ||||
94 | right: overlay.right | ||||
95 | leftMargin: units.smallSpacing | ||||
96 | rightMargin: units.smallSpacing | ||||
97 | } | ||||
98 | elide: Text.ElideRight | ||||
99 | horizontalAlignment: Text.AlignHCenter | ||||
100 | text: { | ||||
101 | var u = modelData.split("/"); | ||||
102 | return decodeURIComponent(u[u.length - 1]); | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | } | ||||
107 | PlasmaComponents.Label { | ||||
108 | property int additionalItems: DisplayRole.split(" ").length - maximumNumberOfPreviews | ||||
109 | visible: additionalItems > 0 | ||||
110 | opacity: 0.6 | ||||
111 | text: i18nc("Indicator that there are more urls in the clipboard than previews shown", "+%1", additionalItems) | ||||
112 | anchors { | ||||
113 | left: previewList.right | ||||
114 | right: parent.right | ||||
115 | bottom: parent.bottom | ||||
116 | margins: units.smallSpacing | ||||
117 | | ||||
118 | } | ||||
119 | verticalAlignment: Text.AlignBottom | ||||
120 | horizontalAlignment: Text.AlignCenter | ||||
121 | font.pointSize: theme.smallestFont.pointSize | ||||
122 | } | ||||
123 | } |