]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphindetailsview.h"
22
23 #include "dolphinmodel.h"
24 #include "dolphincontroller.h"
25 #include "dolphinsettings.h"
26 #include "dolphinsortfilterproxymodel.h"
27 #include "draganddrophelper.h"
28 #include "selectionmanager.h"
29 #include "viewproperties.h"
30
31 #include "dolphin_detailsmodesettings.h"
32 #include "dolphin_generalsettings.h"
33
34 #include <kdirmodel.h>
35 #include <klocale.h>
36 #include <kmenu.h>
37
38 #include <QAbstractProxyModel>
39 #include <QAction>
40 #include <QApplication>
41 #include <QHeaderView>
42 #include <QRubberBand>
43 #include <QPainter>
44 #include <QScrollBar>
45
46 DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
47 QTreeView(parent),
48 m_autoResize(true),
49 m_expandingTogglePressed(false),
50 m_controller(controller),
51 m_selectionManager(0),
52 m_font(),
53 m_decorationSize(),
54 m_showElasticBand(false),
55 m_elasticBandOrigin(),
56 m_elasticBandDestination()
57 {
58 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
59 Q_ASSERT(settings != 0);
60 Q_ASSERT(controller != 0);
61
62 setAcceptDrops(true);
63 setSortingEnabled(true);
64 setUniformRowHeights(true);
65 setSelectionBehavior(SelectItems);
66 setDragDropMode(QAbstractItemView::DragDrop);
67 setDropIndicatorShown(false);
68 setAlternatingRowColors(true);
69 setRootIsDecorated(settings->expandableFolders());
70 setItemsExpandable(settings->expandableFolders());
71 setEditTriggers(QAbstractItemView::NoEditTriggers);
72
73 setMouseTracking(true);
74
75 const ViewProperties props(controller->url());
76 setSortIndicatorSection(props.sorting());
77 setSortIndicatorOrder(props.sortOrder());
78
79 QHeaderView* headerView = header();
80 connect(headerView, SIGNAL(sectionClicked(int)),
81 this, SLOT(synchronizeSortingState(int)));
82 headerView->setContextMenuPolicy(Qt::CustomContextMenu);
83 connect(headerView, SIGNAL(customContextMenuRequested(const QPoint&)),
84 this, SLOT(configureColumns(const QPoint&)));
85 connect(headerView, SIGNAL(sectionResized(int, int, int)),
86 this, SLOT(slotHeaderSectionResized(int, int, int)));
87 connect(headerView, SIGNAL(sectionHandleDoubleClicked(int)),
88 this, SLOT(disableAutoResizing()));
89
90 connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)),
91 this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
92 connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
93 this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
94
95 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
96 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
97 // necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the
98 // RETURN-key in keyPressEvent().
99 if (KGlobalSettings::singleClick()) {
100 connect(this, SIGNAL(clicked(const QModelIndex&)),
101 controller, SLOT(triggerItem(const QModelIndex&)));
102 if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
103 m_selectionManager = new SelectionManager(this);
104 connect(m_selectionManager, SIGNAL(selectionChanged()),
105 this, SLOT(requestActivation()));
106 connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
107 m_selectionManager, SLOT(reset()));
108 }
109 } else {
110 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
111 controller, SLOT(triggerItem(const QModelIndex&)));
112 }
113 connect(this, SIGNAL(entered(const QModelIndex&)),
114 this, SLOT(slotEntered(const QModelIndex&)));
115 connect(this, SIGNAL(viewportEntered()),
116 controller, SLOT(emitViewportEntered()));
117 connect(controller, SIGNAL(zoomIn()),
118 this, SLOT(zoomIn()));
119 connect(controller, SIGNAL(zoomOut()),
120 this, SLOT(zoomOut()));
121 connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
122 this, SLOT(updateColumnVisibility()));
123
124 if (settings->useSystemFont()) {
125 m_font = KGlobalSettings::generalFont();
126 } else {
127 m_font = QFont(settings->fontFamily(),
128 settings->fontSize(),
129 settings->fontWeight(),
130 settings->italicFont());
131 }
132
133 setVerticalScrollMode(QTreeView::ScrollPerPixel);
134 setHorizontalScrollMode(QTreeView::ScrollPerPixel);
135
136 updateDecorationSize();
137
138 setFocus();
139 viewport()->installEventFilter(this);
140
141 connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
142 this, SLOT(updateFont()));
143 }
144
145 DolphinDetailsView::~DolphinDetailsView()
146 {
147 }
148
149 bool DolphinDetailsView::event(QEvent* event)
150 {
151 if (event->type() == QEvent::Polish) {
152 QHeaderView* headerView = header();
153 headerView->setResizeMode(QHeaderView::Interactive);
154 headerView->setMovable(false);
155
156 updateColumnVisibility();
157
158 hideColumn(DolphinModel::Rating);
159 hideColumn(DolphinModel::Tags);
160 } else if (event->type() == QEvent::UpdateRequest) {
161 // a wheel movement will scroll 4 items
162 if (model()->rowCount() > 0) {
163 verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
164 }
165 }
166
167 return QTreeView::event(event);
168 }
169
170 QStyleOptionViewItem DolphinDetailsView::viewOptions() const
171 {
172 QStyleOptionViewItem viewOptions = QTreeView::viewOptions();
173 viewOptions.font = m_font;
174 viewOptions.showDecorationSelected = true;
175 viewOptions.decorationSize = m_decorationSize;
176 return viewOptions;
177 }
178
179 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
180 {
181 QTreeView::contextMenuEvent(event);
182 m_controller->triggerContextMenuRequest(event->pos());
183 }
184
185 void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
186 {
187 m_controller->requestActivation();
188
189 QTreeView::mousePressEvent(event);
190
191 m_expandingTogglePressed = false;
192 const QModelIndex index = indexAt(event->pos());
193 const bool updateState = index.isValid() &&
194 (index.column() == DolphinModel::Name) &&
195 (event->button() == Qt::LeftButton);
196 if (updateState) {
197 // TODO: See comment in DolphinIconsView::mousePressEvent(). Only update
198 // the state if no expanding/collapsing area has been hit:
199 const QRect rect = visualRect(index);
200 if (event->pos().x() >= rect.x() + indentation()) {
201 setState(QAbstractItemView::DraggingState);
202 } else {
203 m_expandingTogglePressed = true;
204 }
205 }
206
207 if (!index.isValid() || (index.column() != DolphinModel::Name)) {
208 const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
209 if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
210 clearSelection();
211 }
212 }
213
214 if ((event->button() == Qt::LeftButton) && !m_expandingTogglePressed) {
215 m_showElasticBand = true;
216
217 const QPoint pos(contentsPos());
218 m_elasticBandOrigin = event->pos();
219 m_elasticBandOrigin.setX(m_elasticBandOrigin.x() + pos.x());
220 m_elasticBandOrigin.setY(m_elasticBandOrigin.y() + pos.y());
221 m_elasticBandDestination = event->pos();
222 }
223 }
224
225 void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event)
226 {
227 if (m_showElasticBand) {
228 const QPoint mousePos = event->pos();
229 const QModelIndex index = indexAt(mousePos);
230 if (!index.isValid()) {
231 // the destination of the selection rectangle is above the viewport. In this
232 // case QTreeView does no selection at all, which is not the wanted behavior
233 // in Dolphin -> select all items within the elastic band rectangle
234 clearSelection();
235
236 const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
237 QRect selRect = QRect(m_elasticBandOrigin, m_elasticBandDestination).normalized();
238 const QRect nameColumnsRect(0, 0, nameColumnWidth, viewport()->height());
239 selRect = nameColumnsRect.intersected(selRect);
240
241 setSelection(selRect, QItemSelectionModel::Select);
242 }
243
244 // TODO: enable QTreeView::mouseMoveEvent(event) again, as soon
245 // as the Qt-issue #199631 has been fixed.
246 // QTreeView::mouseMoveEvent(event);
247 QAbstractItemView::mouseMoveEvent(event);
248 updateElasticBand();
249 } else {
250 // TODO: enable QTreeView::mouseMoveEvent(event) again, as soon
251 // as the Qt-issue #199631 has been fixed.
252 // QTreeView::mouseMoveEvent(event);
253 QAbstractItemView::mouseMoveEvent(event);
254 }
255
256 if (m_expandingTogglePressed) {
257 // Per default QTreeView starts either a selection or a drag operation when dragging
258 // the expanding toggle button (Qt-issue - see TODO comment in DolphinIconsView::mousePressEvent()).
259 // Turn off this behavior in Dolphin to stay predictable:
260 clearSelection();
261 setState(QAbstractItemView::NoState);
262 }
263 }
264
265 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
266 {
267 QTreeView::mouseReleaseEvent(event);
268 m_expandingTogglePressed = false;
269 if (m_showElasticBand) {
270 updateElasticBand();
271 m_showElasticBand = false;
272 }
273 }
274
275 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
276 {
277 DragAndDropHelper::startDrag(this, supportedActions);
278 m_showElasticBand = false;
279 }
280
281 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
282 {
283 if (event->mimeData()->hasUrls()) {
284 event->acceptProposedAction();
285 }
286
287 if (m_showElasticBand) {
288 updateElasticBand();
289 m_showElasticBand = false;
290 }
291 }
292
293 void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent* event)
294 {
295 QTreeView::dragLeaveEvent(event);
296 setDirtyRegion(m_dropRect);
297 }
298
299 void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
300 {
301 QTreeView::dragMoveEvent(event);
302
303 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
304 setDirtyRegion(m_dropRect);
305 const QModelIndex index = indexAt(event->pos());
306 if (index.isValid() && (index.column() == DolphinModel::Name)) {
307 const KFileItem item = m_controller->itemForIndex(index);
308 if (!item.isNull() && item.isDir()) {
309 m_dropRect = visualRect(index);
310 } else {
311 m_dropRect.setSize(QSize()); // set as invalid
312 }
313 setDirtyRegion(m_dropRect);
314 }
315
316 if (event->mimeData()->hasUrls()) {
317 // accept url drops, independently from the destination item
318 event->acceptProposedAction();
319 }
320 }
321
322 void DolphinDetailsView::dropEvent(QDropEvent* event)
323 {
324 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
325 if (!urls.isEmpty()) {
326 event->acceptProposedAction();
327 const QModelIndex index = indexAt(event->pos());
328 KFileItem item;
329 if (index.isValid() && (index.column() == DolphinModel::Name)) {
330 item = m_controller->itemForIndex(index);
331 }
332 m_controller->indicateDroppedUrls(urls,
333 m_controller->url(),
334 item);
335 }
336 QTreeView::dropEvent(event);
337 }
338
339 void DolphinDetailsView::paintEvent(QPaintEvent* event)
340 {
341 QTreeView::paintEvent(event);
342 if (m_showElasticBand) {
343 // The following code has been taken from QListView
344 // and adapted to DolphinDetailsView.
345 // (C) 1992-2007 Trolltech ASA
346 QStyleOptionRubberBand opt;
347 opt.initFrom(this);
348 opt.shape = QRubberBand::Rectangle;
349 opt.opaque = false;
350 opt.rect = elasticBandRect();
351
352 QPainter painter(viewport());
353 painter.save();
354 style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
355 painter.restore();
356 }
357 }
358
359 void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
360 {
361 QTreeView::keyPressEvent(event);
362 m_controller->handleKeyPressEvent(event);
363 }
364
365 void DolphinDetailsView::resizeEvent(QResizeEvent* event)
366 {
367 if (m_autoResize) {
368 resizeColumns();
369 }
370 QTreeView::resizeEvent(event);
371 }
372
373 void DolphinDetailsView::wheelEvent(QWheelEvent* event)
374 {
375 if (m_selectionManager != 0) {
376 m_selectionManager->reset();
377 }
378
379 // let Ctrl+wheel events propagate to the DolphinView for icon zooming
380 if (event->modifiers() & Qt::ControlModifier) {
381 event->ignore();
382 return;
383 }
384
385 QTreeView::wheelEvent(event);
386 }
387
388 void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
389 {
390 QTreeView::currentChanged(current, previous);
391
392 // Stay consistent with QListView: When changing the current index by key presses,
393 // also change the selection.
394 if (QApplication::mouseButtons() == Qt::NoButton) {
395 selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
396 }
397 }
398
399 bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event)
400 {
401 if ((watched == viewport()) && (event->type() == QEvent::Leave)) {
402 // if the mouse is above an item and moved very fast outside the widget,
403 // no viewportEntered() signal might be emitted although the mouse has been moved
404 // above the viewport
405 m_controller->emitViewportEntered();
406 }
407
408 return QTreeView::eventFilter(watched, event);
409 }
410
411 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
412 {
413 QHeaderView* headerView = header();
414 headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
415 }
416
417 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
418 {
419 QHeaderView* headerView = header();
420 headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
421 }
422
423 void DolphinDetailsView::synchronizeSortingState(int column)
424 {
425 // The sorting has already been changed in QTreeView if this slot is
426 // invoked, but Dolphin is not informed about this.
427 DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
428 const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
429 m_controller->indicateSortingChange(sorting);
430 m_controller->indicateSortOrderChange(sortOrder);
431 }
432
433 void DolphinDetailsView::slotEntered(const QModelIndex& index)
434 {
435 const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
436 const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
437 if (pos.x() < nameColumnWidth) {
438 m_controller->emitItemEntered(index);
439 }
440 else {
441 m_controller->emitViewportEntered();
442 }
443 }
444
445 void DolphinDetailsView::updateElasticBand()
446 {
447 if (m_showElasticBand) {
448 QRect dirtyRegion(elasticBandRect());
449 m_elasticBandDestination = viewport()->mapFromGlobal(QCursor::pos());
450 dirtyRegion = dirtyRegion.united(elasticBandRect());
451 setDirtyRegion(dirtyRegion);
452 }
453 }
454
455 QRect DolphinDetailsView::elasticBandRect() const
456 {
457 const QPoint pos(contentsPos());
458 const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
459 return QRect(topLeft, m_elasticBandDestination).normalized();
460 }
461
462 void DolphinDetailsView::zoomIn()
463 {
464 if (isZoomInPossible()) {
465 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
466 switch (settings->iconSize()) {
467 case KIconLoader::SizeSmall: settings->setIconSize(KIconLoader::SizeMedium); break;
468 case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
469 default: Q_ASSERT(false); break;
470 }
471 updateDecorationSize();
472 }
473 }
474
475 void DolphinDetailsView::zoomOut()
476 {
477 if (isZoomOutPossible()) {
478 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
479 switch (settings->iconSize()) {
480 case KIconLoader::SizeLarge: settings->setIconSize(KIconLoader::SizeMedium); break;
481 case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
482 default: Q_ASSERT(false); break;
483 }
484 updateDecorationSize();
485 }
486 }
487
488 void DolphinDetailsView::configureColumns(const QPoint& pos)
489 {
490 KMenu popup(this);
491 popup.addTitle(i18nc("@title:menu", "Columns"));
492
493 QHeaderView* headerView = header();
494 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
495 const int logicalIndex = headerView->logicalIndex(i);
496 const QString text = model()->headerData(i, Qt::Horizontal).toString();
497 QAction* action = popup.addAction(text);
498 action->setCheckable(true);
499 action->setChecked(!headerView->isSectionHidden(logicalIndex));
500 action->setData(i);
501 }
502
503 QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
504 if (activatedAction != 0) {
505 const bool show = activatedAction->isChecked();
506 const int columnIndex = activatedAction->data().toInt();
507
508 KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
509 const KFileItemDelegate::Information info = infoForColumn(columnIndex);
510 if (show) {
511 Q_ASSERT(!list.contains(info));
512 list.append(info);
513 } else {
514 Q_ASSERT(list.contains(info));
515 const int index = list.indexOf(info);
516 list.removeAt(index);
517 }
518
519 m_controller->indicateAdditionalInfoChange(list);
520 setColumnHidden(columnIndex, !show);
521 }
522 }
523
524 void DolphinDetailsView::updateColumnVisibility()
525 {
526 const KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
527 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
528 const KFileItemDelegate::Information info = infoForColumn(i);
529 const bool hide = !list.contains(info);
530 if (isColumnHidden(i) != hide) {
531 setColumnHidden(i, hide);
532 }
533 }
534
535 resizeColumns();
536 }
537
538 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize)
539 {
540 Q_UNUSED(logicalIndex);
541 Q_UNUSED(oldSize);
542 Q_UNUSED(newSize);
543 if (QApplication::mouseButtons() & Qt::LeftButton) {
544 disableAutoResizing();
545 }
546 }
547
548 void DolphinDetailsView::disableAutoResizing()
549 {
550 m_autoResize = false;
551 }
552
553 void DolphinDetailsView::requestActivation()
554 {
555 m_controller->requestActivation();
556 }
557
558 void DolphinDetailsView::updateFont()
559 {
560 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
561 Q_ASSERT(settings != 0);
562
563 if (settings->useSystemFont()) {
564 m_font = KGlobalSettings::generalFont();
565 }
566 }
567
568 bool DolphinDetailsView::isZoomInPossible() const
569 {
570 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
571 return settings->iconSize() < KIconLoader::SizeLarge;
572 }
573
574 bool DolphinDetailsView::isZoomOutPossible() const
575 {
576 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
577 return settings->iconSize() > KIconLoader::SizeSmall;
578 }
579
580 void DolphinDetailsView::updateDecorationSize()
581 {
582 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
583 const int iconSize = settings->iconSize();
584 setIconSize(QSize(iconSize, iconSize));
585 m_decorationSize = QSize(iconSize, iconSize);
586
587 m_controller->setZoomInPossible(isZoomInPossible());
588 m_controller->setZoomOutPossible(isZoomOutPossible());
589
590 if (m_selectionManager != 0) {
591 m_selectionManager->reset();
592 }
593
594 doItemsLayout();
595 }
596
597 QPoint DolphinDetailsView::contentsPos() const
598 {
599 // implementation note: the horizonal position is ignored currently, as no
600 // horizontal scrolling is done anyway during a selection
601 const QScrollBar* scrollbar = verticalScrollBar();
602 Q_ASSERT(scrollbar != 0);
603
604 const int maxHeight = maximumViewportSize().height();
605 const int height = scrollbar->maximum() - scrollbar->minimum() + 1;
606 const int visibleHeight = model()->rowCount() + 1 - height;
607 if (visibleHeight <= 0) {
608 return QPoint(0, 0);
609 }
610
611 const int y = scrollbar->sliderPosition() * maxHeight / visibleHeight;
612 return QPoint(0, y);
613 }
614
615 KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const
616 {
617 KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;
618
619 switch (columnIndex) {
620 case DolphinModel::Size: info = KFileItemDelegate::Size; break;
621 case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break;
622 case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break;
623 case DolphinModel::Owner: info = KFileItemDelegate::Owner; break;
624 case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break;
625 case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break;
626 default: break;
627 }
628
629 return info;
630 }
631
632 void DolphinDetailsView::resizeColumns()
633 {
634 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
635 // around 3 seconds for each (!) resize operation when having > 10000 items).
636 // This gets a problem especially when opening large directories, where several
637 // resize operations are received for showing the currently available items during
638 // loading (the application hangs around 20 seconds when loading > 10000 items).
639
640 QHeaderView* headerView = header();
641 QFontMetrics fontMetrics(viewport()->font());
642
643 int columnWidth[KDirModel::ColumnCount];
644 columnWidth[KDirModel::Size] = fontMetrics.width("00000 Items");
645 columnWidth[KDirModel::ModifiedTime] = fontMetrics.width("0000-00-00 00:00");
646 columnWidth[KDirModel::Permissions] = fontMetrics.width("xxxxxxxxxx");
647 columnWidth[KDirModel::Owner] = fontMetrics.width("xxxxxxxxxx");
648 columnWidth[KDirModel::Group] = fontMetrics.width("xxxxxxxxxx");
649 columnWidth[KDirModel::Type] = fontMetrics.width("XXXX Xxxxxxx");
650
651 int requiredWidth = 0;
652 for (int i = KDirModel::Size; i <= KDirModel::Type; ++i) {
653 if (!isColumnHidden(i)) {
654 columnWidth[i] += 20; // provide a default gap
655 requiredWidth += columnWidth[i];
656 headerView->resizeSection(i, columnWidth[i]);
657 }
658 }
659
660 // resize the name column in a way that the whole available width is used
661 columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
662 if (columnWidth[KDirModel::Name] < 120) {
663 columnWidth[KDirModel::Name] = 120;
664 }
665 headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]);
666 }
667
668 #include "dolphindetailsview.moc"