1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
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 General Public License *
15 * 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 ***************************************************************************/
20 #include "draganddrophelper.h"
22 #include <kdirmodel.h>
25 #include <QAbstractItemView>
26 #include <QAbstractProxyModel>
33 void DragAndDropHelper::startDrag(QAbstractItemView
* itemView
, Qt::DropActions supportedActions
)
35 QModelIndexList indexes
= itemView
->selectionModel()->selectedIndexes();
36 if (indexes
.count() > 0) {
37 QMimeData
*data
= itemView
->model()->mimeData(indexes
);
42 QDrag
* drag
= new QDrag(itemView
);
44 if (indexes
.count() == 1) {
45 QAbstractProxyModel
* proxyModel
= static_cast<QAbstractProxyModel
*>(itemView
->model());
46 KDirModel
* dirModel
= static_cast<KDirModel
*>(proxyModel
->sourceModel());
47 const QModelIndex index
= proxyModel
->mapToSource(indexes
.first());
49 const KFileItem item
= dirModel
->itemForIndex(index
);
50 pixmap
= item
.pixmap(KIconLoader::SizeMedium
, KIconLoader::SizeMedium
);
52 pixmap
= KIcon("item-drag-multiple").pixmap(KIconLoader::SizeMedium
, KIconLoader::SizeMedium
);
54 drag
->setPixmap(pixmap
);
55 drag
->setMimeData(data
);
56 drag
->exec(supportedActions
);
60 void DragAndDropHelper::drawHoverIndication(QWidget
* widget
,
64 if (bounds
.isEmpty()) {
68 QPainter
painter(widget
);
70 QBrush
blendedBrush(brush
);
71 QColor color
= blendedBrush
.color();
73 blendedBrush
.setColor(color
);
75 const int radius
= 10;
76 QPainterPath
path(QPointF(bounds
.left(), bounds
.top() + radius
));
77 path
.quadTo(bounds
.left(), bounds
.top(), bounds
.left() + radius
, bounds
.top());
78 path
.lineTo(bounds
.right() - radius
, bounds
.top());
79 path
.quadTo(bounds
.right(), bounds
.top(), bounds
.right(), bounds
.top() + radius
);
80 path
.lineTo(bounds
.right(), bounds
.bottom() - radius
);
81 path
.quadTo(bounds
.right(), bounds
.bottom(), bounds
.right() - radius
, bounds
.bottom());
82 path
.lineTo(bounds
.left() + radius
, bounds
.bottom());
83 path
.quadTo(bounds
.left(), bounds
.bottom(), bounds
.left(), bounds
.bottom() - radius
);
86 painter
.setRenderHint(QPainter::Antialiasing
);
87 painter
.fillPath(path
, blendedBrush
);