Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/ThumbnailStrip.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.0 | ||||
21 | import QtQuick.Layouts 1.1 | ||||
22 | | ||||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
25 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
26 | | ||||
27 | import org.kde.kquickcontrolsaddons 2.0 | ||||
28 | | ||||
29 | import org.kde.plasma.private.notifications 1.0 as Notifications | ||||
30 | | ||||
31 | ListView { | ||||
32 | id: previewList | ||||
33 | | ||||
34 | readonly property int itemSquareSize: units.gridUnit * 4 | ||||
35 | | ||||
36 | // if it's only one file, show a larger preview | ||||
37 | // however if no preview could be generated, which we only know after we tried, | ||||
38 | // the delegate will use itemSquareSize instead as there's no point in showing a huge file icon | ||||
39 | readonly property int itemWidth: previewList.count === 1 ? width : itemSquareSize | ||||
40 | readonly property int itemHeight: previewList.count === 1 ? Math.round(width / 3) : itemSquareSize | ||||
41 | | ||||
42 | // by the time the "model" is populated, the Layout isn't finished yet, causing ListView to have a 0 width | ||||
43 | // hence it's based on the mainLayout.width instead | ||||
44 | readonly property int maximumItemCount: Math.floor(mainLayout.width / itemSquareSize) | ||||
45 | | ||||
46 | model: { | ||||
47 | var urls = notificationItem.urls | ||||
48 | if (urls.length <= maximumItemCount) { | ||||
49 | return urls | ||||
50 | } | ||||
51 | // if it wouldn't fit, remove one item in favor of the "+n" badge | ||||
52 | return urls.slice(0, maximumItemCount - 1) | ||||
53 | } | ||||
54 | orientation: ListView.Horizontal | ||||
55 | spacing: units.smallSpacing | ||||
56 | interactive: false | ||||
57 | | ||||
58 | footer: notificationItem.urls.length > maximumItemCount ? moreBadge : null | ||||
59 | | ||||
60 | function pressedAction() { | ||||
61 | for (var i = 0; i < count; ++i) { | ||||
62 | var item = itemAtIndex(i) | ||||
63 | if (item.pressed) { | ||||
64 | return item | ||||
65 | } | ||||
66 | } | ||||
67 | } | ||||
68 | | ||||
69 | // HACK ListView only provides itemAt(x,y) methods but since we don't scroll | ||||
70 | // we can make assumptions on what our layout looks like... | ||||
71 | function itemAtIndex(index) { | ||||
72 | return itemAt(index * (itemSquareSize + spacing), 0) | ||||
73 | } | ||||
74 | | ||||
75 | Component { | ||||
76 | id: moreBadge | ||||
77 | | ||||
78 | // if there's more urls than we can display, show a "+n" badge | ||||
79 | Item { | ||||
80 | width: moreLabel.width | ||||
81 | height: previewList.height | ||||
82 | | ||||
83 | PlasmaExtras.Heading { | ||||
84 | id: moreLabel | ||||
85 | anchors { | ||||
86 | left: parent.left | ||||
87 | // ListView doesn't add spacing before the footer | ||||
88 | leftMargin: previewList.spacing | ||||
89 | top: parent.top | ||||
90 | bottom: parent.bottom | ||||
91 | } | ||||
92 | level: 3 | ||||
93 | verticalAlignment: Text.AlignVCenter | ||||
94 | text: i18nc("Indicator that there are more urls in the notification than previews shown", "+%1", notificationItem.urls.length - previewList.count) | ||||
95 | } | ||||
96 | } | ||||
97 | } | ||||
98 | | ||||
99 | delegate: MouseArea { | ||||
100 | id: previewDelegate | ||||
101 | | ||||
102 | // clip is expensive, only clip if the QPixmapItem would leak outside | ||||
103 | clip: previewPixmap.height > height | ||||
104 | | ||||
105 | width: thumbnailer.hasPreview ? previewList.itemWidth : previewList.itemSquareSize | ||||
106 | height: thumbnailer.hasPreview ? previewList.itemHeight : previewList.itemSquareSize | ||||
107 | | ||||
108 | preventStealing: true | ||||
109 | cursorShape: Qt.OpenHandCursor | ||||
110 | | ||||
111 | onClicked: notificationItem.openUrl(modelData) | ||||
112 | | ||||
113 | // cannot drag itself, hence dragging the Pixmap instead | ||||
114 | drag.target: previewPixmap | ||||
115 | | ||||
116 | Drag.dragType: Drag.Automatic | ||||
117 | Drag.active: previewDelegate.drag.active | ||||
118 | Drag.mimeData: ({ | ||||
119 | "text/uri-list": modelData, | ||||
120 | "text/plain": modelData | ||||
121 | }) | ||||
122 | | ||||
123 | // first item determins the ListView height | ||||
124 | Binding { | ||||
125 | target: previewList | ||||
126 | property: "implicitHeight" | ||||
127 | value: previewDelegate.height | ||||
128 | when: index === 0 | ||||
129 | } | ||||
130 | | ||||
131 | Notifications.Thumbnailer { | ||||
132 | id: thumbnailer | ||||
133 | | ||||
134 | readonly property real ratio: pixmapSize.height ? pixmapSize.width / pixmapSize.height : 1 | ||||
135 | | ||||
136 | url: modelData | ||||
137 | size: Qt.size(previewList.itemWidth, previewList.itemHeight) | ||||
138 | } | ||||
139 | | ||||
140 | QPixmapItem { | ||||
141 | id: previewPixmap | ||||
142 | | ||||
143 | anchors.centerIn: parent | ||||
144 | | ||||
145 | width: parent.width | ||||
146 | height: width / thumbnailer.ratio | ||||
147 | pixmap: thumbnailer.pixmap | ||||
148 | } | ||||
149 | | ||||
150 | PlasmaCore.IconItem { | ||||
151 | anchors.fill: parent | ||||
152 | source: thumbnailer.iconName | ||||
153 | usesPlasmaTheme: false | ||||
154 | } | ||||
155 | | ||||
156 | Rectangle { | ||||
157 | anchors { | ||||
158 | left: parent.left | ||||
159 | right: parent.right | ||||
160 | bottom: parent.bottom | ||||
161 | } | ||||
162 | color: theme.textColor | ||||
163 | opacity: 0.6 | ||||
164 | height: fileNameLabel.contentHeight | ||||
165 | | ||||
166 | PlasmaComponents.Label { | ||||
167 | id: fileNameLabel | ||||
168 | anchors { | ||||
169 | fill: parent | ||||
170 | leftMargin: units.smallSpacing | ||||
171 | rightMargin: units.smallSpacing | ||||
172 | } | ||||
173 | wrapMode: Text.NoWrap | ||||
174 | height: implicitHeight // unset Label default height | ||||
175 | horizontalAlignment: Text.AlignHCenter | ||||
176 | verticalAlignment: Text.AlignVCenter | ||||
177 | elide: Text.ElideMiddle | ||||
178 | font.pointSize: theme.smallestFont.pointSize | ||||
179 | color: theme.backgroundColor | ||||
180 | text: { | ||||
181 | var splitUrl = modelData.split("/") | ||||
182 | return splitUrl[splitUrl.length - 1] | ||||
183 | } | ||||
184 | } | ||||
185 | } | ||||
186 | } | ||||
187 | } |