]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
provide zoom-out and zoom-in buttons beside the zoom slider
[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 QModelIndex index = indexAt(event->pos());
353 KFileItem item;
354 if (index.isValid() && (index.column() == DolphinModel::Name)) {
355 item = m_controller->itemForIndex(index);
356 }
357 m_controller->indicateDroppedUrls(item, m_controller->url(), event);
358 QTreeView::dropEvent(event);
359 }
360
361 void DolphinDetailsView::paintEvent(QPaintEvent* event)
362 {
363 QTreeView::paintEvent(event);
364 if (m_showElasticBand) {
365 // The following code has been taken from QListView
366 // and adapted to DolphinDetailsView.
367 // (C) 1992-2007 Trolltech ASA
368 QStyleOptionRubberBand opt;
369 opt.initFrom(this);
370 opt.shape = QRubberBand::Rectangle;
371 opt.opaque = false;
372 opt.rect = elasticBandRect();
373
374 QPainter painter(viewport());
375 painter.save();
376 style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
377 painter.restore();
378 }
379 }
380
381 void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
382 {
383 // If the Control modifier is pressed, a multiple selection
384 // is done and DolphinDetailsView::currentChanged() may not
385 // not change the selection in a custom way.
386 m_keyPressed = !(event->modifiers() & Qt::ControlModifier);
387
388 QTreeView::keyPressEvent(event);
389 m_controller->handleKeyPressEvent(event);
390 }
391
392 void DolphinDetailsView::keyReleaseEvent(QKeyEvent* event)
393 {
394 QTreeView::keyReleaseEvent(event);
395 m_keyPressed = false;
396 }
397
398 void DolphinDetailsView::resizeEvent(QResizeEvent* event)
399 {
400 if (m_autoResize) {
401 resizeColumns();
402 }
403 QTreeView::resizeEvent(event);
404 }
405
406 void DolphinDetailsView::wheelEvent(QWheelEvent* event)
407 {
408 if (m_selectionManager != 0) {
409 m_selectionManager->reset();
410 }
411
412 // let Ctrl+wheel events propagate to the DolphinView for icon zooming
413 if (event->modifiers() & Qt::ControlModifier) {
414 event->ignore();
415 return;
416 }
417
418 QTreeView::wheelEvent(event);
419 }
420
421 void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
422 {
423 QTreeView::currentChanged(current, previous);
424
425 // Stay consistent with QListView: When changing the current index by key presses,
426 // also change the selection.
427 if (m_keyPressed) {
428 selectionModel()->select(current, QItemSelectionModel::ClearAndSelect);
429 }
430 }
431
432 bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event)
433 {
434 if ((watched == viewport()) && (event->type() == QEvent::Leave)) {
435 // if the mouse is above an item and moved very fast outside the widget,
436 // no viewportEntered() signal might be emitted although the mouse has been moved
437 // above the viewport
438 m_controller->emitViewportEntered();
439 }
440
441 return QTreeView::eventFilter(watched, event);
442 }
443
444 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
445 {
446 QHeaderView* headerView = header();
447 headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
448 }
449
450 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
451 {
452 QHeaderView* headerView = header();
453 headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
454 }
455
456 void DolphinDetailsView::synchronizeSortingState(int column)
457 {
458 // The sorting has already been changed in QTreeView if this slot is
459 // invoked, but Dolphin is not informed about this.
460 DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
461 const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
462 m_controller->indicateSortingChange(sorting);
463 m_controller->indicateSortOrderChange(sortOrder);
464 }
465
466 void DolphinDetailsView::slotEntered(const QModelIndex& index)
467 {
468 if (index.column() == DolphinModel::Name) {
469 m_controller->emitItemEntered(index);
470 } else {
471 m_controller->emitViewportEntered();
472 }
473 }
474
475 void DolphinDetailsView::updateElasticBand()
476 {
477 if (m_showElasticBand) {
478 QRect dirtyRegion(elasticBandRect());
479 m_elasticBandDestination = viewport()->mapFromGlobal(QCursor::pos());
480 dirtyRegion = dirtyRegion.united(elasticBandRect());
481 setDirtyRegion(dirtyRegion);
482 }
483 }
484
485 QRect DolphinDetailsView::elasticBandRect() const
486 {
487 const QPoint pos(contentsPos());
488 const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
489 return QRect(topLeft, m_elasticBandDestination).normalized();
490 }
491
492 void DolphinDetailsView::setZoomLevel(int level)
493 {
494 const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);
495 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
496
497 const bool showPreview = m_controller->dolphinView()->showPreview();
498 if (showPreview) {
499 settings->setPreviewSize(size);
500 } else {
501 settings->setIconSize(size);
502 }
503
504 updateDecorationSize(showPreview);
505 }
506
507
508 void DolphinDetailsView::slotShowPreviewChanged()
509 {
510 const DolphinView* view = m_controller->dolphinView();
511 updateDecorationSize(view->showPreview());
512 }
513
514 void DolphinDetailsView::configureColumns(const QPoint& pos)
515 {
516 KMenu popup(this);
517 popup.addTitle(i18nc("@title:menu", "Columns"));
518
519 QHeaderView* headerView = header();
520 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
521 const int logicalIndex = headerView->logicalIndex(i);
522 const QString text = model()->headerData(i, Qt::Horizontal).toString();
523 QAction* action = popup.addAction(text);
524 action->setCheckable(true);
525 action->setChecked(!headerView->isSectionHidden(logicalIndex));
526 action->setData(i);
527 }
528
529 QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
530 if (activatedAction != 0) {
531 const bool show = activatedAction->isChecked();
532 const int columnIndex = activatedAction->data().toInt();
533
534 KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
535 const KFileItemDelegate::Information info = infoForColumn(columnIndex);
536 if (show) {
537 Q_ASSERT(!list.contains(info));
538 list.append(info);
539 } else {
540 Q_ASSERT(list.contains(info));
541 const int index = list.indexOf(info);
542 list.removeAt(index);
543 }
544
545 m_controller->indicateAdditionalInfoChange(list);
546 setColumnHidden(columnIndex, !show);
547 }
548 }
549
550 void DolphinDetailsView::updateColumnVisibility()
551 {
552 const KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
553 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
554 const KFileItemDelegate::Information info = infoForColumn(i);
555 const bool hide = !list.contains(info);
556 if (isColumnHidden(i) != hide) {
557 setColumnHidden(i, hide);
558 }
559 }
560
561 resizeColumns();
562 }
563
564 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize)
565 {
566 Q_UNUSED(logicalIndex);
567 Q_UNUSED(oldSize);
568 Q_UNUSED(newSize);
569 if (QApplication::mouseButtons() & Qt::LeftButton) {
570 disableAutoResizing();
571 }
572 }
573
574 void DolphinDetailsView::slotActivationChanged(bool active)
575 {
576 setAlternatingRowColors(active);
577 }
578
579 void DolphinDetailsView::disableAutoResizing()
580 {
581 m_autoResize = false;
582 }
583
584 void DolphinDetailsView::requestActivation()
585 {
586 m_controller->requestActivation();
587 }
588
589 void DolphinDetailsView::updateFont()
590 {
591 const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
592 Q_ASSERT(settings != 0);
593
594 if (settings->useSystemFont()) {
595 m_font = KGlobalSettings::generalFont();
596 }
597 }
598
599 void DolphinDetailsView::updateDecorationSize(bool showPreview)
600 {
601 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
602 const int iconSize = showPreview ? settings->previewSize() : settings->iconSize();
603 setIconSize(QSize(iconSize, iconSize));
604 m_decorationSize = QSize(iconSize, iconSize);
605
606 if (m_selectionManager != 0) {
607 m_selectionManager->reset();
608 }
609
610 doItemsLayout();
611 }
612
613 QPoint DolphinDetailsView::contentsPos() const
614 {
615 // implementation note: the horizonal position is ignored currently, as no
616 // horizontal scrolling is done anyway during a selection
617 const QScrollBar* scrollbar = verticalScrollBar();
618 Q_ASSERT(scrollbar != 0);
619
620 const int maxHeight = maximumViewportSize().height();
621 const int height = scrollbar->maximum() - scrollbar->minimum() + 1;
622 const int visibleHeight = model()->rowCount() + 1 - height;
623 if (visibleHeight <= 0) {
624 return QPoint(0, 0);
625 }
626
627 const int y = scrollbar->sliderPosition() * maxHeight / visibleHeight;
628 return QPoint(0, y);
629 }
630
631 KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const
632 {
633 KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;
634
635 switch (columnIndex) {
636 case DolphinModel::Size: info = KFileItemDelegate::Size; break;
637 case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break;
638 case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break;
639 case DolphinModel::Owner: info = KFileItemDelegate::Owner; break;
640 case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break;
641 case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break;
642 default: break;
643 }
644
645 return info;
646 }
647
648 void DolphinDetailsView::resizeColumns()
649 {
650 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
651 // around 3 seconds for each (!) resize operation when having > 10000 items).
652 // This gets a problem especially when opening large directories, where several
653 // resize operations are received for showing the currently available items during
654 // loading (the application hangs around 20 seconds when loading > 10000 items).
655
656 QHeaderView* headerView = header();
657 QFontMetrics fontMetrics(viewport()->font());
658
659 int columnWidth[KDirModel::ColumnCount];
660 columnWidth[KDirModel::Size] = fontMetrics.width("00000 Items");
661 columnWidth[KDirModel::ModifiedTime] = fontMetrics.width("0000-00-00 00:00");
662 columnWidth[KDirModel::Permissions] = fontMetrics.width("xxxxxxxxxx");
663 columnWidth[KDirModel::Owner] = fontMetrics.width("xxxxxxxxxx");
664 columnWidth[KDirModel::Group] = fontMetrics.width("xxxxxxxxxx");
665 columnWidth[KDirModel::Type] = fontMetrics.width("XXXX Xxxxxxx");
666
667 int requiredWidth = 0;
668 for (int i = KDirModel::Size; i <= KDirModel::Type; ++i) {
669 if (!isColumnHidden(i)) {
670 columnWidth[i] += 20; // provide a default gap
671 requiredWidth += columnWidth[i];
672 headerView->resizeSection(i, columnWidth[i]);
673 }
674 }
675
676 // resize the name column in a way that the whole available width is used
677 columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
678 if (columnWidth[KDirModel::Name] < 120) {
679 columnWidth[KDirModel::Name] = 120;
680 }
681 headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]);
682 }
683
684 #include "dolphindetailsview.moc"