]>
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);
46 const ViewProperties
props(controller
->url());
47 setSortIndicatorSection(props
.sorting());
48 setSortIndicatorOrder(props
.sortOrder());
50 connect(header(), SIGNAL(sectionClicked(int)),
51 this, SLOT(synchronizeSortingState(int)));
53 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
54 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
55 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
56 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
58 connect(this, SIGNAL(clicked(const QModelIndex
&)),
59 controller
, SLOT(triggerItem(const QModelIndex
&)));
61 connect(controller
, SIGNAL(zoomIn()),
62 this, SLOT(zoomIn()));
63 connect(controller
, SIGNAL(zoomOut()),
64 this, SLOT(zoomOut()));
66 // apply the details mode settings to the widget
67 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
68 Q_ASSERT(settings
!= 0);
70 m_viewOptions
= QTreeView::viewOptions();
71 m_viewOptions
.font
= QFont(settings
->fontFamily(), settings
->fontSize());
72 updateDecorationSize();
74 KFileItemDelegate
* delegate
= new KFileItemDelegate(parent
);
75 setItemDelegate(delegate
);
78 DolphinDetailsView::~DolphinDetailsView()
82 bool DolphinDetailsView::event(QEvent
* event
)
84 if (event
->type() == QEvent::Polish
) {
85 // Assure that by respecting the available width that:
86 // - the 'Name' column is stretched as large as possible
87 // - the remaining columns are as small as possible
88 QHeaderView
* headerView
= header();
89 headerView
->setStretchLastSection(false);
90 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
91 headerView
->setResizeMode(0, QHeaderView::Stretch
);
93 // hide columns if this is indicated by the settings
94 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
95 Q_ASSERT(settings
!= 0);
96 if (!settings
->showDate()) {
97 hideColumn(KDirModel::ModifiedTime
);
100 if (!settings
->showPermissions()) {
101 hideColumn(KDirModel::Permissions
);
104 if (!settings
->showOwner()) {
105 hideColumn(KDirModel::Owner
);
108 if (!settings
->showGroup()) {
109 hideColumn(KDirModel::Group
);
113 return QTreeView::event(event
);
115 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
117 return m_viewOptions
;
120 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
122 QTreeView::contextMenuEvent(event
);
123 m_controller
->triggerContextMenuRequest(event
->pos());
126 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
128 QTreeView::mouseReleaseEvent(event
);
129 m_controller
->triggerActivation();
132 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
134 if (event
->mimeData()->hasUrls()) {
135 event
->acceptProposedAction();
139 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
141 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
142 if (urls
.isEmpty() || (event
->source() == this)) {
143 QTreeView::dropEvent(event
);
146 event
->acceptProposedAction();
147 m_controller
->indicateDroppedUrls(urls
, event
->pos());
151 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
153 QHeaderView
* headerView
= header();
154 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
157 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
159 QHeaderView
* headerView
= header();
160 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
163 void DolphinDetailsView::synchronizeSortingState(int column
)
165 // The sorting has already been changed in QTreeView if this slot is
166 // invoked, but Dolphin is not informed about this.
167 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
168 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
169 m_controller
->indicateSortingChange(sorting
);
170 m_controller
->indicateSortOrderChange(sortOrder
);
173 void DolphinDetailsView::zoomIn()
175 if (isZoomInPossible()) {
176 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
177 // TODO: get rid of K3Icon sizes
178 switch (settings
->iconSize()) {
179 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
180 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
181 default: Q_ASSERT(false); break;
183 updateDecorationSize();
187 void DolphinDetailsView::zoomOut()
189 if (isZoomOutPossible()) {
190 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
191 // TODO: get rid of K3Icon sizes
192 switch (settings
->iconSize()) {
193 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
194 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
195 default: Q_ASSERT(false); break;
197 updateDecorationSize();
201 bool DolphinDetailsView::isZoomInPossible() const
203 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
204 return settings
->iconSize() < K3Icon::SizeLarge
;
207 bool DolphinDetailsView::isZoomOutPossible() const
209 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
210 return settings
->iconSize() > K3Icon::SizeSmall
;
213 void DolphinDetailsView::updateDecorationSize()
215 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
216 const int iconSize
= settings
->iconSize();
217 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
219 m_controller
->setZoomInPossible(isZoomInPossible());
220 m_controller
->setZoomOutPossible(isZoomOutPossible());
225 #include "dolphindetailsview.moc"