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