1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphindetailsview.h"
23 #include "dolphinmodel.h"
24 #include "dolphincontroller.h"
25 #include "dolphinfileitemdelegate.h"
26 #include "dolphinsettings.h"
27 #include "dolphinsortfilterproxymodel.h"
28 #include "draganddrophelper.h"
29 #include "selectionmanager.h"
30 #include "viewproperties.h"
31 #include "zoomlevelinfo.h"
33 #include "dolphin_detailsmodesettings.h"
34 #include "dolphin_generalsettings.h"
36 #include <kdirmodel.h>
40 #include <QAbstractProxyModel>
42 #include <QApplication>
43 #include <QHeaderView>
44 #include <QRubberBand>
48 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
, DolphinController
* controller
) :
51 m_expandingTogglePressed(false),
53 m_useDefaultIndexAt(true),
54 m_controller(controller
),
55 m_selectionManager(0),
58 m_showElasticBand(false),
59 m_elasticBandOrigin(),
60 m_elasticBandDestination()
62 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
63 Q_ASSERT(settings
!= 0);
64 Q_ASSERT(controller
!= 0);
66 setLayoutDirection(Qt::LeftToRight
);
68 setSortingEnabled(true);
69 setUniformRowHeights(true);
70 setSelectionBehavior(SelectItems
);
71 setDragDropMode(QAbstractItemView::DragDrop
);
72 setDropIndicatorShown(false);
73 setAlternatingRowColors(true);
74 setRootIsDecorated(settings
->expandableFolders());
75 setItemsExpandable(settings
->expandableFolders());
76 setEditTriggers(QAbstractItemView::NoEditTriggers
);
78 setMouseTracking(true);
80 const ViewProperties
props(controller
->url());
81 setSortIndicatorSection(props
.sorting());
82 setSortIndicatorOrder(props
.sortOrder());
84 QHeaderView
* headerView
= header();
85 connect(headerView
, SIGNAL(sectionClicked(int)),
86 this, SLOT(synchronizeSortingState(int)));
87 headerView
->setContextMenuPolicy(Qt::CustomContextMenu
);
88 connect(headerView
, SIGNAL(customContextMenuRequested(const QPoint
&)),
89 this, SLOT(configureColumns(const QPoint
&)));
90 connect(headerView
, SIGNAL(sectionResized(int, int, int)),
91 this, SLOT(slotHeaderSectionResized(int, int, int)));
92 connect(headerView
, SIGNAL(sectionHandleDoubleClicked(int)),
93 this, SLOT(disableAutoResizing()));
95 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
96 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
97 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
98 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
100 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
101 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
102 // necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the
103 // RETURN-key in keyPressEvent().
104 if (KGlobalSettings::singleClick()) {
105 connect(this, SIGNAL(clicked(const QModelIndex
&)),
106 controller
, SLOT(triggerItem(const QModelIndex
&)));
108 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
109 controller
, SLOT(triggerItem(const QModelIndex
&)));
112 if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
113 m_selectionManager
= new SelectionManager(this);
114 connect(m_selectionManager
, SIGNAL(selectionChanged()),
115 this, SLOT(requestActivation()));
116 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
117 m_selectionManager
, SLOT(reset()));
120 connect(this, SIGNAL(entered(const QModelIndex
&)),
121 this, SLOT(slotEntered(const QModelIndex
&)));
122 connect(this, SIGNAL(viewportEntered()),
123 controller
, SLOT(emitViewportEntered()));
124 connect(controller
, SIGNAL(zoomLevelChanged(int)),
125 this, SLOT(setZoomLevel(int)));
126 connect(controller
->dolphinView(), SIGNAL(additionalInfoChanged()),
127 this, SLOT(updateColumnVisibility()));
128 connect(controller
, SIGNAL(activationChanged(bool)),
129 this, SLOT(slotActivationChanged(bool)));
131 if (settings
->useSystemFont()) {
132 m_font
= KGlobalSettings::generalFont();
134 m_font
= QFont(settings
->fontFamily(),
135 settings
->fontSize(),
136 settings
->fontWeight(),
137 settings
->italicFont());
140 setVerticalScrollMode(QTreeView::ScrollPerPixel
);
141 setHorizontalScrollMode(QTreeView::ScrollPerPixel
);
143 const DolphinView
* view
= controller
->dolphinView();
144 connect(view
, SIGNAL(showPreviewChanged()),
145 this, SLOT(slotShowPreviewChanged()));
147 updateDecorationSize(view
->showPreview());
150 viewport()->installEventFilter(this);
152 connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
153 this, SLOT(updateFont()));
155 m_useDefaultIndexAt
= false;
158 DolphinDetailsView::~DolphinDetailsView()
162 bool DolphinDetailsView::event(QEvent
* event
)
164 if (event
->type() == QEvent::Polish
) {
165 QHeaderView
* headerView
= header();
166 headerView
->setResizeMode(QHeaderView::Interactive
);
167 headerView
->setMovable(false);
169 updateColumnVisibility();
171 hideColumn(DolphinModel::Rating
);
172 hideColumn(DolphinModel::Tags
);
173 } else if (event
->type() == QEvent::UpdateRequest
) {
174 // a wheel movement will scroll 4 items
175 if (model()->rowCount() > 0) {
176 verticalScrollBar()->setSingleStep((sizeHintForRow(0) / 3) * 4);
180 return QTreeView::event(event
);
183 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
185 QStyleOptionViewItem viewOptions
= QTreeView::viewOptions();
186 viewOptions
.font
= m_font
;
187 viewOptions
.showDecorationSelected
= true;
188 viewOptions
.decorationSize
= m_decorationSize
;
192 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
194 QTreeView::contextMenuEvent(event
);
195 m_controller
->triggerContextMenuRequest(event
->pos());
198 void DolphinDetailsView::mousePressEvent(QMouseEvent
* event
)
200 m_controller
->requestActivation();
202 const QModelIndex current
= currentIndex();
203 QTreeView::mousePressEvent(event
);
205 m_expandingTogglePressed
= false;
206 const QModelIndex index
= indexAt(event
->pos());
207 const bool updateState
= index
.isValid() &&
208 (index
.column() == DolphinModel::Name
) &&
209 (event
->button() == Qt::LeftButton
);
211 // TODO: See comment in DolphinIconsView::mousePressEvent(). Only update
212 // the state if no expanding/collapsing area has been hit:
213 const QRect rect
= visualRect(index
);
214 if (event
->pos().x() >= rect
.x() + indentation()) {
215 setState(QAbstractItemView::DraggingState
);
217 m_expandingTogglePressed
= true;
221 if (!index
.isValid() || (index
.column() != DolphinModel::Name
)) {
222 // the mouse press is done somewhere outside the filename column
223 if (QApplication::mouseButtons() & Qt::MidButton
) {
224 m_controller
->replaceUrlByClipboard();
227 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
228 if (!(modifier
& Qt::ShiftModifier
) && !(modifier
& Qt::ControlModifier
)) {
232 // restore the current index, other columns are handled as viewport area
233 selectionModel()->setCurrentIndex(current
, QItemSelectionModel::Current
);
236 if ((event
->button() == Qt::LeftButton
) && !m_expandingTogglePressed
) {
237 m_showElasticBand
= true;
238 const QPoint pos
= contentsPos();
239 const QPoint
scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value());
240 m_elasticBandOrigin
= event
->pos() + pos
+ scrollPos
;
241 m_elasticBandDestination
= m_elasticBandOrigin
;
245 void DolphinDetailsView::mouseMoveEvent(QMouseEvent
* event
)
247 if (m_showElasticBand
) {
248 const QPoint mousePos
= event
->pos();
249 const QModelIndex index
= indexAt(mousePos
);
250 if (!index
.isValid()) {
251 // the destination of the selection rectangle is above the viewport. In this
252 // case QTreeView does no selection at all, which is not the wanted behavior
253 // in Dolphin -> select all items within the elastic band rectangle
256 const int nameColumnWidth
= header()->sectionSize(DolphinModel::Name
);
257 QRect selRect
= elasticBandRect();
258 const QRect
nameColumnsRect(0, 0, nameColumnWidth
, viewport()->height());
259 selRect
= nameColumnsRect
.intersected(selRect
);
261 setSelection(selRect
, QItemSelectionModel::Select
);
265 // TODO: enable QTreeView::mouseMoveEvent(event) again, as soon
266 // as the Qt-issue #199631 has been fixed.
267 // QTreeView::mouseMoveEvent(event);
268 QAbstractItemView::mouseMoveEvent(event
);
271 // TODO: enable QTreeView::mouseMoveEvent(event) again, as soon
272 // as the Qt-issue #199631 has been fixed.
273 // QTreeView::mouseMoveEvent(event);
274 QAbstractItemView::mouseMoveEvent(event
);
277 if (m_expandingTogglePressed
) {
278 // Per default QTreeView starts either a selection or a drag operation when dragging
279 // the expanding toggle button (Qt-issue - see TODO comment in DolphinIconsView::mousePressEvent()).
280 // Turn off this behavior in Dolphin to stay predictable:
282 setState(QAbstractItemView::NoState
);
286 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
288 const QModelIndex index
= indexAt(event
->pos());
289 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
290 QTreeView::mouseReleaseEvent(event
);
292 // don't change the current index if the cursor is released
293 // above any other column than the name column, as the other
294 // columns act as viewport
295 const QModelIndex current
= currentIndex();
296 QTreeView::mouseReleaseEvent(event
);
297 selectionModel()->setCurrentIndex(current
, QItemSelectionModel::Current
);
300 m_expandingTogglePressed
= false;
301 if (m_showElasticBand
) {
303 m_showElasticBand
= false;
307 void DolphinDetailsView::startDrag(Qt::DropActions supportedActions
)
309 DragAndDropHelper::startDrag(this, supportedActions
, m_controller
);
310 m_showElasticBand
= false;
313 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
315 if (event
->mimeData()->hasUrls()) {
316 event
->acceptProposedAction();
319 if (m_showElasticBand
) {
321 m_showElasticBand
= false;
325 void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent
* event
)
327 QTreeView::dragLeaveEvent(event
);
328 setDirtyRegion(m_dropRect
);
331 void DolphinDetailsView::dragMoveEvent(QDragMoveEvent
* event
)
333 QTreeView::dragMoveEvent(event
);
335 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
336 setDirtyRegion(m_dropRect
);
337 const QModelIndex index
= indexAt(event
->pos());
338 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
339 const KFileItem item
= m_controller
->itemForIndex(index
);
340 if (!item
.isNull() && item
.isDir()) {
341 m_dropRect
= visualRect(index
);
343 m_dropRect
.setSize(QSize()); // set as invalid
345 setDirtyRegion(m_dropRect
);
348 if (event
->mimeData()->hasUrls()) {
349 // accept url drops, independently from the destination item
350 event
->acceptProposedAction();
354 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
356 const QModelIndex index
= indexAt(event
->pos());
358 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
359 item
= m_controller
->itemForIndex(index
);
361 m_controller
->indicateDroppedUrls(item
, m_controller
->url(), event
);
362 QTreeView::dropEvent(event
);
365 void DolphinDetailsView::paintEvent(QPaintEvent
* event
)
367 QTreeView::paintEvent(event
);
368 if (m_showElasticBand
) {
369 // The following code has been taken from QListView
370 // and adapted to DolphinDetailsView.
371 // (C) 1992-2007 Trolltech ASA
372 QStyleOptionRubberBand opt
;
374 opt
.shape
= QRubberBand::Rectangle
;
376 opt
.rect
= elasticBandRect();
378 QPainter
painter(viewport());
380 style()->drawControl(QStyle::CE_RubberBand
, &opt
, &painter
);
385 void DolphinDetailsView::keyPressEvent(QKeyEvent
* event
)
387 // If the Control modifier is pressed, a multiple selection
388 // is done and DolphinDetailsView::currentChanged() may not
389 // not change the selection in a custom way.
390 m_keyPressed
= !(event
->modifiers() & Qt::ControlModifier
);
392 QTreeView::keyPressEvent(event
);
393 m_controller
->handleKeyPressEvent(event
);
396 void DolphinDetailsView::keyReleaseEvent(QKeyEvent
* event
)
398 QTreeView::keyReleaseEvent(event
);
399 m_keyPressed
= false;
402 void DolphinDetailsView::resizeEvent(QResizeEvent
* event
)
407 QTreeView::resizeEvent(event
);
410 void DolphinDetailsView::wheelEvent(QWheelEvent
* event
)
412 if (m_selectionManager
!= 0) {
413 m_selectionManager
->reset();
416 // let Ctrl+wheel events propagate to the DolphinView for icon zooming
417 if (event
->modifiers() & Qt::ControlModifier
) {
422 QTreeView::wheelEvent(event
);
425 void DolphinDetailsView::currentChanged(const QModelIndex
& current
, const QModelIndex
& previous
)
427 QTreeView::currentChanged(current
, previous
);
429 // Stay consistent with QListView: When changing the current index by key presses,
430 // also change the selection.
432 selectionModel()->select(current
, QItemSelectionModel::ClearAndSelect
);
436 bool DolphinDetailsView::eventFilter(QObject
* watched
, QEvent
* event
)
438 if ((watched
== viewport()) && (event
->type() == QEvent::Leave
)) {
439 // if the mouse is above an item and moved very fast outside the widget,
440 // no viewportEntered() signal might be emitted although the mouse has been moved
441 // above the viewport
442 m_controller
->emitViewportEntered();
445 return QTreeView::eventFilter(watched
, event
);
448 QModelIndex
DolphinDetailsView::indexAt(const QPoint
& point
) const
450 // the blank portion of the name column counts as empty space
451 const QModelIndex index
= QTreeView::indexAt(point
);
452 const bool isAboveEmptySpace
= !m_useDefaultIndexAt
&&
453 (index
.column() == KDirModel::Name
) && !nameColumnRect(index
).contains(point
);
454 return isAboveEmptySpace
? QModelIndex() : index
;
457 void DolphinDetailsView::setSelection(const QRect
&rect
, QItemSelectionModel::SelectionFlags command
)
459 // We must override setSelection() as Qt calls it internally and when this happens
460 // we must ensure that the default indexAt() is used.
461 if (!m_showElasticBand
) {
462 m_useDefaultIndexAt
= true;
463 QTreeView::setSelection(rect
, command
);
464 m_useDefaultIndexAt
= false;
466 // Select the items contained within the elastic band.
468 // TODO - would this still work if the columns could be re-ordered
469 // (which I want to implement eventually :))?
471 // Very naive implementation - clears all selected, then walks a tree,
472 // selecting all items whose nameColumnRect(...) intersects rect.
474 // Choose a sensible startIndex - a parentless index in the
475 // name column, as close to the top of the rect as we
477 QRect normalisedRect
= rect
.normalized();
478 QModelIndex startIndex
= QTreeView::indexAt(normalisedRect
.topLeft());
479 if (startIndex
.isValid()) {
480 while (startIndex
.parent().isValid()) {
481 startIndex
= startIndex
.parent();
484 // just pick the topmost row for safety
485 model()->index(0, KDirModel::Name
);
487 startIndex
= model()->index(startIndex
.row(), KDirModel::Name
);
489 setSelectionRecursive(startIndex
, normalisedRect
, command
);
493 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
495 QHeaderView
* headerView
= header();
496 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
499 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
501 QHeaderView
* headerView
= header();
502 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
505 void DolphinDetailsView::synchronizeSortingState(int column
)
507 // The sorting has already been changed in QTreeView if this slot is
508 // invoked, but Dolphin is not informed about this.
509 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
510 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
511 m_controller
->indicateSortingChange(sorting
);
512 m_controller
->indicateSortOrderChange(sortOrder
);
515 void DolphinDetailsView::slotEntered(const QModelIndex
& index
)
517 if (index
.column() == DolphinModel::Name
) {
518 m_controller
->emitItemEntered(index
);
520 m_controller
->emitViewportEntered();
524 void DolphinDetailsView::updateElasticBand()
526 if (m_showElasticBand
) {
527 QRect
dirtyRegion(elasticBandRect());
528 const QPoint
scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value());
529 m_elasticBandDestination
= viewport()->mapFromGlobal(QCursor::pos()) + scrollPos
;
530 dirtyRegion
= dirtyRegion
.united(elasticBandRect());
531 setDirtyRegion(dirtyRegion
);
535 QRect
DolphinDetailsView::elasticBandRect() const
537 const QPoint
pos(contentsPos());
538 const QPoint
scrollPos(horizontalScrollBar()->value(), verticalScrollBar()->value());
540 const QPoint topLeft
= m_elasticBandOrigin
- pos
- scrollPos
;
541 const QPoint bottomRight
= m_elasticBandDestination
- pos
- scrollPos
;
542 return QRect(topLeft
, bottomRight
).normalized();
545 void DolphinDetailsView::setZoomLevel(int level
)
547 const int size
= ZoomLevelInfo::iconSizeForZoomLevel(level
);
548 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
550 const bool showPreview
= m_controller
->dolphinView()->showPreview();
552 settings
->setPreviewSize(size
);
554 settings
->setIconSize(size
);
557 updateDecorationSize(showPreview
);
561 void DolphinDetailsView::slotShowPreviewChanged()
563 const DolphinView
* view
= m_controller
->dolphinView();
564 updateDecorationSize(view
->showPreview());
567 void DolphinDetailsView::configureColumns(const QPoint
& pos
)
570 popup
.addTitle(i18nc("@title:menu", "Columns"));
572 QHeaderView
* headerView
= header();
573 for (int i
= DolphinModel::Size
; i
<= DolphinModel::Type
; ++i
) {
574 const int logicalIndex
= headerView
->logicalIndex(i
);
575 const QString text
= model()->headerData(i
, Qt::Horizontal
).toString();
576 QAction
* action
= popup
.addAction(text
);
577 action
->setCheckable(true);
578 action
->setChecked(!headerView
->isSectionHidden(logicalIndex
));
582 QAction
* activatedAction
= popup
.exec(header()->mapToGlobal(pos
));
583 if (activatedAction
!= 0) {
584 const bool show
= activatedAction
->isChecked();
585 const int columnIndex
= activatedAction
->data().toInt();
587 KFileItemDelegate::InformationList list
= m_controller
->dolphinView()->additionalInfo();
588 const KFileItemDelegate::Information info
= infoForColumn(columnIndex
);
590 Q_ASSERT(!list
.contains(info
));
593 Q_ASSERT(list
.contains(info
));
594 const int index
= list
.indexOf(info
);
595 list
.removeAt(index
);
598 m_controller
->indicateAdditionalInfoChange(list
);
599 setColumnHidden(columnIndex
, !show
);
603 void DolphinDetailsView::updateColumnVisibility()
605 const KFileItemDelegate::InformationList list
= m_controller
->dolphinView()->additionalInfo();
606 for (int i
= DolphinModel::Size
; i
<= DolphinModel::Type
; ++i
) {
607 const KFileItemDelegate::Information info
= infoForColumn(i
);
608 const bool hide
= !list
.contains(info
);
609 if (isColumnHidden(i
) != hide
) {
610 setColumnHidden(i
, hide
);
617 void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex
, int oldSize
, int newSize
)
619 Q_UNUSED(logicalIndex
);
622 if (QApplication::mouseButtons() & Qt::LeftButton
) {
623 disableAutoResizing();
627 void DolphinDetailsView::slotActivationChanged(bool active
)
629 setAlternatingRowColors(active
);
632 void DolphinDetailsView::disableAutoResizing()
634 m_autoResize
= false;
637 void DolphinDetailsView::requestActivation()
639 m_controller
->requestActivation();
642 void DolphinDetailsView::updateFont()
644 const DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
645 Q_ASSERT(settings
!= 0);
647 if (settings
->useSystemFont()) {
648 m_font
= KGlobalSettings::generalFont();
652 void DolphinDetailsView::updateDecorationSize(bool showPreview
)
654 DetailsModeSettings
* settings
= DolphinSettings::instance().detailsModeSettings();
655 const int iconSize
= showPreview
? settings
->previewSize() : settings
->iconSize();
656 setIconSize(QSize(iconSize
, iconSize
));
657 m_decorationSize
= QSize(iconSize
, iconSize
);
659 if (m_selectionManager
!= 0) {
660 m_selectionManager
->reset();
666 QPoint
DolphinDetailsView::contentsPos() const
668 // implementation note: the horizonal position is ignored currently, as no
669 // horizontal scrolling is done anyway during a selection
670 const QScrollBar
* scrollbar
= verticalScrollBar();
671 Q_ASSERT(scrollbar
!= 0);
673 const int maxHeight
= maximumViewportSize().height();
674 const int height
= scrollbar
->maximum() - scrollbar
->minimum() + 1;
675 const int visibleHeight
= model()->rowCount() + 1 - height
;
676 if (visibleHeight
<= 0) {
680 const int y
= scrollbar
->sliderPosition() * maxHeight
/ visibleHeight
;
684 KFileItemDelegate::Information
DolphinDetailsView::infoForColumn(int columnIndex
) const
686 KFileItemDelegate::Information info
= KFileItemDelegate::NoInformation
;
688 switch (columnIndex
) {
689 case DolphinModel::Size
: info
= KFileItemDelegate::Size
; break;
690 case DolphinModel::ModifiedTime
: info
= KFileItemDelegate::ModificationTime
; break;
691 case DolphinModel::Permissions
: info
= KFileItemDelegate::Permissions
; break;
692 case DolphinModel::Owner
: info
= KFileItemDelegate::Owner
; break;
693 case DolphinModel::Group
: info
= KFileItemDelegate::OwnerAndGroup
; break;
694 case DolphinModel::Type
: info
= KFileItemDelegate::FriendlyMimeType
; break;
701 void DolphinDetailsView::resizeColumns()
703 // Using the resize mode QHeaderView::ResizeToContents is too slow (it takes
704 // around 3 seconds for each (!) resize operation when having > 10000 items).
705 // This gets a problem especially when opening large directories, where several
706 // resize operations are received for showing the currently available items during
707 // loading (the application hangs around 20 seconds when loading > 10000 items).
709 QHeaderView
* headerView
= header();
710 QFontMetrics
fontMetrics(viewport()->font());
712 int columnWidth
[KDirModel::ColumnCount
];
713 columnWidth
[KDirModel::Size
] = fontMetrics
.width("00000 Items");
714 columnWidth
[KDirModel::ModifiedTime
] = fontMetrics
.width("0000-00-00 00:00");
715 columnWidth
[KDirModel::Permissions
] = fontMetrics
.width("xxxxxxxxxx");
716 columnWidth
[KDirModel::Owner
] = fontMetrics
.width("xxxxxxxxxx");
717 columnWidth
[KDirModel::Group
] = fontMetrics
.width("xxxxxxxxxx");
718 columnWidth
[KDirModel::Type
] = fontMetrics
.width("XXXX Xxxxxxx");
720 int requiredWidth
= 0;
721 for (int i
= KDirModel::Size
; i
<= KDirModel::Type
; ++i
) {
722 if (!isColumnHidden(i
)) {
723 columnWidth
[i
] += 20; // provide a default gap
724 requiredWidth
+= columnWidth
[i
];
725 headerView
->resizeSection(i
, columnWidth
[i
]);
729 // resize the name column in a way that the whole available width is used
730 columnWidth
[KDirModel::Name
] = viewport()->width() - requiredWidth
;
731 if (columnWidth
[KDirModel::Name
] < 120) {
732 columnWidth
[KDirModel::Name
] = 120;
734 headerView
->resizeSection(KDirModel::Name
, columnWidth
[KDirModel::Name
]);
737 QRect
DolphinDetailsView::nameColumnRect(const QModelIndex
& index
) const
739 QRect rect
= visualRect(index
);
740 const KFileItem item
= m_controller
->itemForIndex(index
);
741 if (!item
.isNull()) {
742 const int width
= DolphinFileItemDelegate::nameColumnWidth(item
.name(), viewOptions());
743 rect
.setWidth(width
);
749 void DolphinDetailsView::setSelectionRecursive(const QModelIndex
& startIndex
,
751 QItemSelectionModel::SelectionFlags command
)
753 if (!startIndex
.isValid()) {
757 // rect is assumed to be in viewport coordinates and normalized.
758 // Move down through the siblings of startIndex, exploring the children
759 // of any expanded nodes.
760 Q_ASSERT(rect
.width() >= 0 && rect
.height() >= 0);
761 QModelIndex currIndex
= startIndex
;
763 const QModelIndex belowIndex
= indexBelow(currIndex
);
764 if (isExpanded(currIndex
)) {
765 // If belowIndex exists and is above the top of rect, then we need not explore
766 // the children of currIndex as they will always be above "below". Otherwise,
767 // explore the children.
768 if (!belowIndex
.isValid() || visualRect(belowIndex
).bottom() >= rect
.top()) {
769 setSelectionRecursive(currIndex
.child(0, currIndex
.column()), rect
, command
);
773 QRect itemContentRect
= nameColumnRect(currIndex
);
774 if (itemContentRect
.top() > rect
.bottom()) {
775 // All remaining items will be below itemContentRect, so we may cull.
779 if (itemContentRect
.intersects(rect
)) {
780 selectionModel()->select(currIndex
, QItemSelectionModel::Select
);
783 currIndex
= belowIndex
;
784 } while (currIndex
.isValid());
787 #include "dolphindetailsview.moc"