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