]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
Allow to adjust the maximum size for previews.
[dolphin.git] / src / dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "dolphindetailsview.h"
22
23 #include "dolphincontroller.h"
24 #include "dolphinsettings.h"
25 #include "dolphinsortfilterproxymodel.h"
26 #include "viewproperties.h"
27
28 #include "dolphin_detailsmodesettings.h"
29
30 #include <assert.h>
31 #include <kdirmodel.h>
32 #include <QHeaderView>
33
34 DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
35 QTreeView(parent),
36 m_controller(controller)
37 {
38 assert(controller != 0);
39
40 setAcceptDrops(true);
41 setRootIsDecorated(false);
42 setSortingEnabled(true);
43 setUniformRowHeights(true);
44
45 const ViewProperties props(controller->url());
46 setSortIndicatorSection(props.sorting());
47 setSortIndicatorOrder(props.sortOrder());
48
49 connect(header(), SIGNAL(sectionClicked(int)),
50 this, SLOT(synchronizeSortingState(int)));
51
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)));
56
57 connect(this, SIGNAL(clicked(const QModelIndex&)),
58 controller, SLOT(triggerItem(const QModelIndex&)));
59
60 // apply the details mode settings to the widget
61 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
62 assert(settings != 0);
63
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);
68 }
69
70 DolphinDetailsView::~DolphinDetailsView()
71 {
72 }
73
74 bool DolphinDetailsView::event(QEvent* event)
75 {
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);
84
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);
90 }
91
92 if (!settings->showPermissions()) {
93 hideColumn(KDirModel::Permissions);
94 }
95
96 if (!settings->showOwner()) {
97 hideColumn(KDirModel::Owner);
98 }
99
100 if (!settings->showGroup()) {
101 hideColumn(KDirModel::Group);
102 }
103 }
104
105 return QTreeView::event(event);
106 }
107 QStyleOptionViewItem DolphinDetailsView::viewOptions() const
108 {
109 return m_viewOptions;
110 }
111
112 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
113 {
114 QTreeView::contextMenuEvent(event);
115 m_controller->triggerContextMenuRequest(event->pos());
116 }
117
118 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
119 {
120 QTreeView::mouseReleaseEvent(event);
121 m_controller->triggerActivation();
122 }
123
124 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
125 {
126 if (event->mimeData()->hasUrls()) {
127 event->acceptProposedAction();
128 }
129 }
130
131 void DolphinDetailsView::dropEvent(QDropEvent* event)
132 {
133 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
134 if (urls.isEmpty() || (event->source() == this)) {
135 QTreeView::dropEvent(event);
136 }
137 else {
138 event->acceptProposedAction();
139 m_controller->indicateDroppedUrls(urls, event->pos());
140 }
141 }
142
143 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
144 {
145 QHeaderView* headerView = header();
146 headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
147 }
148
149 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
150 {
151 QHeaderView* headerView = header();
152 headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
153 }
154
155 void DolphinDetailsView::synchronizeSortingState(int column)
156 {
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);
163 }
164
165 #include "dolphindetailsview.moc"