X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e4170c1910ad91fd31bc64edfab17ddc814411d5..c6992dd7f898a5c92b52d54a032efd1beef40980:/src/kcategorizedview.cpp diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index 8a0b3c8c5..51b4a000b 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -129,12 +129,12 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index) if (listView->layoutDirection() == Qt::LeftToRight) { retRect = QRect(listView->spacing(), listView->spacing() * 2 + - categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0); + categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0); } else { retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 + - categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0); + categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0); } int viewportWidth = listView->viewport()->width() - listView->spacing(); @@ -189,7 +189,7 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index) retRect.setTop(retRect.top() + (rowsInt * itemHeight) + - categoryDrawer->categoryHeight(listView->viewOptions()) + + categoryDrawer->categoryHeight(index, listView->viewOptions()) + listView->spacing() * 2); if (listView->gridSize().isEmpty()) @@ -273,7 +273,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat retRect.setTop(retRect.top() + (rowsInt * itemHeight) + - categoryDrawer->categoryHeight(listView->viewOptions()) + + categoryDrawer->categoryHeight(index, listView->viewOptions()) + listView->spacing() * 2); if (listView->gridSize().isEmpty()) @@ -283,7 +283,7 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat } } - retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions())); + retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions())); return retRect; } @@ -396,7 +396,7 @@ void KCategorizedView::Private::updateScrollbars() QModelIndex lastIndex = categoriesIndexes.isEmpty() ? QModelIndex() : categoriesIndexes[categories.last()].last(); int lastItemBottom = cachedRectIndex(lastIndex).top() + - listView->spacing() + (listView->gridSize().isEmpty() ? 0 : listView->gridSize().height()) - listView->viewport()->height(); + listView->spacing() + (listView->gridSize().isEmpty() ? biggestItemSize.height() : listView->gridSize().height()) - listView->viewport()->height(); listView->horizontalScrollBar()->setRange(0, 0); @@ -1242,17 +1242,6 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, return QListView::moveCursor(cursorAction, modifiers); } - QModelIndex current = selectionModel()->currentIndex(); - - if (!current.isValid()) - { - current = model()->index(0, 0, QModelIndex()); - selectionModel()->select(current, QItemSelectionModel::NoUpdate); - d->forcedSelectionPosition = 0; - - return current; - } - int viewportWidth = viewport()->width() - spacing(); int itemWidth; @@ -1270,6 +1259,28 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, if (!elementsPerRow) elementsPerRow++; + QModelIndex current = selectionModel()->currentIndex(); + + if (!current.isValid()) + { + if (cursorAction == MoveEnd) + { + current = model()->index(model()->rowCount() - 1, 0, QModelIndex()); + d->forcedSelectionPosition = d->elementsInfo[current.row()].relativeOffsetToCategory % elementsPerRow; + } + else + { + current = model()->index(0, 0, QModelIndex()); + d->forcedSelectionPosition = 0; + } + + return current; + } + else if (!current.isValid()) + { + return QModelIndex(); + } + QString lastCategory = d->categories.first(); QString theCategory = d->categories.first(); QString afterCategory = d->categories.first();