]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
9ce51dbd2e1187a7a254e319c64055da01cc8d75
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 connect(this, SIGNAL(clicked(const QModelIndex
&)),
48 controller
, SLOT(triggerItem(const QModelIndex
&)));
49 connect(this, SIGNAL(activated(const QModelIndex
&)),
50 controller
, SLOT(triggerItem(const QModelIndex
&)));
51 connect(controller
, SIGNAL(zoomIn()),
52 this, SLOT(zoomIn()));
53 connect(controller
, SIGNAL(zoomOut()),
54 this, SLOT(zoomOut()));
56 // apply the column mode settings to the widget
57 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
58 Q_ASSERT(settings
!= 0);
60 m_viewOptions
= QColumnView::viewOptions();
62 QFont
font(settings
->fontFamily(), settings
->fontSize());
63 font
.setItalic(settings
->italicFont());
64 font
.setBold(settings
->boldFont());
65 m_viewOptions
.font
= font
;
67 updateDecorationSize();
70 DolphinColumnView::~DolphinColumnView()
74 QStyleOptionViewItem
DolphinColumnView::viewOptions() const
79 void DolphinColumnView::contextMenuEvent(QContextMenuEvent
* event
)
81 QColumnView::contextMenuEvent(event
);
82 m_controller
->triggerContextMenuRequest(event
->pos());
85 void DolphinColumnView::mouseReleaseEvent(QMouseEvent
* event
)
87 QColumnView::mouseReleaseEvent(event
);
88 m_controller
->triggerActivation();
91 void DolphinColumnView::dragEnterEvent(QDragEnterEvent
* event
)
93 if (event
->mimeData()->hasUrls()) {
94 event
->acceptProposedAction();
98 void DolphinColumnView::dropEvent(QDropEvent
* event
)
100 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
101 if (!urls
.isEmpty()) {
102 m_controller
->indicateDroppedUrls(urls
,
103 indexAt(event
->pos()),
105 event
->acceptProposedAction();
107 QColumnView::dropEvent(event
);
110 void DolphinColumnView::zoomIn()
112 if (isZoomInPossible()) {
113 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
114 // TODO: get rid of K3Icon sizes
115 switch (settings
->iconSize()) {
116 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
117 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
118 default: Q_ASSERT(false); break;
120 updateDecorationSize();
124 void DolphinColumnView::zoomOut()
126 if (isZoomOutPossible()) {
127 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
128 // TODO: get rid of K3Icon sizes
129 switch (settings
->iconSize()) {
130 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
131 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
132 default: Q_ASSERT(false); break;
134 updateDecorationSize();
138 bool DolphinColumnView::isZoomInPossible() const
140 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
141 return settings
->iconSize() < K3Icon::SizeLarge
;
144 bool DolphinColumnView::isZoomOutPossible() const
146 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
147 return settings
->iconSize() > K3Icon::SizeSmall
;
150 void DolphinColumnView::updateDecorationSize()
152 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
153 const int iconSize
= settings
->iconSize();
154 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
156 m_controller
->setZoomInPossible(isZoomInPossible());
157 m_controller
->setZoomOutPossible(isZoomOutPossible());
162 #include "dolphincolumnview.moc"