X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a2fc277e1d117b0b78cda5b7f084245e553f36c5..d351d41e4bfd982646d7919b7eeb2cf98992edc3:/src/kcategorizedview.cpp diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index 894da2cae..72936113c 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -24,7 +24,6 @@ #include // trunc on C99 compliant systems #include // trunc for not C99 compliant systems -#include #include #include #include @@ -361,7 +360,7 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index, } QStyleOption optionCopy = option; - const QString category = proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); + const QString category = proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); optionCopy.state &= ~QStyle::State_Selected; @@ -871,12 +870,29 @@ void KCategorizedView::setSelection(const QRect &rect, return; } + int viewportWidth = viewport()->width() - spacing(); + int itemWidth; + + if (gridSize().isEmpty()) + { + itemWidth = d->biggestItemSize.width(); + } + else + { + itemWidth = gridSize().width(); + } + + int itemWidthPlusSeparation = spacing() + itemWidth; + int elementsPerRow = viewportWidth / itemWidthPlusSeparation; + QItemSelection selection; if (!d->mouseButtonPressed) { selection = QItemSelection(dirtyIndexes[0], dirtyIndexes[0]); d->currentViewIndex = dirtyIndexes[0]; + selectionModel()->setCurrentIndex(d->currentViewIndex, flags); + d->forcedSelectionPosition = d->elementsInfo[d->currentViewIndex.row()].relativeOffsetToCategory % elementsPerRow; } else { @@ -898,6 +914,12 @@ void KCategorizedView::setSelection(const QRect &rect, if (last.isValid()) selection << QItemSelectionRange(first, last); + + if (first == last) + { + selectionModel()->setCurrentIndex(first, QItemSelectionModel::SelectCurrent); + d->forcedSelectionPosition = d->elementsInfo[first.row()].relativeOffsetToCategory % elementsPerRow; + } } if (d->lastSelection.count()) @@ -1329,7 +1351,7 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, } // Add all elements mapped to the source model and explore categories - QString prevCategory = d->proxyModel->data(d->proxyModel->index(0, d->proxyModel->sortColumn()), KCategorizedSortFilterProxyModel::CategoryRole).toString(); + QString prevCategory = d->proxyModel->data(d->proxyModel->index(0, d->proxyModel->sortColumn()), KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); QString lastCategory = prevCategory; QModelIndexList modelIndexList; struct Private::ElementInfo elementInfo; @@ -1346,7 +1368,7 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, d->modelIndexList << index; - lastCategory = d->proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryRole).toString(); + lastCategory = d->proxyModel->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); elementInfo.category = lastCategory;