]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
implement renaming, moving to trash and deleting for the treeview panel
[dolphin.git] / src / dolphincolumnview.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 "dolphincolumnview.h"
21
22 #include "dolphincontroller.h"
23 #include "dolphinsettings.h"
24
25 #include "dolphin_columnmodesettings.h"
26
27 #include <kdirmodel.h>
28 #include <kfileitem.h>
29 #include <kfileitemdelegate.h>
30
31 #include <QAbstractProxyModel>
32 #include <QPoint>
33
34 DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
35 QColumnView(parent),
36 m_controller(controller)
37 {
38 Q_ASSERT(controller != 0);
39
40 viewport()->setAttribute(Qt::WA_Hover);
41
42 connect(this, SIGNAL(clicked(const QModelIndex&)),
43 controller, SLOT(triggerItem(const QModelIndex&)));
44 connect(this, SIGNAL(activated(const QModelIndex&)),
45 controller, SLOT(triggerItem(const QModelIndex&)));
46 connect(controller, SIGNAL(zoomIn()),
47 this, SLOT(zoomIn()));
48 connect(controller, SIGNAL(zoomOut()),
49 this, SLOT(zoomOut()));
50
51 // apply the column mode settings to the widget
52 const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
53 Q_ASSERT(settings != 0);
54
55 m_viewOptions = QColumnView::viewOptions();
56
57 QFont font(settings->fontFamily(), settings->fontSize());
58 font.setItalic(settings->italicFont());
59 font.setBold(settings->boldFont());
60 m_viewOptions.font = font;
61
62 updateDecorationSize();
63 }
64
65 DolphinColumnView::~DolphinColumnView()
66 {
67 }
68
69 QStyleOptionViewItem DolphinColumnView::viewOptions() const
70 {
71 return m_viewOptions;
72 }
73
74 void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event)
75 {
76 QColumnView::contextMenuEvent(event);
77 m_controller->triggerContextMenuRequest(event->pos());
78 }
79
80 void DolphinColumnView::mouseReleaseEvent(QMouseEvent* event)
81 {
82 QColumnView::mouseReleaseEvent(event);
83 m_controller->triggerActivation();
84 }
85
86 void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
87 {
88 if (event->mimeData()->hasUrls()) {
89 event->acceptProposedAction();
90 }
91 }
92
93 void DolphinColumnView::dropEvent(QDropEvent* event)
94 {
95 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
96 if (!urls.isEmpty()) {
97 m_controller->indicateDroppedUrls(urls,
98 indexAt(event->pos()),
99 event->source());
100 event->acceptProposedAction();
101 }
102 QColumnView::dropEvent(event);
103 }
104
105 void DolphinColumnView::zoomIn()
106 {
107 if (isZoomInPossible()) {
108 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
109 // TODO: get rid of K3Icon sizes
110 switch (settings->iconSize()) {
111 case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break;
112 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break;
113 default: Q_ASSERT(false); break;
114 }
115 updateDecorationSize();
116 }
117 }
118
119 void DolphinColumnView::zoomOut()
120 {
121 if (isZoomOutPossible()) {
122 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
123 // TODO: get rid of K3Icon sizes
124 switch (settings->iconSize()) {
125 case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break;
126 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break;
127 default: Q_ASSERT(false); break;
128 }
129 updateDecorationSize();
130 }
131 }
132
133 bool DolphinColumnView::isZoomInPossible() const
134 {
135 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
136 return settings->iconSize() < K3Icon::SizeLarge;
137 }
138
139 bool DolphinColumnView::isZoomOutPossible() const
140 {
141 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
142 return settings->iconSize() > K3Icon::SizeSmall;
143 }
144
145 void DolphinColumnView::updateDecorationSize()
146 {
147 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
148 const int iconSize = settings->iconSize();
149 m_viewOptions.decorationSize = QSize(iconSize, iconSize);
150
151 m_controller->setZoomInPossible(isZoomInPossible());
152 m_controller->setZoomOutPossible(isZoomOutPossible());
153
154 doItemsLayout();
155 }
156
157 #include "dolphincolumnview.moc"