┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-11-19 07:34:34 +0100
committerPeter Penz <[email protected]>2011-11-19 07:36:25 +0100
commitcbab7fdc624dea5871ad9db14a77b7a2c8d47d41 (patch)
tree1fd5b9a834bd19ef09c05f0cab2e42cc6746fd4a /src
parentb6fb59fc7e8a0eb82fcd479ca3613bea682722cc (diff)
Improve dragging pixmap
When dragging multiple files, those files should be shown as part of the dragging pixmap like in Dolphin 1.7. BUG: 285031 FIXED-IN: 4.8.0
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kfileitemlistview.cpp87
1 files changed, 75 insertions, 12 deletions
diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp
index 528140deb..fa1a23fac 100644
--- a/src/kitemviews/kfileitemlistview.cpp
+++ b/src/kitemviews/kfileitemlistview.cpp
@@ -23,12 +23,14 @@
#include "kfileitemmodelrolesupdater.h"
#include "kfileitemlistwidget.h"
#include "kfileitemmodel.h"
+#include "kpixmapmodifier_p.h"
#include <KLocale>
#include <KStringHandler>
#include <KDebug>
#include <KIcon>
+#include <QPainter>
#include <QTextLine>
#include <QTimer>
@@ -220,22 +222,83 @@ QHash<QByteArray, QSizeF> KFileItemListView::visibleRolesSizes(const KItemRangeL
QPixmap KFileItemListView::createDragPixmap(const QSet<int>& indexes) const
{
- QPixmap pixmap;
+ if (!model()) {
+ return QPixmap();
+ }
- if (model()) {
- QSetIterator<int> it(indexes);
- while (it.hasNext()) {
- const int index = it.next();
- // TODO: Only one item is considered currently
- pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
- if (pixmap.isNull()) {
- KIcon icon(model()->data(index).value("iconName").toString());
- pixmap = icon.pixmap(itemSize().toSize());
- }
+ const int itemCount = indexes.count();
+ Q_ASSERT(itemCount > 0);
+ if (itemCount == 1) {
+ // Only one item is selected. Use the original icon without resizing.
+ const int index = indexes.values().first();
+ QPixmap dragPixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
+ if (dragPixmap.isNull()) {
+ KIcon icon(model()->data(index).value("iconName").toString());
+ dragPixmap = icon.pixmap(itemSize().toSize());
+ }
+ return dragPixmap;
+ }
+
+ // If more than one item is dragged, align the items inside a
+ // rectangular grid. The maximum grid size is limited to 5 x 5 items.
+ int xCount;
+ int size;
+ if (itemCount > 16) {
+ xCount = 5;
+ size = KIconLoader::SizeSmall;
+ } else if (itemCount > 9) {
+ xCount = 4;
+ size = KIconLoader::SizeSmallMedium;
+ } else {
+ xCount = 3;
+ size = KIconLoader::SizeMedium;
+ }
+
+ if (itemCount < xCount) {
+ xCount = itemCount;
+ }
+
+ int yCount = itemCount / xCount;
+ if (itemCount % xCount != 0) {
+ ++yCount;
+ }
+ if (yCount > xCount) {
+ yCount = xCount;
+ }
+
+ // Draw the selected items into the grid cells.
+ QPixmap dragPixmap(xCount * size + xCount - 1, yCount * size + yCount - 1);
+ dragPixmap.fill(Qt::transparent);
+
+ QPainter painter(&dragPixmap);
+ int x = 0;
+ int y = 0;
+ QSetIterator<int> it(indexes);
+ while (it.hasNext()) {
+ const int index = it.next();
+
+ QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
+ if (pixmap.isNull()) {
+ KIcon icon(model()->data(index).value("iconName").toString());
+ pixmap = icon.pixmap(size, size);
+ } else {
+ KPixmapModifier::scale(pixmap, QSize(size, size));
+ }
+
+ painter.drawPixmap(x, y, pixmap);
+
+ x += size + 1;
+ if (x >= dragPixmap.width()) {
+ x = 0;
+ y += size + 1;
+ }
+
+ if (y >= dragPixmap.height()) {
+ break;
}
}
- return pixmap;
+ return dragPixmap;
}
void KFileItemListView::initializeItemListWidget(KItemListWidget* item)