]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.cpp
Step one for having DolphinParts for the icons and details view, which can be used...
[dolphin.git] / src / dolphiniconsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphiniconsview.h"
21
22 #include "dolphincontroller.h"
23
24 #include <assert.h>
25 #include <kdirmodel.h>
26 #include <kfileitem.h>
27
28 #include <QAbstractProxyModel>
29
30 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
31 QListView(parent),
32 m_controller(controller)
33 {
34 assert(controller != 0);
35
36 setResizeMode(QListView::Adjust);
37
38 // TODO: read out settings
39 setViewMode(QListView::IconMode);
40 setSpacing(32);
41
42 connect(this, SIGNAL(clicked(const QModelIndex&)),
43 controller, SLOT(triggerItem(const QModelIndex&)));
44 }
45
46 DolphinIconsView::~DolphinIconsView()
47 {
48 }
49
50 QStyleOptionViewItem DolphinIconsView::viewOptions() const
51 {
52 return QListView::viewOptions();
53
54 // TODO: the view options should been read from the settings;
55 // the following code is just for testing...
56 //QStyleOptionViewItem options = QListView::viewOptions();
57 //options.decorationAlignment = Qt::AlignRight;
58 //options.decorationPosition = QStyleOptionViewItem::Right;
59 //options.decorationSize = QSize(100, 100);
60 //options.showDecorationSelected = true;
61 //options.state = QStyle::State_MouseOver;
62 //return options;
63 }
64
65 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
66 {
67 QListView::contextMenuEvent(event);
68 m_controller->triggerContextMenuRequest(event->pos(),
69 event->globalPos());
70 }
71
72 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
73 {
74 QListView::mouseReleaseEvent(event);
75 m_controller->triggerActivation();
76 }
77
78 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
79 {
80 if (event->mimeData()->hasUrls()) {
81 event->acceptProposedAction();
82 }
83 }
84
85 void DolphinIconsView::dropEvent(QDropEvent* event)
86 {
87 QListView::dropEvent(event);
88 // TODO: temporary deactivated until DolphinController will support this
89
90 /* KFileItem* directory = 0;
91 bool dropIntoDirectory = false;
92 const QModelIndex index = indexAt(event->pos());
93 if (index.isValid()) {
94 KFileItem* item = m_dolphinView->fileItem(index);
95 assert(item != 0);
96 dropIntoDirectory = item->isDir();
97 if (dropIntoDirectory) {
98 directory = item;
99 }
100 }
101
102 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
103 if (urls.isEmpty() || (event->source() == this) && !dropIntoDirectory) {
104 QListView::dropEvent(event);
105 }
106 else {
107 event->acceptProposedAction();
108 const KUrl& destination = (directory == 0) ? m_dolphinView->url() :
109 directory->url();
110 m_dolphinView->mainWindow()->dropUrls(urls, destination);
111 }*/
112 }
113
114 #include "dolphiniconsview.moc"