]>
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"
31 #include <kdirmodel.h>
32 #include <kfileitemdelegate.h>
34 #include <QHeaderView>
36 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
, DolphinController
* controller
) :
38 m_controller(controller
)
40 assert(controller
!= 0);
43 setRootIsDecorated(false);
44 setSortingEnabled(true);
45 setUniformRowHeights(true);
47 const ViewProperties
props(controller
->url());
48 setSortIndicatorSection(props
.sorting());
49 setSortIndicatorOrder(props
.sortOrder());
51 connect(header(), SIGNAL(sectionClicked(int)),
52 this, SLOT(synchronizeSortingState(int)));
54 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
55 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
56 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
57 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
59 connect(this, SIGNAL(clicked(const QModelIndex
&)),
60 controller
, SLOT(triggerItem(const QModelIndex
&)));
62 // apply the details mode settings to the widget
63 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
64 assert(settings
!= 0);
66 m_viewOptions
= QTreeView::viewOptions();
67 m_viewOptions
.font
= QFont(settings
->fontFamily(), settings
->fontSize());
68 const int iconSize
= settings
->iconSize();
69 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
71 KFileItemDelegate
* delegate
= new KFileItemDelegate(parent
);
72 setItemDelegate(delegate
);
75 DolphinDetailsView::~DolphinDetailsView()
79 bool DolphinDetailsView::event(QEvent
* event
)
81 if (event
->type() == QEvent::Polish
) {
82 // Assure that by respecting the available width that:
83 // - the 'Name' column is stretched as large as possible
84 // - the remaining columns are as small as possible
85 QHeaderView
* headerView
= header();
86 headerView
->setStretchLastSection(false);
87 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
88 headerView
->setResizeMode(0, QHeaderView::Stretch
);
90 // hide columns if this is indicated by the settings
91 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
92 assert(settings
!= 0);
93 if (!settings
->showDate()) {
94 hideColumn(KDirModel::ModifiedTime
);
97 if (!settings
->showPermissions()) {
98 hideColumn(KDirModel::Permissions
);
101 if (!settings
->showOwner()) {
102 hideColumn(KDirModel::Owner
);
105 if (!settings
->showGroup()) {
106 hideColumn(KDirModel::Group
);
110 return QTreeView::event(event
);
112 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
114 return m_viewOptions
;
117 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
119 QTreeView::contextMenuEvent(event
);
120 m_controller
->triggerContextMenuRequest(event
->pos());
123 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
125 QTreeView::mouseReleaseEvent(event
);
126 m_controller
->triggerActivation();
129 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
131 if (event
->mimeData()->hasUrls()) {
132 event
->acceptProposedAction();
136 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
138 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
139 if (urls
.isEmpty() || (event
->source() == this)) {
140 QTreeView::dropEvent(event
);
143 event
->acceptProposedAction();
144 m_controller
->indicateDroppedUrls(urls
, event
->pos());
148 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
150 QHeaderView
* headerView
= header();
151 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
154 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
156 QHeaderView
* headerView
= header();
157 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
160 void DolphinDetailsView::synchronizeSortingState(int column
)
162 // The sorting has already been changed in QTreeView if this slot is
163 // invoked, but Dolphin is not informed about this.
164 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
165 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
166 m_controller
->indicateSortingChange(sorting
);
167 m_controller
->indicateSortOrderChange(sortOrder
);
170 #include "dolphindetailsview.moc"