]>
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);
40 viewport()->setAttribute(Qt::WA_Hover
);
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()));
51 // apply the column mode settings to the widget
52 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
53 Q_ASSERT(settings
!= 0);
55 m_viewOptions
= QColumnView::viewOptions();
57 QFont
font(settings
->fontFamily(), settings
->fontSize());
58 font
.setItalic(settings
->italicFont());
59 font
.setBold(settings
->boldFont());
60 m_viewOptions
.font
= font
;
62 updateDecorationSize();
65 DolphinColumnView::~DolphinColumnView()
69 QStyleOptionViewItem
DolphinColumnView::viewOptions() const
74 void DolphinColumnView::contextMenuEvent(QContextMenuEvent
* event
)
76 QColumnView::contextMenuEvent(event
);
77 m_controller
->triggerContextMenuRequest(event
->pos());
80 void DolphinColumnView::mouseReleaseEvent(QMouseEvent
* event
)
82 QColumnView::mouseReleaseEvent(event
);
83 m_controller
->triggerActivation();
86 void DolphinColumnView::dragEnterEvent(QDragEnterEvent
* event
)
88 if (event
->mimeData()->hasUrls()) {
89 event
->acceptProposedAction();
93 void DolphinColumnView::dropEvent(QDropEvent
* event
)
95 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
96 if (!urls
.isEmpty()) {
97 m_controller
->indicateDroppedUrls(urls
,
98 indexAt(event
->pos()),
100 event
->acceptProposedAction();
102 QColumnView::dropEvent(event
);
105 void DolphinColumnView::zoomIn()
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;
115 updateDecorationSize();
119 void DolphinColumnView::zoomOut()
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;
129 updateDecorationSize();
133 bool DolphinColumnView::isZoomInPossible() const
135 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
136 return settings
->iconSize() < K3Icon::SizeLarge
;
139 bool DolphinColumnView::isZoomOutPossible() const
141 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
142 return settings
->iconSize() > K3Icon::SizeSmall
;
145 void DolphinColumnView::updateDecorationSize()
147 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
148 const int iconSize
= settings
->iconSize();
149 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
151 m_controller
->setZoomInPossible(isZoomInPossible());
152 m_controller
->setZoomOutPossible(isZoomOutPossible());
157 #include "dolphincolumnview.moc"