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