]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
some cleanups for the sidebar pages (move protected members to private section etc.)
[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 setAcceptDrops(true);
41 setSelectionBehavior(SelectItems);
42 setDragDropMode(QAbstractItemView::DragDrop);
43 setDropIndicatorShown(false);
44
45 viewport()->setAttribute(Qt::WA_Hover);
46
47 if (KGlobalSettings::singleClick()) {
48 connect(this, SIGNAL(clicked(const QModelIndex&)),
49 controller, SLOT(triggerItem(const QModelIndex&)));
50 } else {
51 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
52 controller, SLOT(triggerItem(const QModelIndex&)));
53 }
54 connect(this, SIGNAL(activated(const QModelIndex&)),
55 controller, SLOT(triggerItem(const QModelIndex&)));
56 connect(controller, SIGNAL(zoomIn()),
57 this, SLOT(zoomIn()));
58 connect(controller, SIGNAL(zoomOut()),
59 this, SLOT(zoomOut()));
60
61 // apply the column mode settings to the widget
62 const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
63 Q_ASSERT(settings != 0);
64
65 m_viewOptions = QColumnView::viewOptions();
66
67 QFont font(settings->fontFamily(), settings->fontSize());
68 font.setItalic(settings->italicFont());
69 font.setBold(settings->boldFont());
70 m_viewOptions.font = font;
71
72 updateDecorationSize();
73 }
74
75 DolphinColumnView::~DolphinColumnView()
76 {}
77
78 QStyleOptionViewItem DolphinColumnView::viewOptions() const
79 {
80 return m_viewOptions;
81 }
82
83 void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event)
84 {
85 QColumnView::contextMenuEvent(event);
86 m_controller->triggerContextMenuRequest(event->pos());
87 }
88
89 void DolphinColumnView::mouseReleaseEvent(QMouseEvent* event)
90 {
91 QColumnView::mouseReleaseEvent(event);
92 m_controller->triggerActivation();
93 }
94
95 void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
96 {
97 if (event->mimeData()->hasUrls()) {
98 event->acceptProposedAction();
99 }
100 }
101
102 void DolphinColumnView::dropEvent(QDropEvent* event)
103 {
104 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
105 if (!urls.isEmpty()) {
106 m_controller->indicateDroppedUrls(urls,
107 indexAt(event->pos()),
108 event->source());
109 event->acceptProposedAction();
110 }
111 QColumnView::dropEvent(event);
112 }
113
114 void DolphinColumnView::zoomIn()
115 {
116 if (isZoomInPossible()) {
117 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
118 // TODO: get rid of K3Icon sizes
119 switch (settings->iconSize()) {
120 case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break;
121 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break;
122 default: Q_ASSERT(false); break;
123 }
124 updateDecorationSize();
125 }
126 }
127
128 void DolphinColumnView::zoomOut()
129 {
130 if (isZoomOutPossible()) {
131 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
132 // TODO: get rid of K3Icon sizes
133 switch (settings->iconSize()) {
134 case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break;
135 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break;
136 default: Q_ASSERT(false); break;
137 }
138 updateDecorationSize();
139 }
140 }
141
142 bool DolphinColumnView::isZoomInPossible() const
143 {
144 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
145 return settings->iconSize() < K3Icon::SizeLarge;
146 }
147
148 bool DolphinColumnView::isZoomOutPossible() const
149 {
150 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
151 return settings->iconSize() > K3Icon::SizeSmall;
152 }
153
154 void DolphinColumnView::updateDecorationSize()
155 {
156 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
157 const int iconSize = settings->iconSize();
158 m_viewOptions.decorationSize = QSize(iconSize, iconSize);
159
160 m_controller->setZoomInPossible(isZoomInPossible());
161 m_controller->setZoomOutPossible(isZoomOutPossible());
162
163 doItemsLayout();
164 }
165
166 #include "dolphincolumnview.moc"