2 * Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library/Lesser General Public License
6 * version 2, or (at your option) any later version, as published by the
7 * Free Software Foundation
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 General Public License for more details
14 * You should have received a copy of the GNU Library/Lesser 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.
20 #include "customdragtreeview_p.h"
21 #include "kcategorizeditemsview_p.h"
27 CustomDragTreeView::CustomDragTreeView(QWidget
* parent
)
28 : QTreeView(parent
) {}
30 void CustomDragTreeView::startDrag(Qt::DropActions supportedActions
)
32 Q_UNUSED(supportedActions
);
34 // TODO: calculate real size for pixmap - using the icon sizes, not fixed
41 QModelIndexList indexes
= selectedIndexes();
42 if (indexes
.count() > 0) {
43 QMimeData
*data
= model()->mimeData(indexes
);
48 int size
= PIX_SIZE
+ (qMin(MAX_COUNT
, indexes
.count()) * MAX_OFFSET
);
50 if (indexes
.count() > MAX_COUNT
) {
51 off
= (MAX_OFFSET
* MAX_COUNT
) / indexes
.count();
54 //kDebug() << "Size: " << size << " Off: " << off << "\n";
56 QPixmap
pixmap(size
, size
);
57 pixmap
.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent
58 QPainter
painter(&pixmap
);
59 QRect
rect(0, 0, PIX_SIZE
, PIX_SIZE
);
61 foreach (const QModelIndex
&index
, indexes
) {
62 if (index
.column() != 0) {
66 KCategorizedItemsViewModels::AbstractItem
* item
=
67 m_view
->getItemByProxyIndex(index
);
70 rect
.setSize(item
->icon().actualSize(QSize(PIX_SIZE
, PIX_SIZE
)));
71 //painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes
72 item
->icon().paint(&painter
, rect
);
73 rect
.moveTopLeft(rect
.topLeft() + QPoint(off
, off
));
78 QDrag
*drag
= new QDrag(this);
79 drag
->setPixmap(pixmap
);
80 drag
->setMimeData(data
);
81 drag
->start(supportedActions
);
82 //drag->setHotSpot(d->pressedPosition - rect.topLeft());
83 //if (drag->start(supportedActions) == Qt::MoveAction)
84 // d->clearOrRemove();