]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
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. *
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. *
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 ***************************************************************************/
20 #include "dolphincolumnview.h"
22 #include "dolphincontroller.h"
23 #include "dolphinsettings.h"
25 #include "dolphin_columnmodesettings.h"
27 #include <kdirmodel.h>
28 #include <kfileitem.h>
29 #include <kfileitemdelegate.h>
31 #include <QAbstractProxyModel>
34 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
36 m_controller(controller
)
38 Q_ASSERT(controller
!= 0);
41 setSelectionBehavior(SelectItems
);
42 setDragDropMode(QAbstractItemView::DragDrop
);
43 setDropIndicatorShown(false);
45 viewport()->setAttribute(Qt::WA_Hover
);
47 if (KGlobalSettings::singleClick()) {
48 connect(this, SIGNAL(clicked(const QModelIndex
&)),
49 controller
, SLOT(triggerItem(const QModelIndex
&)));
51 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
52 controller
, SLOT(triggerItem(const QModelIndex
&)));
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()));
61 // apply the column mode settings to the widget
62 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
63 Q_ASSERT(settings
!= 0);
65 m_viewOptions
= QColumnView::viewOptions();
67 QFont
font(settings
->fontFamily(), settings
->fontSize());
68 font
.setItalic(settings
->italicFont());
69 font
.setBold(settings
->boldFont());
70 m_viewOptions
.font
= font
;
72 updateDecorationSize();
75 DolphinColumnView::~DolphinColumnView()
78 QStyleOptionViewItem
DolphinColumnView::viewOptions() const
83 void DolphinColumnView::contextMenuEvent(QContextMenuEvent
* event
)
85 QColumnView::contextMenuEvent(event
);
86 m_controller
->triggerContextMenuRequest(event
->pos());
89 void DolphinColumnView::mouseReleaseEvent(QMouseEvent
* event
)
91 QColumnView::mouseReleaseEvent(event
);
92 m_controller
->triggerActivation();
95 void DolphinColumnView::dragEnterEvent(QDragEnterEvent
* event
)
97 if (event
->mimeData()->hasUrls()) {
98 event
->acceptProposedAction();
102 void DolphinColumnView::dropEvent(QDropEvent
* event
)
104 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
105 if (!urls
.isEmpty()) {
106 m_controller
->indicateDroppedUrls(urls
,
107 indexAt(event
->pos()),
109 event
->acceptProposedAction();
111 QColumnView::dropEvent(event
);
114 void DolphinColumnView::zoomIn()
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;
124 updateDecorationSize();
128 void DolphinColumnView::zoomOut()
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;
138 updateDecorationSize();
142 bool DolphinColumnView::isZoomInPossible() const
144 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
145 return settings
->iconSize() < K3Icon::SizeLarge
;
148 bool DolphinColumnView::isZoomOutPossible() const
150 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
151 return settings
->iconSize() > K3Icon::SizeSmall
;
154 void DolphinColumnView::updateDecorationSize()
156 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
157 const int iconSize
= settings
->iconSize();
158 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
160 m_controller
->setZoomInPossible(isZoomInPossible());
161 m_controller
->setZoomOutPossible(isZoomOutPossible());
166 #include "dolphincolumnview.moc"