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