]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphindetailsview.h"
23 #include "dolphincontroller.h"
24 #include "dolphinsettings.h"
25 #include "dolphinsortfilterproxymodel.h"
26 #include "viewproperties.h"
28 #include "dolphin_detailsmodesettings.h"
30 #include <kdirmodel.h>
31 #include <kfileitemdelegate.h>
33 #include <QHeaderView>
35 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
, DolphinController
* controller
) :
37 m_controller(controller
)
39 Q_ASSERT(controller
!= 0);
42 setRootIsDecorated(false);
43 setSortingEnabled(true);
44 setUniformRowHeights(true);
45 setSelectionBehavior(SelectItems
);
46 setDragDropMode(QAbstractItemView::DragDrop
);
47 setDropIndicatorShown(false);
49 viewport()->setAttribute(Qt::WA_Hover
);
51 const ViewProperties
props(controller
->url());
52 setSortIndicatorSection(props
.sorting());
53 setSortIndicatorOrder(props
.sortOrder());
55 connect(header(), SIGNAL(sectionClicked(int)),
56 this, SLOT(synchronizeSortingState(int)));
58 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
59 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
60 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
61 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
63 if (KGlobalSettings::singleClick()) {
64 connect(this, SIGNAL(clicked(const QModelIndex
&)),
65 controller
, SLOT(triggerItem(const QModelIndex
&)));
67 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
68 controller
, SLOT(triggerItem(const QModelIndex
&)));
70 connect(this, SIGNAL(activated(const QModelIndex
&)),
71 controller
, SLOT(triggerItem(const QModelIndex
&)));
73 connect(controller
, SIGNAL(zoomIn()),
74 this, SLOT(zoomIn()));
75 connect(controller
, SIGNAL(zoomOut()),
76 this, SLOT(zoomOut()));
78 // apply the details mode settings to the widget
79 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
80 Q_ASSERT(settings
!= 0);
82 m_viewOptions
= QTreeView::viewOptions();
84 QFont
font(settings
->fontFamily(), settings
->fontSize());
85 font
.setItalic(settings
->italicFont());
86 font
.setBold(settings
->boldFont());
87 m_viewOptions
.font
= font
;
89 updateDecorationSize();
92 DolphinDetailsView::~DolphinDetailsView()
95 bool DolphinDetailsView::event(QEvent
* event
)
97 if (event
->type() == QEvent::Polish
) {
98 // Assure that by respecting the available width that:
99 // - the 'Name' column is stretched as large as possible
100 // - the remaining columns are as small as possible
101 QHeaderView
* headerView
= header();
102 headerView
->setStretchLastSection(false);
103 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
104 headerView
->setResizeMode(0, QHeaderView::Stretch
);
106 // hide columns if this is indicated by the settings
107 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
108 Q_ASSERT(settings
!= 0);
109 if (!settings
->showDate()) {
110 hideColumn(KDirModel::ModifiedTime
);
113 if (!settings
->showPermissions()) {
114 hideColumn(KDirModel::Permissions
);
117 if (!settings
->showOwner()) {
118 hideColumn(KDirModel::Owner
);
121 if (!settings
->showGroup()) {
122 hideColumn(KDirModel::Group
);
125 if (!settings
->showType()) {
126 hideColumn(KDirModel::Type
);
130 return QTreeView::event(event
);
133 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
135 return m_viewOptions
;
138 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
140 QTreeView::contextMenuEvent(event
);
141 m_controller
->triggerContextMenuRequest(event
->pos());
144 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
146 QTreeView::mouseReleaseEvent(event
);
147 m_controller
->triggerActivation();
150 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
152 if (event
->mimeData()->hasUrls()) {
153 event
->acceptProposedAction();
157 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
159 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
160 if (!urls
.isEmpty()) {
161 event
->acceptProposedAction();
162 m_controller
->indicateDroppedUrls(urls
,
163 indexAt(event
->pos()),
166 QTreeView::dropEvent(event
);
169 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
171 QHeaderView
* headerView
= header();
172 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
175 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
177 QHeaderView
* headerView
= header();
178 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
181 void DolphinDetailsView::synchronizeSortingState(int column
)
183 // The sorting has already been changed in QTreeView if this slot is
184 // invoked, but Dolphin is not informed about this.
185 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
186 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
187 m_controller
->indicateSortingChange(sorting
);
188 m_controller
->indicateSortOrderChange(sortOrder
);
191 void DolphinDetailsView::zoomIn()
193 if (isZoomInPossible()) {
194 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
195 // TODO: get rid of K3Icon sizes
196 switch (settings
->iconSize()) {
197 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
198 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
199 default: Q_ASSERT(false); break;
201 updateDecorationSize();
205 void DolphinDetailsView::zoomOut()
207 if (isZoomOutPossible()) {
208 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
209 // TODO: get rid of K3Icon sizes
210 switch (settings
->iconSize()) {
211 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
212 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
213 default: Q_ASSERT(false); break;
215 updateDecorationSize();
219 bool DolphinDetailsView::isZoomInPossible() const
221 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
222 return settings
->iconSize() < K3Icon::SizeLarge
;
225 bool DolphinDetailsView::isZoomOutPossible() const
227 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
228 return settings
->iconSize() > K3Icon::SizeSmall
;
231 void DolphinDetailsView::updateDecorationSize()
233 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
234 const int iconSize
= settings
->iconSize();
235 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
237 m_controller
->setZoomInPossible(isZoomInPossible());
238 m_controller
->setZoomOutPossible(isZoomOutPossible());
243 #include "dolphindetailsview.moc"