]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.cpp
don't accept drops into the same view if it is not done above a directory
[dolphin.git] / src / dolphiniconsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphiniconsview.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinview.h"
24
25 #include <assert.h>
26 #include <kdirmodel.h>
27 #include <kfileitem.h>
28
29 #include <QAbstractProxyModel>
30
31 DolphinIconsView::DolphinIconsView(DolphinView* parent) :
32 QListView(parent),
33 m_dolphinView(parent)
34 {
35 setResizeMode(QListView::Adjust);
36 }
37
38 DolphinIconsView::~DolphinIconsView()
39 {
40 }
41
42 QStyleOptionViewItem DolphinIconsView::viewOptions() const
43 {
44 return QListView::viewOptions();
45
46 // TODO: the view options should been read from the settings;
47 // the following code is just for testing...
48 //QStyleOptionViewItem options = QListView::viewOptions();
49 //options.decorationAlignment = Qt::AlignRight;
50 //options.decorationPosition = QStyleOptionViewItem::Right;
51 //options.decorationSize = QSize(100, 100);
52 //options.showDecorationSelected = true;
53 //options.state = QStyle::State_MouseOver;
54 //return options;
55 }
56
57 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
58 {
59 QListView::contextMenuEvent(event);
60
61 KFileItem* item = 0;
62
63 const QModelIndex index = indexAt(event->pos());
64 if (index.isValid()) {
65 item = m_dolphinView->fileItem(index);
66 }
67
68 m_dolphinView->openContextMenu(item, event->globalPos());
69 }
70
71 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
72 {
73 QListView::mouseReleaseEvent(event);
74 m_dolphinView->declareViewActive();
75 }
76
77 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
78 {
79 if (event->mimeData()->hasUrls()) {
80 event->acceptProposedAction();
81 }
82 }
83
84 void DolphinIconsView::dropEvent(QDropEvent* event)
85 {
86 KFileItem* directory = 0;
87 bool dropIntoDirectory = false;
88 const QModelIndex index = indexAt(event->pos());
89 if (index.isValid()) {
90 KFileItem* item = m_dolphinView->fileItem(index);
91 assert(item != 0);
92 dropIntoDirectory = item->isDir();
93 if (dropIntoDirectory) {
94 directory = item;
95 }
96 }
97
98 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
99 if (urls.isEmpty() || (event->source() == this) && !dropIntoDirectory) {
100 QListView::dropEvent(event);
101 }
102 else {
103 event->acceptProposedAction();
104 const KUrl& destination = (directory == 0) ? m_dolphinView->url() :
105 directory->url();
106 m_dolphinView->mainWindow()->dropUrls(urls, destination);
107 }
108 }
109
110 #include "dolphiniconsview.moc"