]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
734328bc653784ec351cb7c0d22030522bb7e12b
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()
79 QStyleOptionViewItem
DolphinColumnView::viewOptions() const
84 void DolphinColumnView::contextMenuEvent(QContextMenuEvent
* event
)
86 QColumnView::contextMenuEvent(event
);
87 m_controller
->triggerContextMenuRequest(event
->pos());
90 void DolphinColumnView::mouseReleaseEvent(QMouseEvent
* event
)
92 QColumnView::mouseReleaseEvent(event
);
93 m_controller
->triggerActivation();
96 void DolphinColumnView::dragEnterEvent(QDragEnterEvent
* event
)
98 if (event
->mimeData()->hasUrls()) {
99 event
->acceptProposedAction();
103 void DolphinColumnView::dropEvent(QDropEvent
* event
)
105 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
106 if (!urls
.isEmpty()) {
107 m_controller
->indicateDroppedUrls(urls
,
108 indexAt(event
->pos()),
110 event
->acceptProposedAction();
112 QColumnView::dropEvent(event
);
115 void DolphinColumnView::zoomIn()
117 if (isZoomInPossible()) {
118 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
119 // TODO: get rid of K3Icon sizes
120 switch (settings
->iconSize()) {
121 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
122 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
123 default: Q_ASSERT(false); break;
125 updateDecorationSize();
129 void DolphinColumnView::zoomOut()
131 if (isZoomOutPossible()) {
132 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
133 // TODO: get rid of K3Icon sizes
134 switch (settings
->iconSize()) {
135 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
136 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
137 default: Q_ASSERT(false); break;
139 updateDecorationSize();
143 bool DolphinColumnView::isZoomInPossible() const
145 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
146 return settings
->iconSize() < K3Icon::SizeLarge
;
149 bool DolphinColumnView::isZoomOutPossible() const
151 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
152 return settings
->iconSize() > K3Icon::SizeSmall
;
155 void DolphinColumnView::updateDecorationSize()
157 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
158 const int iconSize
= settings
->iconSize();
159 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
161 m_controller
->setZoomInPossible(isZoomInPossible());
162 m_controller
->setZoomOutPossible(isZoomOutPossible());
167 #include "dolphincolumnview.moc"