]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
Provide an option for the details view to expand folders (= tree view), as this is...
[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 QTreeView::mouseMoveEvent(event);
231 updateElasticBand();
232 } else {
233 QTreeView::mouseMoveEvent(event);
234 }
235 }
236
237 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
238 {
239 QTreeView::mouseReleaseEvent(event);
240 if (m_showElasticBand) {
241 updateElasticBand();
242 m_showElasticBand = false;
243 }
244 }
245
246 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
247 {
248 DragAndDropHelper::startDrag(this, supportedActions);
249 }
250
251 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
252 {
253 if (event->mimeData()->hasUrls()) {
254 event->acceptProposedAction();
255 }
256
257 if (m_showElasticBand) {
258 updateElasticBand();
259 m_showElasticBand = false;
260 }
261 m_dragging = true;
262 }
263
264 void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent* event)
265 {
266 QTreeView::dragLeaveEvent(event);
267
268 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
269 m_dragging = false;
270 setDirtyRegion(m_dropRect);
271 }
272
273 void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
274 {
275 QTreeView::dragMoveEvent(event);
276
277 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
278 setDirtyRegion(m_dropRect);
279 const QModelIndex index = indexAt(event->pos());
280 if (!index.isValid() || (index.column() != DolphinModel::Name)) {
281 m_dragging = false;
282 } else {
283 m_dragging = true;
284 const KFileItem item = itemForIndex(index);
285 if (!item.isNull() && item.isDir()) {
286 m_dropRect = visualRect(index);
287 } else {
288 m_dropRect.setSize(QSize()); // set as invalid
289 }
290 setDirtyRegion(m_dropRect);
291 }
292
293 if (event->mimeData()->hasUrls()) {
294 // accept url drops, independently from the destination item
295 event->acceptProposedAction();
296 }
297 }
298
299 void DolphinDetailsView::dropEvent(QDropEvent* event)
300 {
301 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
302 if (!urls.isEmpty()) {
303 event->acceptProposedAction();
304 const QModelIndex index = indexAt(event->pos());
305 KFileItem item;
306 if (index.isValid() && (index.column() == DolphinModel::Name)) {
307 item = itemForIndex(index);
308 }
309 m_controller->indicateDroppedUrls(urls,
310 m_controller->url(),
311 item);
312 }
313 QTreeView::dropEvent(event);
314 m_dragging = false;
315 }
316
317 void DolphinDetailsView::paintEvent(QPaintEvent* event)
318 {
319 QTreeView::paintEvent(event);
320 if (m_showElasticBand) {
321 // The following code has been taken from QListView
322 // and adapted to DolphinDetailsView.
323 // (C) 1992-2007 Trolltech ASA
324 QStyleOptionRubberBand opt;
325 opt.initFrom(this);
326 opt.shape = QRubberBand::Rectangle;
327 opt.opaque = false;
328 opt.rect = elasticBandRect();
329
330 QPainter painter(viewport());
331 painter.save();
332 style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
333 painter.restore();
334 }
335
336 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
337 if (m_dragging) {
338 const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
339 DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
340 }
341 }
342
343 void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
344 {
345 QTreeView::keyPressEvent(event);
346
347 const QItemSelectionModel* selModel = selectionModel();
348 const QModelIndex currentIndex = selModel->currentIndex();
349 const bool trigger = currentIndex.isValid()
350 && (event->key() == Qt::Key_Return)
351 && (selModel->selectedIndexes().count() <= 1);
352 if (trigger) {
353 triggerItem(currentIndex);
354 }
355 }
356
357 void DolphinDetailsView::resizeEvent(QResizeEvent* event)
358 {
359 if (m_autoResize) {
360 resizeColumns();
361 }
362 QTreeView::resizeEvent(event);
363 }
364
365 void DolphinDetailsView::wheelEvent(QWheelEvent* event)
366 {
367 // let Ctrl+wheel events propagate to the DolphinView for icon zooming
368 if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) {
369 event->ignore();
370 return;
371 }
372 QTreeView::wheelEvent(event);
373 }
374
375 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
376 {
377 QHeaderView* headerView = header();
378 headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
379 }
380
381 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
382 {
383 QHeaderView* headerView = header();
384 headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
385 }
386
387 void DolphinDetailsView::synchronizeSortingState(int column)
388 {
389 // The sorting has already been changed in QTreeView if this slot is
390 // invoked, but Dolphin is not informed about this.
391 DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
392 const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
393 m_controller->indicateSortingChange(sorting);
394 m_controller->indicateSortOrderChange(sortOrder);
395 }
396
397 void DolphinDetailsView::slotEntered(const QModelIndex& index)
398 {
399 const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
400 const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
401 if (pos.x() < nameColumnWidth) {
402 m_controller->emitItemEntered(itemForIndex(index));
403 }
404 else {
405 m_controller->emitViewportEntered();
406 }
407 }
408
409 void DolphinDetailsView::updateElasticBand()
410 {
411 if (m_showElasticBand) {
412 QRect dirtyRegion(elasticBandRect());
413 m_elasticBandDestination = viewport()->mapFromGlobal(QCursor::pos());
414 dirtyRegion = dirtyRegion.united(elasticBandRect());
415 setDirtyRegion(dirtyRegion);
416 }
417 }
418
419 QRect DolphinDetailsView::elasticBandRect() const
420 {
421 const QPoint pos(contentsPos());
422 const QPoint topLeft(m_elasticBandOrigin.x() - pos.x(), m_elasticBandOrigin.y() - pos.y());
423 return QRect(topLeft, m_elasticBandDestination).normalized();
424 }
425
426 void DolphinDetailsView::zoomIn()
427 {
428 if (isZoomInPossible()) {
429 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
430 switch (settings->iconSize()) {
431 case KIconLoader::SizeSmall: settings->setIconSize(KIconLoader::SizeMedium); break;
432 case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
433 default: Q_ASSERT(false); break;
434 }
435 updateDecorationSize();
436 }
437 }
438
439 void DolphinDetailsView::zoomOut()
440 {
441 if (isZoomOutPossible()) {
442 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
443 switch (settings->iconSize()) {
444 case KIconLoader::SizeLarge: settings->setIconSize(KIconLoader::SizeMedium); break;
445 case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
446 default: Q_ASSERT(false); break;
447 }
448 updateDecorationSize();
449 }
450 }
451
452 void DolphinDetailsView::triggerItem(const QModelIndex& index)
453 {
454 const KFileItem item = itemForIndex(index);
455 if (index.isValid() && (index.column() == KDirModel::Name)) {
456 m_controller->triggerItem(item);
457 } else {
458 clearSelection();
459 m_controller->emitItemEntered(item);
460 }
461 }
462
463 void DolphinDetailsView::configureColumns(const QPoint& pos)
464 {
465 KMenu popup(this);
466 popup.addTitle(i18nc("@title:menu", "Columns"));
467
468 QHeaderView* headerView = header();
469 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
470 const int logicalIndex = headerView->logicalIndex(i);
471 const QString text = model()->headerData(i, Qt::Horizontal).toString();
472 QAction* action = popup.addAction(text);
473 action->setCheckable(true);
474 action->setChecked(!headerView->isSectionHidden(logicalIndex));
475 action->setData(i);
476 }
477
478 QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
479 if (activatedAction != 0) {
480 const bool show = activatedAction->isChecked();
481 const int columnIndex = activatedAction->data().toInt();
482
483 KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
484 const KFileItemDelegate::Information info = infoForColumn(columnIndex);
485 if (show) {
486 Q_ASSERT(!list.contains(info));
487 list.append(info);
488 } else {
489 Q_ASSERT(list.contains(info));
490 const int index = list.indexOf(info);
491 list.removeAt(index);
492 }
493
494 m_controller->indicateAdditionalInfoChange(list);
495 setColumnHidden(columnIndex, !show);
496 }
497 }
498
499 void DolphinDetailsView::updateColumnVisibility()
500 {
501 const KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
502 for (int i = DolphinModel::Size; i <= DolphinModel::Type; ++i) {
503 const KFileItemDelegate::Information info = infoForColumn(i);
504 const bool hide = !list.contains(info);
505 if (isColumnHidden(i) != hide) {
506 setColumnHidden(i, hide);
507 }
508 }
509
510 resizeColumns();
511 }
512
513 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize, int newSize)
514 {
515 Q_UNUSED(logicalIndex);
516 Q_UNUSED(oldSize);
517 Q_UNUSED(newSize);
518 if (QApplication::mouseButtons() & Qt::LeftButton) {
519 disableAutoResizing();
520 }
521 }
522
523 void DolphinDetailsView::disableAutoResizing()
524 {
525 m_autoResize = false;
526 }
527
528 void DolphinDetailsView::requestActivation()
529 {
530 m_controller->requestActivation();
531 }
532
533 bool DolphinDetailsView::isZoomInPossible() const
534 {
535 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
536 return settings->iconSize() < KIconLoader::SizeLarge;
537 }
538
539 bool DolphinDetailsView::isZoomOutPossible() const
540 {
541 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
542 return settings->iconSize() > KIconLoader::SizeSmall;
543 }
544
545 void DolphinDetailsView::updateDecorationSize()
546 {
547 DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
548 const int iconSize = settings->iconSize();
549 setIconSize(QSize(iconSize, iconSize));
550 m_decorationSize = QSize(iconSize, iconSize);
551
552 m_controller->setZoomInPossible(isZoomInPossible());
553 m_controller->setZoomOutPossible(isZoomOutPossible());
554
555 doItemsLayout();
556 }
557
558 QPoint DolphinDetailsView::contentsPos() const
559 {
560 // implementation note: the horizonal position is ignored currently, as no
561 // horizontal scrolling is done anyway during a selection
562 const QScrollBar* scrollbar = verticalScrollBar();
563 Q_ASSERT(scrollbar != 0);
564
565 const int maxHeight = maximumViewportSize().height();
566 const int height = scrollbar->maximum() - scrollbar->minimum() + 1;
567 const int visibleHeight = model()->rowCount() + 1 - height;
568 if (visibleHeight <= 0) {
569 return QPoint(0, 0);
570 }
571
572 const int y = scrollbar->sliderPosition() * maxHeight / visibleHeight;
573 return QPoint(0, y);
574 }
575
576 KFileItem DolphinDetailsView::itemForIndex(const QModelIndex& index) const
577 {
578 QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
579 KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
580 const QModelIndex dirIndex = proxyModel->mapToSource(index);
581 return dirModel->itemForIndex(dirIndex);
582 }
583
584 KFileItemDelegate::Information DolphinDetailsView::infoForColumn(int columnIndex) const
585 {
586 KFileItemDelegate::Information info = KFileItemDelegate::NoInformation;
587
588 switch (columnIndex) {
589 case DolphinModel::Size: info = KFileItemDelegate::Size; break;
590 case DolphinModel::ModifiedTime: info = KFileItemDelegate::ModificationTime; break;
591 case DolphinModel::Permissions: info = KFileItemDelegate::Permissions; break;
592 case DolphinModel::Owner: info = KFileItemDelegate::Owner; break;
593 case DolphinModel::Group: info = KFileItemDelegate::OwnerAndGroup; break;
594 case DolphinModel::Type: info = KFileItemDelegate::FriendlyMimeType; break;
595 default: break;
596 }
597
598 return info;
599 }
600
601 void DolphinDetailsView::resizeColumns()
602 {
603 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
604 // around 3 seconds for each (!) resize operation when having > 10000 items).
605 // This gets a problem especially when opening large directories, where several
606 // resize operations are received for showing the currently available items during
607 // loading (the application hangs around 20 seconds when loading > 10000 items).
608
609 QHeaderView* headerView = header();
610 QFontMetrics fontMetrics(viewport()->font());
611
612 int columnWidth[KDirModel::ColumnCount];
613 columnWidth[KDirModel::Size] = fontMetrics.width("00000 Items");
614 columnWidth[KDirModel::ModifiedTime] = fontMetrics.width("0000-00-00 00:00");
615 columnWidth[KDirModel::Permissions] = fontMetrics.width("xxxxxxxxxx");
616 columnWidth[KDirModel::Owner] = fontMetrics.width("xxxxxxxxxx");
617 columnWidth[KDirModel::Group] = fontMetrics.width("xxxxxxxxxx");
618 columnWidth[KDirModel::Type] = fontMetrics.width("XXXX Xxxxxxx");
619
620 int requiredWidth = 0;
621 for (int i = KDirModel::Size; i <= KDirModel::Type; ++i) {
622 if (!isColumnHidden(i)) {
623 columnWidth[i] += 20; // provide a default gap
624 requiredWidth += columnWidth[i];
625 headerView->resizeSection(i, columnWidth[i]);
626 }
627 }
628
629 // resize the name column in a way that the whole available width is used
630 columnWidth[KDirModel::Name] = viewport()->width() - requiredWidth;
631 if (columnWidth[KDirModel::Name] < 120) {
632 columnWidth[KDirModel::Name] = 120;
633 }
634 headerView->resizeSection(KDirModel::Name, columnWidth[KDirModel::Name]);
635 }
636
637 #include "dolphindetailsview.moc"