libplasma
customdragtreeview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kcategorizeditemsview_p.h"
00021
00022 #define PIX_SIZE 64
00023 #define MAX_OFFSET 16
00024 #define MAX_COUNT 5
00025
00026 CustomDragTreeView::CustomDragTreeView(QWidget * parent)
00027 : QTreeView(parent) {}
00028
00029 void CustomDragTreeView::startDrag ( Qt::DropActions supportedActions )
00030 {
00031 Q_UNUSED(supportedActions);
00032
00033
00034
00035
00036 if (!m_view) return;
00037
00038 QModelIndexList indexes = selectedIndexes();
00039 if (indexes.count() > 0) {
00040 QMimeData *data = model()->mimeData(indexes);
00041 if (!data) {
00042 return;
00043 }
00044
00045 int size = PIX_SIZE + (qMin(MAX_COUNT, indexes.count()) * MAX_OFFSET);
00046 int off = MAX_OFFSET;
00047 if (indexes.count() > MAX_COUNT) {
00048 off = (MAX_OFFSET * MAX_COUNT) / indexes.count();
00049 }
00050
00051 kDebug() << "Size: " << size << " Off: " << off << "\n";
00052
00053 QPixmap pixmap(size, size);
00054 pixmap.fill(QColor(255, 255, 255, 0));
00055 QPainter painter(&pixmap);
00056 QRect rect(0, 0, PIX_SIZE, PIX_SIZE);
00057
00058 foreach (QModelIndex index, indexes) {
00059 if (index.column() != 0) continue;
00060
00061 KCategorizedItemsViewModels::AbstractItem * item =
00062 m_view->getItemByProxyIndex(index);
00063
00064 if (item) {
00065 rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE)));
00066
00067 item->icon().paint(&painter, rect);
00068 rect.moveTopLeft(rect.topLeft() + QPoint(off, off));
00069 }
00070 }
00071 painter.end();
00072
00073
00074 QDrag *drag = new QDrag(this);
00075 drag->setPixmap(pixmap);
00076 drag->setMimeData(data);
00077 drag->start(supportedActions);
00078
00079
00080
00081 }
00082 }
00083