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