]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.cpp
I hope this compiles better
[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 setGridSize(QSize(128, 96));
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 }
70
71 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
72 {
73 QListView::mouseReleaseEvent(event);
74 m_controller->triggerActivation();
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 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
87 if (urls.isEmpty() || (event->source() == this)) {
88 QListView::dropEvent(event);
89 }
90 else {
91 event->acceptProposedAction();
92 m_controller->indicateDroppedUrls(urls, event->pos());
93 }
94 }
95
96 #include "dolphiniconsview.moc"