]>
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 <QHeaderView>
34 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
, DolphinController
* controller
) :
36 m_controller(controller
)
38 assert(controller
!= 0);
41 setRootIsDecorated(false);
42 setSortingEnabled(true);
43 setUniformRowHeights(true);
45 const ViewProperties
props(controller
->url());
46 setSortIndicatorSection(props
.sorting());
47 setSortIndicatorOrder(props
.sortOrder());
49 connect(header(), SIGNAL(sectionClicked(int)),
50 this, SLOT(synchronizeSortingState(int)));
52 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
53 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
54 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
55 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
57 connect(this, SIGNAL(clicked(const QModelIndex
&)),
58 controller
, SLOT(triggerItem(const QModelIndex
&)));
60 // apply the details mode settings to the widget
61 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
62 assert(settings
!= 0);
64 m_viewOptions
= QTreeView::viewOptions();
65 m_viewOptions
.font
= QFont(settings
->fontFamily(), settings
->fontSize());
66 const int iconSize
= settings
->iconSize();
67 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
70 DolphinDetailsView::~DolphinDetailsView()
74 bool DolphinDetailsView::event(QEvent
* event
)
76 if (event
->type() == QEvent::Polish
) {
77 // Assure that by respecting the available width that:
78 // - the 'Name' column is stretched as large as possible
79 // - the remaining columns are as small as possible
80 QHeaderView
* headerView
= header();
81 headerView
->setStretchLastSection(false);
82 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
83 headerView
->setResizeMode(0, QHeaderView::Stretch
);
85 // hide columns if this is indicated by the settings
86 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
87 assert(settings
!= 0);
88 if (!settings
->showDate()) {
89 hideColumn(KDirModel::ModifiedTime
);
92 if (!settings
->showPermissions()) {
93 hideColumn(KDirModel::Permissions
);
96 if (!settings
->showOwner()) {
97 hideColumn(KDirModel::Owner
);
100 if (!settings
->showGroup()) {
101 hideColumn(KDirModel::Group
);
105 return QTreeView::event(event
);
107 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
109 return m_viewOptions
;
112 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
114 QTreeView::contextMenuEvent(event
);
115 m_controller
->triggerContextMenuRequest(event
->pos());
118 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
120 QTreeView::mouseReleaseEvent(event
);
121 m_controller
->triggerActivation();
124 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
126 if (event
->mimeData()->hasUrls()) {
127 event
->acceptProposedAction();
131 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
133 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
134 if (urls
.isEmpty() || (event
->source() == this)) {
135 QTreeView::dropEvent(event
);
138 event
->acceptProposedAction();
139 m_controller
->indicateDroppedUrls(urls
, event
->pos());
143 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
145 QHeaderView
* headerView
= header();
146 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
149 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
151 QHeaderView
* headerView
= header();
152 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
155 void DolphinDetailsView::synchronizeSortingState(int column
)
157 // The sorting has already been changed in QTreeView if this slot is
158 // invoked, but Dolphin is not informed about this.
159 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
160 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
161 m_controller
->indicateSortingChange(sorting
);
162 m_controller
->indicateSortOrderChange(sortOrder
);
165 #include "dolphindetailsview.moc"