]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphiniconsview.cpp
The icons view and details view don't use hardcoded (test-) values anymore, instead...
[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 #include "dolphinsettings.h"
24
25 #include "dolphin_iconsmodesettings.h"
26
27 #include <assert.h>
28 #include <kdirmodel.h>
29 #include <kfileitem.h>
30
31 #include <QAbstractProxyModel>
32
33 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
34 QListView(parent),
35 m_controller(controller)
36 {
37 assert(controller != 0);
38 setResizeMode(QListView::Adjust);
39
40 connect(this, SIGNAL(clicked(const QModelIndex&)),
41 controller, SLOT(triggerItem(const QModelIndex&)));
42
43 // apply the icons mode settings to the widget
44 const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
45 assert(settings != 0);
46
47 if (settings->arrangement() == QListView::TopToBottom) {
48 setViewMode(QListView::IconMode);
49 }
50 else {
51 setViewMode(QListView::ListMode);
52 }
53
54 setGridSize(QSize(settings->gridWidth(), settings->gridHeight()));
55 setSpacing(settings->gridSpacing());
56
57 m_viewOptions = QListView::viewOptions();
58 m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
59 const int iconSize = settings->iconSize();
60 m_viewOptions.decorationSize = QSize(iconSize, iconSize);
61 }
62
63 DolphinIconsView::~DolphinIconsView()
64 {
65 }
66
67 QStyleOptionViewItem DolphinIconsView::viewOptions() const
68 {
69 return m_viewOptions;
70 }
71
72 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
73 {
74 QListView::contextMenuEvent(event);
75 m_controller->triggerContextMenuRequest(event->pos());
76 }
77
78 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
79 {
80 QListView::mouseReleaseEvent(event);
81 m_controller->triggerActivation();
82 }
83
84 void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
85 {
86 if (event->mimeData()->hasUrls()) {
87 event->acceptProposedAction();
88 }
89 }
90
91 void DolphinIconsView::dropEvent(QDropEvent* event)
92 {
93 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
94 if (urls.isEmpty() || (event->source() == this)) {
95 QListView::dropEvent(event);
96 }
97 else {
98 event->acceptProposedAction();
99 m_controller->indicateDroppedUrls(urls, event->pos());
100 }
101 }
102
103 #include "dolphiniconsview.moc"