]>
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 connect(this, SIGNAL(clicked(const QModelIndex
&)),
64 controller
, SLOT(triggerItem(const QModelIndex
&)));
65 connect(this, SIGNAL(activated(const QModelIndex
&)),
66 controller
, SLOT(triggerItem(const QModelIndex
&)));
68 connect(controller
, SIGNAL(zoomIn()),
69 this, SLOT(zoomIn()));
70 connect(controller
, SIGNAL(zoomOut()),
71 this, SLOT(zoomOut()));
73 // apply the details mode settings to the widget
74 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
75 Q_ASSERT(settings
!= 0);
77 m_viewOptions
= QTreeView::viewOptions();
79 QFont
font(settings
->fontFamily(), settings
->fontSize());
80 font
.setItalic(settings
->italicFont());
81 font
.setBold(settings
->boldFont());
82 m_viewOptions
.font
= font
;
84 updateDecorationSize();
87 DolphinDetailsView::~DolphinDetailsView()
91 bool DolphinDetailsView::event(QEvent
* event
)
93 if (event
->type() == QEvent::Polish
) {
94 // Assure that by respecting the available width that:
95 // - the 'Name' column is stretched as large as possible
96 // - the remaining columns are as small as possible
97 QHeaderView
* headerView
= header();
98 headerView
->setStretchLastSection(false);
99 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
100 headerView
->setResizeMode(0, QHeaderView::Stretch
);
102 // hide columns if this is indicated by the settings
103 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
104 Q_ASSERT(settings
!= 0);
105 if (!settings
->showDate()) {
106 hideColumn(KDirModel::ModifiedTime
);
109 if (!settings
->showPermissions()) {
110 hideColumn(KDirModel::Permissions
);
113 if (!settings
->showOwner()) {
114 hideColumn(KDirModel::Owner
);
117 if (!settings
->showGroup()) {
118 hideColumn(KDirModel::Group
);
122 return QTreeView::event(event
);
125 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
127 return m_viewOptions
;
130 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
132 QTreeView::contextMenuEvent(event
);
133 m_controller
->triggerContextMenuRequest(event
->pos());
136 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
138 QTreeView::mouseReleaseEvent(event
);
139 m_controller
->triggerActivation();
142 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
144 if (event
->mimeData()->hasUrls()) {
145 event
->acceptProposedAction();
149 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
151 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
152 if (!urls
.isEmpty()) {
153 event
->acceptProposedAction();
154 m_controller
->indicateDroppedUrls(urls
,
155 indexAt(event
->pos()),
158 QTreeView::dropEvent(event
);
161 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
163 QHeaderView
* headerView
= header();
164 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
167 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
169 QHeaderView
* headerView
= header();
170 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
173 void DolphinDetailsView::synchronizeSortingState(int column
)
175 // The sorting has already been changed in QTreeView if this slot is
176 // invoked, but Dolphin is not informed about this.
177 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
178 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
179 m_controller
->indicateSortingChange(sorting
);
180 m_controller
->indicateSortOrderChange(sortOrder
);
183 void DolphinDetailsView::zoomIn()
185 if (isZoomInPossible()) {
186 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
187 // TODO: get rid of K3Icon sizes
188 switch (settings
->iconSize()) {
189 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
190 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
191 default: Q_ASSERT(false); break;
193 updateDecorationSize();
197 void DolphinDetailsView::zoomOut()
199 if (isZoomOutPossible()) {
200 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
201 // TODO: get rid of K3Icon sizes
202 switch (settings
->iconSize()) {
203 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
204 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
205 default: Q_ASSERT(false); break;
207 updateDecorationSize();
211 bool DolphinDetailsView::isZoomInPossible() const
213 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
214 return settings
->iconSize() < K3Icon::SizeLarge
;
217 bool DolphinDetailsView::isZoomOutPossible() const
219 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
220 return settings
->iconSize() > K3Icon::SizeSmall
;
223 void DolphinDetailsView::updateDecorationSize()
225 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
226 const int iconSize
= settings
->iconSize();
227 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
229 m_controller
->setZoomInPossible(isZoomInPossible());
230 m_controller
->setZoomOutPossible(isZoomOutPossible());
235 #include "dolphindetailsview.moc"