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