1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * Copyright (C) 2008 by Simon St. James (kdedevel@etotheipiplusone.com) *
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 "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"
36 #include "dolphin_detailsmodesettings.h"
37 #include "dolphin_generalsettings.h"
44 #include <QApplication>
45 #include <QHeaderView>
48 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
,
49 DolphinViewController
* dolphinViewController
,
50 const ViewModeController
* viewModeController
,
51 DolphinSortFilterProxyModel
* proxyModel
) :
52 DolphinTreeView(parent
),
54 m_dolphinViewController(dolphinViewController
),
55 m_extensionsFactory(0),
56 m_expandableFoldersAction(0),
61 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
63 Q_ASSERT(dolphinViewController
);
64 Q_ASSERT(viewModeController
);
66 setLayoutDirection(Qt::LeftToRight
);
68 setSortingEnabled(true);
69 setSelectionBehavior(SelectItems
);
70 setDragDropMode(QAbstractItemView::DragDrop
);
71 setDropIndicatorShown(false);
72 setAlternatingRowColors(true);
73 setRootIsDecorated(settings
->expandableFolders());
74 setItemsExpandable(settings
->expandableFolders());
75 setEditTriggers(QAbstractItemView::NoEditTriggers
);
78 setMouseTracking(true);
80 const ViewProperties
props(viewModeController
->url());
81 setSortIndicatorSection(props
.sorting());
82 setSortIndicatorOrder(props
.sortOrder());
84 QHeaderView
* headerView
= header();
85 connect(headerView
, SIGNAL(sectionClicked(int)),
86 this, SLOT(synchronizeSortingState(int)));
87 headerView
->setContextMenuPolicy(Qt::CustomContextMenu
);
88 connect(headerView
, SIGNAL(customContextMenuRequested(const QPoint
&)),
89 this, SLOT(configureSettings(const QPoint
&)));
90 connect(headerView
, SIGNAL(sectionResized(int, int, int)),
91 this, SLOT(slotHeaderSectionResized(int, int, int)));
92 connect(headerView
, SIGNAL(sectionHandleDoubleClicked(int)),
93 this, SLOT(disableAutoResizing()));
95 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
96 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
97 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
98 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
100 connect(this, SIGNAL(clicked(const QModelIndex
&)),
101 dolphinViewController
, SLOT(requestTab(const QModelIndex
&)));
102 if (KGlobalSettings::singleClick()) {
103 connect(this, SIGNAL(clicked(const QModelIndex
&)),
104 dolphinViewController
, SLOT(triggerItem(const QModelIndex
&)));
106 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
107 dolphinViewController
, SLOT(triggerItem(const QModelIndex
&)));
110 connect(this, SIGNAL(entered(const QModelIndex
&)),
111 this, SLOT(slotEntered(const QModelIndex
&)));
112 connect(this, SIGNAL(viewportEntered()),
113 dolphinViewController
, SLOT(emitViewportEntered()));
114 connect(viewModeController
, SIGNAL(zoomLevelChanged(int)),
115 this, SLOT(setZoomLevel(int)));
116 connect(dolphinViewController
->view(), SIGNAL(additionalInfoChanged()),
117 this, SLOT(updateColumnVisibility()));
118 connect(viewModeController
, SIGNAL(activationChanged(bool)),
119 this, SLOT(slotActivationChanged(bool)));
121 if (settings
->useSystemFont()) {
122 m_font
= KGlobalSettings::generalFont();
124 m_font
= QFont(settings
->fontFamily(),
125 qRound(settings
->fontSize()),
126 settings
->fontWeight(),
127 settings
->italicFont());
128 m_font
.setPointSizeF(settings
->fontSize());
131 setVerticalScrollMode(QTreeView::ScrollPerPixel
);
132 setHorizontalScrollMode(QTreeView::ScrollPerPixel
);
134 const DolphinView
* view
= dolphinViewController
->view();
135 connect(view
, SIGNAL(showPreviewChanged()),
136 this, SLOT(slotShowPreviewChanged()));
138 viewport()->installEventFilter(this);
140 connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)),
141 this, SLOT(slotGlobalSettingsChanged(int)));
143 m_expandableFoldersAction
= new QAction(i18nc("@option:check", "Expandable Folders"), this);
144 m_expandableFoldersAction
->setCheckable(true);
145 connect(m_expandableFoldersAction
, SIGNAL(toggled(bool)),
146 this, SLOT(setFoldersExpandable(bool)));
148 connect(this, SIGNAL(expanded(const QModelIndex
&)), this, SLOT(slotExpanded(const QModelIndex
&)));
149 connect(this, SIGNAL(collapsed(const QModelIndex
&)), this, SLOT(slotCollapsed(const QModelIndex
&)));
151 updateDecorationSize(view
->showPreview());
153 m_extensionsFactory
= new ViewExtensionsFactory(this, dolphinViewController
, viewModeController
);
154 m_extensionsFactory
->fileItemDelegate()->setMinimizedNameColumn(true);
156 KDirLister
*dirLister
= qobject_cast
<KDirModel
*>(proxyModel
->sourceModel())->dirLister();
157 connect(dirLister
, SIGNAL(newItems(KFileItemList
)), this, SLOT(resizeColumns()));
160 DolphinDetailsView::~DolphinDetailsView()
164 QSet
<KUrl
> DolphinDetailsView::expandedUrls() const
166 return m_expandedUrls
;
169 bool DolphinDetailsView::event(QEvent
* event
)
171 if (event
->type() == QEvent::Polish
) {
172 header()->setResizeMode(QHeaderView::Interactive
);
173 updateColumnVisibility();
176 return DolphinTreeView::event(event
);
179 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
181 QStyleOptionViewItem viewOptions
= DolphinTreeView::viewOptions();
182 viewOptions
.font
= m_font
;
183 viewOptions
.fontMetrics
= QFontMetrics(m_font
);
184 viewOptions
.showDecorationSelected
= true;
185 viewOptions
.decorationSize
= m_decorationSize
;
189 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
191 DolphinTreeView::contextMenuEvent(event
);
193 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
194 m_expandableFoldersAction
->setChecked(settings
->expandableFolders());
195 m_dolphinViewController
->triggerContextMenuRequest(event
->pos(),
196 QList
<QAction
*>() << m_expandableFoldersAction
);
199 void DolphinDetailsView::mousePressEvent(QMouseEvent
* event
)
201 m_dolphinViewController
->requestActivation();
203 DolphinTreeView::mousePressEvent(event
);
205 const QModelIndex index
= indexAt(event
->pos());
206 if (!index
.isValid() || (index
.column() != DolphinModel::Name
)) {
207 // The mouse press is done somewhere outside the filename column
208 if (QApplication::mouseButtons() & Qt::MidButton
) {
209 m_dolphinViewController
->replaceUrlByClipboard();
214 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions
)
216 DragAndDropHelper::instance().startDrag(this, supportedActions
, m_dolphinViewController
);
217 DolphinTreeView::startDrag(supportedActions
);
220 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
222 event
->acceptProposedAction();
223 DolphinTreeView::dragEnterEvent(event
);
226 void DolphinDetailsView::dragMoveEvent(QDragMoveEvent
* event
)
228 DolphinTreeView::dragMoveEvent(event
);
229 event
->acceptProposedAction();
232 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
234 const QModelIndex index
= indexAt(event
->pos());
236 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
237 item
= m_dolphinViewController
->itemForIndex(index
);
239 m_dolphinViewController
->indicateDroppedUrls(item
, event
);
240 DolphinTreeView::dropEvent(event
);
243 void DolphinDetailsView::keyPressEvent(QKeyEvent
* event
)
245 DolphinTreeView::keyPressEvent(event
);
246 m_dolphinViewController
->handleKeyPressEvent(event
);
249 void DolphinDetailsView::resizeEvent(QResizeEvent
* event
)
251 DolphinTreeView::resizeEvent(event
);
257 void DolphinDetailsView::wheelEvent(QWheelEvent
* event
)
259 const int step
= m_decorationSize
.height();
260 verticalScrollBar()->setSingleStep(step
);
261 DolphinTreeView::wheelEvent(event
);
264 void DolphinDetailsView::currentChanged(const QModelIndex
& current
, const QModelIndex
& previous
)
266 m_extensionsFactory
->handleCurrentIndexChange(current
, previous
);
267 DolphinTreeView::currentChanged(current
, previous
);
269 // If folders are expanded, the width which is available for editing may have changed
270 // because it depends on the level of the current item in the folder hierarchy.
271 adjustMaximumSizeForEditing(current
);
274 bool DolphinDetailsView::eventFilter(QObject
* watched
, QEvent
* event
)
276 if ((watched
== viewport()) && (event
->type() == QEvent::Leave
)) {
277 // If the mouse is above an item and moved very fast outside the widget,
278 // no viewportEntered() signal might be emitted although the mouse has been moved
279 // above the viewport.
280 m_dolphinViewController
->emitViewportEntered();
283 return DolphinTreeView::eventFilter(watched
, event
);
286 QRect
DolphinDetailsView::visualRect(const QModelIndex
& index
) const
288 QRect rect
= DolphinTreeView::visualRect(index
);
289 const KFileItem item
= m_dolphinViewController
->itemForIndex(index
);
290 if (!item
.isNull()) {
291 const int width
= DolphinFileItemDelegate::nameColumnWidth(item
.text(), viewOptions());
293 if (width
< rect
.width()) {
294 rect
.setWidth(width
);
301 bool DolphinDetailsView::acceptsDrop(const QModelIndex
& index
) const
303 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
304 // Accept drops above directories
305 const KFileItem item
= m_dolphinViewController
->itemForIndex(index
);
306 return !item
.isNull() && item
.isDir();
312 void DolphinDetailsView::rowsAboutToBeRemoved(const QModelIndex
&parent
, int start
, int end
)
314 removeExpandedIndexes(parent
, start
, end
);
315 DolphinTreeView::rowsAboutToBeRemoved(parent
, start
, end
);
318 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
320 header()->setSortIndicator(sorting
, header()->sortIndicatorOrder());
323 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
325 header()->setSortIndicator(header()->sortIndicatorSection(), sortOrder
);
328 void DolphinDetailsView::synchronizeSortingState(int column
)
330 // The sorting has already been changed in QTreeView if this slot is
331 // invoked, but Dolphin is not informed about this.
332 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
333 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
334 m_dolphinViewController
->indicateSortingChange(sorting
);
335 m_dolphinViewController
->indicateSortOrderChange(sortOrder
);
338 void DolphinDetailsView::slotEntered(const QModelIndex
& index
)
340 if (index
.column() == DolphinModel::Name
) {
341 m_dolphinViewController
->emitItemEntered(index
);
343 m_dolphinViewController
->emitViewportEntered();
347 void DolphinDetailsView::setZoomLevel(int level
)
349 const int size
= ZoomLevelInfo::iconSizeForZoomLevel(level
);
350 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
352 const bool showPreview
= m_dolphinViewController
->view()->showPreview();
354 settings
->setPreviewSize(size
);
356 settings
->setIconSize(size
);
359 updateDecorationSize(showPreview
);
362 void DolphinDetailsView::slotShowPreviewChanged()
364 const DolphinView
* view
= m_dolphinViewController
->view();
365 updateDecorationSize(view
->showPreview());
368 void DolphinDetailsView::configureSettings(const QPoint
& pos
)
371 popup
.addTitle(i18nc("@title:menu", "Columns"));
373 // Add checkbox items for each column
374 QHeaderView
* headerView
= header();
375 const int columns
= model()->columnCount();
376 for (int i
= 0; i
< columns
; ++i
) {
377 const int logicalIndex
= headerView
->logicalIndex(i
);
378 const QString text
= model()->headerData(logicalIndex
, Qt::Horizontal
).toString();
379 if (!text
.isEmpty()) {
380 QAction
* action
= popup
.addAction(text
);
381 action
->setCheckable(true);
382 action
->setChecked(!headerView
->isSectionHidden(logicalIndex
));
383 action
->setData(logicalIndex
);
384 action
->setEnabled(logicalIndex
!= DolphinModel::Name
);
387 popup
.addSeparator();
389 QAction
* activatedAction
= popup
.exec(header()->mapToGlobal(pos
));
390 if (activatedAction
) {
391 const bool show
= activatedAction
->isChecked();
392 const int columnIndex
= activatedAction
->data().toInt();
394 KFileItemDelegate::InformationList list
= m_dolphinViewController
->view()->additionalInfo();
395 const KFileItemDelegate::Information info
= infoForColumn(columnIndex
);
397 Q_ASSERT(!list
.contains(info
));
400 Q_ASSERT(list
.contains(info
));
401 const int index
= list
.indexOf(info
);
402 list
.removeAt(index
);
405 m_dolphinViewController
->indicateAdditionalInfoChange(list
);
406 setColumnHidden(columnIndex
, !show
);
411 void DolphinDetailsView::updateColumnVisibility()
413 QHeaderView
* headerView
= header();
414 disconnect(headerView
, SIGNAL(sectionMoved(int, int, int)),
415 this, SLOT(saveColumnPositions()));
417 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
418 const QList
<int> columnPositions
= settings
->columnPositions();
420 const KFileItemDelegate::InformationList list
= m_dolphinViewController
->view()->additionalInfo();
421 for (int i
= DolphinModel::Name
; i
< DolphinModel::ExtraColumnCount
; ++i
) {
422 const KFileItemDelegate::Information info
= infoForColumn(i
);
423 const bool hide
= !list
.contains(info
) && (i
!= DolphinModel::Name
);
424 if (isColumnHidden(i
) != hide
) {
425 setColumnHidden(i
, hide
);
428 // If the list columnPositions has been written by an older Dolphin version,
429 // its length might be smaller than DolphinModel::ExtraColumnCount. Therefore,
430 // we have to check if item number i exists before accessing it.
431 if (i
< columnPositions
.length()) {
432 const int position
= columnPositions
[i
];
434 // The position might be outside the correct range if the list columnPositions
435 // has been written by a newer Dolphin version with more columns.
436 if (position
< DolphinModel::ExtraColumnCount
) {
437 const int from
= headerView
->visualIndex(i
);
438 headerView
->moveSection(from
, position
);
445 connect(headerView
, SIGNAL(sectionMoved(int, int, int)),
446 this, SLOT(saveColumnPositions()));
449 void DolphinDetailsView::resizeColumns()
451 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
452 // around 3 seconds for each (!) resize operation when having > 10000 items).
453 // This gets a problem especially when opening large directories, where several
454 // resize operations are received for showing the currently available items during
455 // loading (the application hangs around 20 seconds when loading > 10000 items).
457 QHeaderView
* headerView
= header();
458 const int rowCount
= model()->rowCount();
459 QFontMetrics
fontMetrics(viewport()->font());
460 const int horizontalGap
= fontMetrics
.height();
462 // Define the maximum number of rows, where an exact (but expensive) calculation
463 // of the widths is done.
464 const int maxRowCount
= 200;
466 // Calculate the required with for each column and store it in columnWidth[]
467 int columnWidth
[DolphinModel::ExtraColumnCount
];
469 for (int column
= 0; column
< DolphinModel::ExtraColumnCount
; ++column
) {
470 columnWidth
[column
] = 0;
471 if (!isColumnHidden(column
)) {
472 // Calculate the required width for the current column and consider only
473 // up to maxRowCount columns for performance reasons
475 const int count
= qMin(rowCount
, maxRowCount
);
476 for (int row
= 0; row
< count
; ++row
) {
477 const QModelIndex index
= model()->index(row
, column
);
479 if (column
== DolphinModel::Size
) {
480 // This is a workaround as KFileItemDelegate::sizeHint() does not
481 // work in a way that is required for calculating the size.
482 const QAbstractProxyModel
* proxyModel
= qobject_cast
<const QAbstractProxyModel
*>(model());
483 const KDirModel
* dirModel
= qobject_cast
<const KDirModel
*>(proxyModel
->sourceModel());
484 const QModelIndex dirIndex
= proxyModel
->mapToSource(index
);
485 text
= itemSizeString(dirIndex
, dirModel
->itemForIndex(dirIndex
));
487 text
= model()->data(index
).toString();
489 const int width
= fontMetrics
.width(text
) + horizontalGap
;
490 if (width
> columnWidth
[column
]) {
491 columnWidth
[column
] = width
;
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 const int headlineWidth
= fontMetrics
.width(headline
) + horizontalGap
;
501 columnWidth
[column
] = qMax(columnWidth
[column
], headlineWidth
);
505 // Resize all columns except of the name column
506 int requiredWidth
= 0;
507 for (int column
= KDirModel::Size
; column
< DolphinModel::ExtraColumnCount
; ++column
) {
508 if (!isColumnHidden(column
)) {
509 requiredWidth
+= columnWidth
[column
];
510 headerView
->resizeSection(column
, columnWidth
[column
]);
514 // Resize the name column in a way that the whole available width is used
515 columnWidth
[KDirModel::Name
] = viewport()->width() - requiredWidth
;
517 const int minNameWidth
= 300;
518 if (columnWidth
[KDirModel::Name
] < minNameWidth
) {
519 columnWidth
[KDirModel::Name
] = minNameWidth
;
521 if ((rowCount
> 0) && (rowCount
< maxRowCount
)) {
522 // Try to decrease the name column width without clipping any text
523 const int nameWidth
= sizeHintForColumn(DolphinModel::Name
);
524 if (nameWidth
+ requiredWidth
<= viewport()->width()) {
525 columnWidth
[KDirModel::Name
] = viewport()->width() - requiredWidth
;
526 } else if (nameWidth
< minNameWidth
) {
527 columnWidth
[KDirModel::Name
] = nameWidth
;
532 headerView
->resizeSection(KDirModel::Name
, columnWidth
[KDirModel::Name
]);
535 void DolphinDetailsView::saveColumnPositions()
537 QList
<int> columnPositions
;
538 for (int i
= DolphinModel::Name
; i
< DolphinModel::ExtraColumnCount
; ++i
) {
539 columnPositions
.append(header()->visualIndex(i
));
542 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
543 settings
->setColumnPositions(columnPositions
);
546 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex
, int oldSize
, int newSize
)
548 Q_UNUSED(logicalIndex
);
551 // If the user changes the size of the headers, the autoresize feature should be
552 // turned off. As there is no dedicated interface to find out whether the header
553 // section has been resized by the user or by a resize event, another approach is used.
554 // Attention: Take care when changing the if-condition to verify that there is no
555 // regression in combination with bug 178630 (see fix in comment #8).
556 if ((QApplication::mouseButtons() & Qt::LeftButton
) && header()->underMouse()) {
557 disableAutoResizing();
560 adjustMaximumSizeForEditing(currentIndex());
563 void DolphinDetailsView::slotActivationChanged(bool active
)
565 setAlternatingRowColors(active
);
568 void DolphinDetailsView::disableAutoResizing()
570 m_autoResize
= false;
573 void DolphinDetailsView::requestActivation()
575 m_dolphinViewController
->requestActivation();
578 void DolphinDetailsView::slotGlobalSettingsChanged(int category
)
582 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
584 if (settings
->useSystemFont()) {
585 m_font
= KGlobalSettings::generalFont();
587 // Disconnect then reconnect, since the settings have been changed, the connection requirements may have also.
588 disconnect(this, SIGNAL(clicked(QModelIndex
)), m_dolphinViewController
, SLOT(triggerItem(QModelIndex
)));
589 disconnect(this, SIGNAL(doubleClicked(QModelIndex
)), m_dolphinViewController
, SLOT(triggerItem(QModelIndex
)));
590 if (KGlobalSettings::singleClick()) {
591 connect(this, SIGNAL(clicked(QModelIndex
)), m_dolphinViewController
, SLOT(triggerItem(QModelIndex
)));
593 connect(this, SIGNAL(doubleClicked(QModelIndex
)), m_dolphinViewController
, SLOT(triggerItem(QModelIndex
)));
598 void DolphinDetailsView::setFoldersExpandable(bool expandable
)
601 // Collapse all expanded folders, as QTreeView::setItemsExpandable(false)
602 // does not do this task
603 const int rowCount
= model()->rowCount();
604 for (int row
= 0; row
< rowCount
; ++row
) {
605 setExpanded(model()->index(row
, 0), false);
608 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
609 settings
->setExpandableFolders(expandable
);
610 setRootIsDecorated(expandable
);
611 setItemsExpandable(expandable
);
613 // The width of the space which is available for editing has changed
614 // because of the (dis)appearance of the expanding toggles
615 adjustMaximumSizeForEditing(currentIndex());
618 void DolphinDetailsView::slotExpanded(const QModelIndex
& index
)
620 KFileItem item
= m_dolphinViewController
->itemForIndex(index
);
621 if (!item
.isNull()) {
622 m_expandedUrls
.insert(item
.url());
626 void DolphinDetailsView::slotCollapsed(const QModelIndex
& index
)
628 KFileItem item
= m_dolphinViewController
->itemForIndex(index
);
629 if (!item
.isNull()) {
630 m_expandedUrls
.remove(item
.url());
634 void DolphinDetailsView::removeExpandedIndexes(const QModelIndex
& parent
, int start
, int end
)
636 if (m_expandedUrls
.isEmpty()) {
640 for (int row
= start
; row
<= end
; row
++) {
641 const QModelIndex index
= model()->index(row
, 0, parent
);
642 if (isExpanded(index
)) {
643 slotCollapsed(index
);
644 removeExpandedIndexes(index
, 0, model()->rowCount(index
) - 1);
649 void DolphinDetailsView::updateDecorationSize(bool showPreview
)
651 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
652 const int iconSize
= showPreview
? settings
->previewSize() : settings
->iconSize();
653 setIconSize(QSize(iconSize
, iconSize
));
654 m_decorationSize
= QSize(iconSize
, iconSize
);
656 if (m_extensionsFactory
) {
657 // The old maximumSize used by KFileItemDelegate is not valid any more after the icon size change.
658 // It must be discarded before doItemsLayout() is called (see bug 234600).
659 m_extensionsFactory
->fileItemDelegate()->setMaximumSize(QSize());
664 // Calculate the new maximumSize for KFileItemDelegate after the icon size change.
665 QModelIndex current
= currentIndex();
666 if (current
.isValid()) {
667 adjustMaximumSizeForEditing(current
);
671 KFileItemDelegate::Information
DolphinDetailsView::infoForColumn(int columnIndex
) const
673 return AdditionalInfoAccessor::instance().keyForColumn(columnIndex
);
676 void DolphinDetailsView::adjustMaximumSizeForEditing(const QModelIndex
& index
)
678 // Make sure that the full width of the "Name" column is available for "Rename Inline".
679 // Before we do that, we have to check if m_extensionsFactory has been initialised because
680 // it is possible that we end up here before the constructor is finished (see bug 257035)
681 if (m_extensionsFactory
) {
682 m_extensionsFactory
->fileItemDelegate()->setMaximumSize(QTreeView::visualRect(index
).size());
686 QString
DolphinDetailsView::itemSizeString(const QModelIndex
& index
, const KFileItem
& item
) const
688 // The following code has been copied from KFileItemDelegate::Private::itemSize()
689 // Copyright (c) 2006-2007, 2008 Fredrik Höglund <fredrik@kde.org>
690 // Ideally this should be handled by KFileItemDelegate::sizeHint().
692 return KGlobal::locale()->formatByteSize(item
.size());
695 // Return the number of items in the directory
696 const QVariant value
= index
.data(KDirModel::ChildCountRole
);
697 const int count
= value
.type() == QVariant::Int
? value
.toInt() : KDirModel::ChildCountUnknown
;
699 if (count
== KDirModel::ChildCountUnknown
) {
703 return i18ncp("Items in a folder", "1 item", "%1 items", count
);
706 #include "dolphindetailsview.moc"