]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphindetailsview.cpp
Forward port: Don't grab the focus if the view did not have the focus already.
[dolphin.git] / src / views / dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * Copyright (C) 2008 by Simon St. James (kdedevel@etotheipiplusone.com) *
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 "additionalinfoaccessor.h"
24 #include "dolphinmodel.h"
25 #include "dolphinviewcontroller.h"
26 #include "dolphinfileitemdelegate.h"
27 #include "settings/dolphinsettings.h"
28 #include "dolphinsortfilterproxymodel.h"
29 #include "dolphinviewautoscroller.h"
30 #include "draganddrophelper.h"
31 #include "viewextensionsfactory.h"
32 #include "viewmodecontroller.h"
33 #include "viewproperties.h"
34 #include "zoomlevelinfo.h"
35
36 #include "dolphin_detailsmodesettings.h"
37 #include "dolphin_generalsettings.h"
38
39 #include <kdirmodel.h>
40 #include <kdirlister.h>
41 #include <klocale.h>
42 #include <kmenu.h>
43
44 #include <QApplication>
45 #include <QHeaderView>
46 #include <QScrollBar>
47
48 DolphinDetailsView::DolphinDetailsView(QWidget* parent,
49 DolphinViewController* dolphinViewController,
50 const ViewModeController* viewModeController,
51 DolphinSortFilterProxyModel* proxyModel) :
52 DolphinTreeView(parent),
53 m_autoResize(true),
54 m_dolphinViewController(dolphinViewController),
55 m_viewModeController(viewModeController),
56 m_extensionsFactory(0),
57 m_expandableFoldersAction(0),
58 m_expandedUrls(),
59 m_font(),
60 m_decorationSize()
61 {
62 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
63 Q_ASSERT(settings != 0);
64 Q_ASSERT(dolphinViewController != 0);
65 Q_ASSERT(viewModeController != 0);
66
67 setLayoutDirection(Qt::LeftToRight);
68 setAcceptDrops(true);
69 setSortingEnabled(true);
70 setUniformRowHeights(true);
71 setSelectionBehavior(SelectItems);
72 setDragDropMode(QAbstractItemView::DragDrop);
73 setDropIndicatorShown(false);
74 setAlternatingRowColors(true);
75 setRootIsDecorated(settings->expandableFolders());
76 setItemsExpandable(settings->expandableFolders());
77 setEditTriggers(QAbstractItemView::NoEditTriggers);
78 setModel(proxyModel);
79
80 setMouseTracking(true);
81
82 const ViewProperties props(viewModeController->url());
83 setSortIndicatorSection(props.sorting());
84 setSortIndicatorOrder(props.sortOrder());
85
86 QHeaderView* headerView = header();
87 connect(headerView, SIGNAL(sectionClicked(int)),
88 this, SLOT(synchronizeSortingState(int)));
89 headerView->setContextMenuPolicy(Qt::CustomContextMenu);
90 connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
91 this, SLOT(configureSettings(const QPoint&)));
92 connect(headerView, SIGNAL(sectionResized(int, int, int)),
93 this, SLOT(slotHeaderSectionResized(int, int, int)));
94 connect(headerView, SIGNAL(sectionHandleDoubleClicked(int)),
95 this, SLOT(disableAutoResizing()));
96
97 connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)),
98 this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
99 connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
100 this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
101
102 connect(this, SIGNAL(clicked(const QModelIndex&)),
103 dolphinViewController, SLOT(requestTab(const QModelIndex&)));
104 if (KGlobalSettings::singleClick()) {
105 connect(this, SIGNAL(clicked(const QModelIndex&)),
106 dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
107 } else {
108 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
109 dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
110 }
111
112 connect(this, SIGNAL(entered(const QModelIndex&)),
113 this, SLOT(slotEntered(const QModelIndex&)));
114 connect(this, SIGNAL(viewportEntered()),
115 dolphinViewController, SLOT(emitViewportEntered()));
116 connect(viewModeController, SIGNAL(zoomLevelChanged(int)),
117 this, SLOT(setZoomLevel(int)));
118 connect(dolphinViewController->view(), SIGNAL(additionalInfoChanged()),
119 this, SLOT(updateColumnVisibility()));
120 connect(viewModeController, SIGNAL(activationChanged(bool)),
121 this, SLOT(slotActivationChanged(bool)));
122
123 if (settings->useSystemFont()) {
124 m_font = KGlobalSettings::generalFont();
125 } else {
126 m_font = QFont(settings->fontFamily(),
127 qRound(settings->fontSize()),
128 settings->fontWeight(),
129 settings->italicFont());
130 m_font.setPointSizeF(settings->fontSize());
131 }
132
133 setVerticalScrollMode(QTreeView::ScrollPerPixel);
134 setHorizontalScrollMode(QTreeView::ScrollPerPixel);
135
136 const DolphinView* view = dolphinViewController->view();
137 connect(view, SIGNAL(showPreviewChanged()),
138 this, SLOT(slotShowPreviewChanged()));
139
140
141 viewport()->installEventFilter(this);
142
143 connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)),
144 this, SLOT(slotGlobalSettingsChanged(int)));
145
146 m_expandableFoldersAction = new QAction(i18nc("@option:check", "Expandable Folders"), this);
147 m_expandableFoldersAction->setCheckable(true);
148 connect(m_expandableFoldersAction, SIGNAL(toggled(bool)),
149 this, SLOT(setFoldersExpandable(bool)));
150
151 connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(slotExpanded(const QModelIndex&)));
152 connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(slotCollapsed(const QModelIndex&)));
153
154 updateDecorationSize(view->showPreview());
155
156 m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController);
157 m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
158
159 KDirLister *dirLister = qobject_cast<KDirModel*>(proxyModel->sourceModel())->dirLister();
160 connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SLOT(resizeColumns()));
161 }
162
163 DolphinDetailsView::~DolphinDetailsView()
164 {
165 }
166
167 QSet<KUrl> DolphinDetailsView::expandedUrls() const
168 {
169 return m_expandedUrls;
170 }
171
172 bool DolphinDetailsView::event(QEvent* event)
173 {
174 if (event->type() == QEvent::Polish) {
175 header()->setResizeMode(QHeaderView::Interactive);
176 updateColumnVisibility();
177 }
178
179 return DolphinTreeView::event(event);
180 }
181
182 QStyleOptionViewItem DolphinDetailsView::viewOptions() const
183 {
184 QStyleOptionViewItem viewOptions = DolphinTreeView::viewOptions();
185 viewOptions.font = m_font;
186 viewOptions.fontMetrics = QFontMetrics(m_font);
187 viewOptions.showDecorationSelected = true;
188 viewOptions.decorationSize = m_decorationSize;
189 return viewOptions;
190 }
191
192 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
193 {
194 DolphinTreeView::contextMenuEvent(event);
195
196 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
197 m_expandableFoldersAction->setChecked(settings->expandableFolders());
198 m_dolphinViewController->triggerContextMenuRequest(event->pos(),
199 QList<QAction*>() << m_expandableFoldersAction);
200 }
201
202 void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
203 {
204 m_dolphinViewController->requestActivation();
205
206 DolphinTreeView::mousePressEvent(event);
207
208 const QModelIndex index = indexAt(event->pos());
209 if (!index.isValid() || (index.column() != DolphinModel::Name)) {
210 // The mouse press is done somewhere outside the filename column
211 if (QApplication::mouseButtons() & Qt::MidButton) {
212 m_dolphinViewController->replaceUrlByClipboard();
213 }
214 }
215 }
216
217 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
218 {
219 DragAndDropHelper::instance().startDrag(this, supportedActions, m_dolphinViewController);
220 DolphinTreeView::startDrag(supportedActions);
221 }
222
223 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
224 {
225 event->acceptProposedAction();
226 DolphinTreeView::dragEnterEvent(event);
227 }
228
229 void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
230 {
231 DolphinTreeView::dragMoveEvent(event);
232 event->acceptProposedAction();
233 }
234
235 void DolphinDetailsView::dropEvent(QDropEvent* event)
236 {
237 const QModelIndex index = indexAt(event->pos());
238 KFileItem item;
239 if (index.isValid() && (index.column() == DolphinModel::Name)) {
240 item = m_dolphinViewController->itemForIndex(index);
241 }
242 m_dolphinViewController->indicateDroppedUrls(item, m_viewModeController->url(), event);
243 DolphinTreeView::dropEvent(event);
244 }
245
246 void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
247 {
248 DolphinTreeView::keyPressEvent(event);
249 m_dolphinViewController->handleKeyPressEvent(event);
250 }
251
252 void DolphinDetailsView::resizeEvent(QResizeEvent* event)
253 {
254 DolphinTreeView::resizeEvent(event);
255 if (m_autoResize) {
256 resizeColumns();
257 }
258 }
259
260 void DolphinDetailsView::wheelEvent(QWheelEvent* event)
261 {
262 const int step = m_decorationSize.height();
263 verticalScrollBar()->setSingleStep(step);
264 DolphinTreeView::wheelEvent(event);
265 }
266
267 void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
268 {
269 m_extensionsFactory->handleCurrentIndexChange(current, previous);
270 DolphinTreeView::currentChanged(current, previous);
271
272 // If folders are expanded, the width which is available for editing may have changed
273 // because it depends on the level of the current item in the folder hierarchy.
274 adjustMaximumSizeForEditing(current);
275 }
276
277 bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event)
278 {
279 if ((watched == viewport()) && (event->type() == QEvent::Leave)) {
280 // If the mouse is above an item and moved very fast outside the widget,
281 // no viewportEntered() signal might be emitted although the mouse has been moved
282 // above the viewport.
283 m_dolphinViewController->emitViewportEntered();
284 }
285
286 return DolphinTreeView::eventFilter(watched, event);
287 }
288
289 QRect DolphinDetailsView::visualRect(const QModelIndex& index) const
290 {
291 QRect rect = DolphinTreeView::visualRect(index);
292 const KFileItem item = m_dolphinViewController->itemForIndex(index);
293 if (!item.isNull()) {
294 const int width = DolphinFileItemDelegate::nameColumnWidth(item.text(), viewOptions());
295
296 if (width < rect.width()) {
297 rect.setWidth(width);
298 }
299 }
300
301 return rect;
302 }
303
304 bool DolphinDetailsView::acceptsDrop(const QModelIndex& index) const
305 {
306 if (index.isValid() && (index.column() == DolphinModel::Name)) {
307 // Accept drops above directories
308 const KFileItem item = m_dolphinViewController->itemForIndex(index);
309 return !item.isNull() && item.isDir();
310 }
311
312 return false;
313 }
314
315 void DolphinDetailsView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
316 {
317 removeExpandedIndexes(parent, start, end);
318 DolphinTreeView::rowsAboutToBeRemoved(parent, start, end);
319 }
320
321 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
322 {
323 header()->setSortIndicator(sorting, header()->sortIndicatorOrder());
324 }
325
326 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
327 {
328 header()->setSortIndicator(header()->sortIndicatorSection(), sortOrder);
329 }
330
331 void DolphinDetailsView::synchronizeSortingState(int column)
332 {
333 // The sorting has already been changed in QTreeView if this slot is
334 // invoked, but Dolphin is not informed about this.
335 DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
336 const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
337 m_dolphinViewController->indicateSortingChange(sorting);
338 m_dolphinViewController->indicateSortOrderChange(sortOrder);
339 }
340
341 void DolphinDetailsView::slotEntered(const QModelIndex& index)
342 {
343 if (index.column() == DolphinModel::Name) {
344 m_dolphinViewController->emitItemEntered(index);
345 } else {
346 m_dolphinViewController->emitViewportEntered();
347 }
348 }
349
350 void DolphinDetailsView::setZoomLevel(int level)
351 {
352 const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);
353 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
354
355 const bool showPreview = m_dolphinViewController->view()->showPreview();
356 if (showPreview) {
357 settings->setPreviewSize(size);
358 } else {
359 settings->setIconSize(size);
360 }
361
362 updateDecorationSize(showPreview);
363 }
364
365 void DolphinDetailsView::slotShowPreviewChanged()
366 {
367 const DolphinView* view = m_dolphinViewController->view();
368 updateDecorationSize(view->showPreview());
369 }
370
371 void DolphinDetailsView::configureSettings(const QPoint& pos)
372 {
373 KMenu popup(this);
374 popup.addTitle(i18nc("@title:menu", "Columns"));
375
376 // Add checkbox items for each column
377 QHeaderView* headerView = header();
378 const int columns = model()->columnCount();
379 for (int i = 0; i < columns; ++i) {
380 const int logicalIndex = headerView->logicalIndex(i);
381 const QString text = model()->headerData(logicalIndex, Qt::Horizontal).toString();
382 if (!text.isEmpty()) {
383 QAction* action = popup.addAction(text);
384 action->setCheckable(true);
385 action->setChecked(!headerView->isSectionHidden(logicalIndex));
386 action->setData(logicalIndex);
387 action->setEnabled(logicalIndex != DolphinModel::Name);
388 }
389 }
390 popup.addSeparator();
391
392 QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
393 if (activatedAction != 0) {
394 const bool show = activatedAction->isChecked();
395 const int columnIndex = activatedAction->data().toInt();
396
397 KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo();
398 const KFileItemDelegate::Information info = infoForColumn(columnIndex);
399 if (show) {
400 Q_ASSERT(!list.contains(info));
401 list.append(info);
402 } else {
403 Q_ASSERT(list.contains(info));
404 const int index = list.indexOf(info);
405 list.removeAt(index);
406 }
407
408 m_dolphinViewController->indicateAdditionalInfoChange(list);
409 setColumnHidden(columnIndex, !show);
410 resizeColumns();
411 }
412 }
413
414 void DolphinDetailsView::updateColumnVisibility()
415 {
416 QHeaderView* headerView = header();
417 disconnect(headerView, SIGNAL(sectionMoved(int, int, int)),
418 this, SLOT(saveColumnPositions()));
419
420 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
421 const QList<int> columnPositions = settings->columnPositions();
422
423 const KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo();
424 for (int i = DolphinModel::Name; i < DolphinModel::ExtraColumnCount; ++i) {
425 const KFileItemDelegate::Information info = infoForColumn(i);
426 const bool hide = !list.contains(info) && (i != DolphinModel::Name);
427 if (isColumnHidden(i) != hide) {
428 setColumnHidden(i, hide);
429 }
430
431 // If the list columnPositions has been written by an older Dolphin version,
432 // its length might be smaller than DolphinModel::ExtraColumnCount. Therefore,
433 // we have to check if item number i exists before accessing it.
434 if (i < columnPositions.length()) {
435 const int position = columnPositions[i];
436
437 // The position might be outside the correct range if the list columnPositions
438 // has been written by a newer Dolphin version with more columns.
439 if (position < DolphinModel::ExtraColumnCount) {
440 const int from = headerView->visualIndex(i);
441 headerView->moveSection(from, position);
442 }
443 }
444 }
445
446 resizeColumns();
447
448 connect(headerView, SIGNAL(sectionMoved(int, int, int)),
449 this, SLOT(saveColumnPositions()));
450 }
451
452 void DolphinDetailsView::resizeColumns()
453 {
454 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
455 // around 3 seconds for each (!) resize operation when having > 10000 items).
456 // This gets a problem especially when opening large directories, where several
457 // resize operations are received for showing the currently available items during
458 // loading (the application hangs around 20 seconds when loading > 10000 items).
459
460 QHeaderView* headerView = header();
461 const int rowCount = model()->rowCount();
462 QFontMetrics fontMetrics(viewport()->font());
463
464 // Define the maximum number of rows, where an exact (but expensive) calculation
465 // of the widths is done.
466 const int maxRowCount = 200;
467
468 // Calculate the required with for each column and store it in columnWidth[]
469 int columnWidth[DolphinModel::ExtraColumnCount];
470
471 for (int column = 0; column < DolphinModel::ExtraColumnCount; ++column) {
472 columnWidth[column] = 0;
473 if (!isColumnHidden(column)) {
474 // Calculate the required width for the current column and consider only
475 // up to maxRowCount columns for performance reasons
476 if (rowCount > 0) {
477 const QAbstractProxyModel* proxyModel = qobject_cast<const QAbstractProxyModel*>(model());
478 const KDirModel* dirModel = qobject_cast<const KDirModel*>(proxyModel->sourceModel());
479
480 const int count = qMin(rowCount, maxRowCount);
481 const QStyleOptionViewItem option = viewOptions();
482 for (int row = 0; row < count; ++row) {
483 const QModelIndex index = dirModel->index(row, column);
484 const int width = itemDelegate()->sizeHint(option, index).width();
485 if (width > columnWidth[column]) {
486 columnWidth[column] = width;
487 }
488 }
489 }
490
491 // Assure that the required width is sufficient for the header too
492 const int logicalIndex = headerView->logicalIndex(column);
493 const QString headline = model()->headerData(logicalIndex, Qt::Horizontal).toString();
494 // TODO: check Qt-sources which left/right-gap is used for the headlines
495 const int headlineWidth = fontMetrics.width(headline) + 20;
496
497 columnWidth[column] = qMax(columnWidth[column], headlineWidth);
498 }
499 }
500
501 // Resize all columns except of the name column
502 int requiredWidth = 0;
503 for (int column = KDirModel::Size; column < DolphinModel::ExtraColumnCount; ++column) {
504 if (!isColumnHidden(column)) {
505 requiredWidth += columnWidth[column];
506 headerView->resizeSection(column, columnWidth[column]);
507 }
508 }
509
510 // Resize the name column in a way that the whole available width is used
511 columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
512
513 const int minNameWidth = 300;
514 if (columnWidth[KDirModel::Name] < minNameWidth) {
515 columnWidth[KDirModel::Name] = minNameWidth;
516
517 if ((rowCount > 0) && (rowCount < maxRowCount)) {
518 // Try to decrease the name column width without clipping any text
519 const int nameWidth = sizeHintForColumn(DolphinModel::Name);
520 if (nameWidth + requiredWidth <= viewport()->width()) {
521 columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
522 } else if (nameWidth < minNameWidth) {
523 columnWidth[KDirModel::Name] = nameWidth;
524 }
525 }
526 }
527
528 headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]);
529 }
530
531 void DolphinDetailsView::saveColumnPositions()
532 {
533 QList<int> columnPositions;
534 for (int i = DolphinModel::Name; i < DolphinModel::ExtraColumnCount; ++i) {
535 columnPositions.append(header()->visualIndex(i));
536 }
537
538 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
539 settings->setColumnPositions(columnPositions);
540 }
541
542 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize)
543 {
544 Q_UNUSED(logicalIndex);
545 Q_UNUSED(oldSize);
546 Q_UNUSED(newSize);
547 // If the user changes the size of the headers, the autoresize feature should be
548 // turned off. As there is no dedicated interface to find out whether the header
549 // section has been resized by the user or by a resize event, another approach is used.
550 // Attention: Take care when changing the if-condition to verify that there is no
551 // regression in combination with bug 178630 (see fix in comment #8).
552 if ((QApplication::mouseButtons() & Qt::LeftButton) && header()->underMouse()) {
553 disableAutoResizing();
554 }
555
556 adjustMaximumSizeForEditing(currentIndex());
557 }
558
559 void DolphinDetailsView::slotActivationChanged(bool active)
560 {
561 setAlternatingRowColors(active);
562 }
563
564 void DolphinDetailsView::disableAutoResizing()
565 {
566 m_autoResize = false;
567 }
568
569 void DolphinDetailsView::requestActivation()
570 {
571 m_dolphinViewController->requestActivation();
572 }
573
574 void DolphinDetailsView::slotGlobalSettingsChanged(int category)
575 {
576 Q_UNUSED(category);
577
578 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
579 Q_ASSERT(settings != 0);
580 if (settings->useSystemFont()) {
581 m_font = KGlobalSettings::generalFont();
582 }
583 // Disconnect then reconnect, since the settings have been changed, the connection requirements may have also.
584 disconnect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
585 disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
586 if (KGlobalSettings::singleClick()) {
587 connect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
588 } else {
589 connect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
590 }
591 }
592
593
594 void DolphinDetailsView::setFoldersExpandable(bool expandable)
595 {
596 if (!expandable) {
597 // Collapse all expanded folders, as QTreeView::setItemsExpandable(false)
598 // does not do this task
599 const int rowCount = model()->rowCount();
600 for (int row = 0; row < rowCount; ++row) {
601 setExpanded(model()->index(row, 0), false);
602 }
603 }
604 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
605 settings->setExpandableFolders(expandable);
606 setRootIsDecorated(expandable);
607 setItemsExpandable(expandable);
608
609 // The width of the space which is available for editing has changed
610 // because of the (dis)appearance of the expanding toggles
611 adjustMaximumSizeForEditing(currentIndex());
612 }
613
614 void DolphinDetailsView::slotExpanded(const QModelIndex& index)
615 {
616 KFileItem item = m_dolphinViewController->itemForIndex(index);
617 if (!item.isNull()) {
618 m_expandedUrls.insert(item.url());
619 }
620 }
621
622 void DolphinDetailsView::slotCollapsed(const QModelIndex& index)
623 {
624 KFileItem item = m_dolphinViewController->itemForIndex(index);
625 if (!item.isNull()) {
626 m_expandedUrls.remove(item.url());
627 }
628 }
629
630 void DolphinDetailsView::removeExpandedIndexes(const QModelIndex& parent, int start, int end)
631 {
632 if (m_expandedUrls.isEmpty()) {
633 return;
634 }
635
636 for (int row = start; row <= end; row++) {
637 const QModelIndex index = model()->index(row, 0, parent);
638 if (isExpanded(index)) {
639 slotCollapsed(index);
640 removeExpandedIndexes(index, 0, model()->rowCount(index) - 1);
641 }
642 }
643 }
644
645 void DolphinDetailsView::updateDecorationSize(bool showPreview)
646 {
647 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
648 const int iconSize = showPreview ? settings->previewSize() : settings->iconSize();
649 setIconSize(QSize(iconSize, iconSize));
650 m_decorationSize = QSize(iconSize, iconSize);
651
652 if (m_extensionsFactory) {
653 // The old maximumSize used by KFileItemDelegate is not valid any more after the icon size change.
654 // It must be discarded before doItemsLayout() is called (see bug 234600).
655 m_extensionsFactory->fileItemDelegate()->setMaximumSize(QSize());
656 }
657
658 doItemsLayout();
659
660 // Calculate the new maximumSize for KFileItemDelegate after the icon size change.
661 QModelIndex current = currentIndex();
662 if (current.isValid()) {
663 adjustMaximumSizeForEditing(current);
664 }
665 }
666
667 KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const
668 {
669 return AdditionalInfoAccessor::instance().keyForColumn(columnIndex);
670 }
671
672 void DolphinDetailsView::adjustMaximumSizeForEditing(const QModelIndex& index)
673 {
674 // Make sure that the full width of the "Name" column is available for "Rename Inline".
675 // Before we do that, we have to check if m_extensionsFactory has been initialised because
676 // it is possible that we end up here before the constructor is finished (see bug 257035)
677 if (m_extensionsFactory) {
678 m_extensionsFactory->fileItemDelegate()->setMaximumSize(QTreeView::visualRect(index).size());
679 }
680 }
681
682 #include "dolphindetailsview.moc"