X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6d858cd70f4adb08757fb24e69d9cc3a3a713390..b607d3cc4bbce0ef496730b25dfe2ec7bf00ab7a:/src/kcategorizedview.cpp diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp index 97045f383..e178760ee 100644 --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -33,7 +33,7 @@ #include #include "kitemcategorizer.h" -#include "ksortfilterproxymodel.h" +#include "dolphinsortfilterproxymodel.h" class LessThan { @@ -44,7 +44,7 @@ public: CategoryPurpose }; - inline LessThan(const KSortFilterProxyModel *proxyModel, + inline LessThan(const DolphinSortFilterProxyModel *proxyModel, Purpose purpose) : proxyModel(proxyModel) , purpose(purpose) @@ -67,7 +67,7 @@ public: } private: - const KSortFilterProxyModel *proxyModel; + const DolphinSortFilterProxyModel *proxyModel; const Purpose purpose; }; @@ -83,7 +83,6 @@ KCategorizedView::Private::Private(KCategorizedView *listView) , isDragging(false) , dragLeftViewport(false) , proxyModel(0) - , lastIndex(QModelIndex()) { } @@ -201,19 +200,15 @@ QRect KCategorizedView::Private::visualRectInViewport(const QModelIndex &index) if (rows - trunc(rows)) rowsInt++; + retRect.setTop(retRect.top() + + (rowsInt * itemHeight) + + itemCategorizer->categoryHeight(listView->viewOptions()) + + listView->spacing() * 2); + if (listView->gridSize().isEmpty()) { retRect.setTop(retRect.top() + - (rowsInt * listView->spacing()) + - (rowsInt * itemHeight) + - itemCategorizer->categoryHeight(listView->viewOptions()) + - listView->spacing() * 2); - } - else - { - retRect.setTop(retRect.top() + - (rowsInt * itemHeight) + - itemCategorizer->categoryHeight(listView->viewOptions())); + (rowsInt * listView->spacing())); } } @@ -289,19 +284,15 @@ QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &cat if (rows - trunc(rows)) rowsInt++; + retRect.setTop(retRect.top() + + (rowsInt * itemHeight) + + itemCategorizer->categoryHeight(listView->viewOptions()) + + listView->spacing() * 2); + if (listView->gridSize().isEmpty()) { retRect.setTop(retRect.top() + - (rowsInt * listView->spacing()) + - (rowsInt * itemHeight) + - itemCategorizer->categoryHeight(listView->viewOptions()) + - listView->spacing() * 2); - } - else - { - retRect.setTop(retRect.top() + - (rowsInt * itemHeight) + - itemCategorizer->categoryHeight(listView->viewOptions())); + (rowsInt * listView->spacing())); } } @@ -396,6 +387,9 @@ void KCategorizedView::Private::drawNewCategory(const QModelIndex &index, void KCategorizedView::Private::updateScrollbars() { + // find the last index in the last category + 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(); @@ -491,7 +485,7 @@ void KCategorizedView::setModel(QAbstractItemModel *model) QListView::setModel(model); - d->proxyModel = dynamic_cast(model); + d->proxyModel = dynamic_cast(model); if (d->proxyModel) { @@ -630,6 +624,11 @@ void KCategorizedView::paintEvent(QPaintEvent *event) QStyleOptionViewItemV3 option = viewOptions(); option.widget = this; + if (wordWrap()) + { + option.features |= QStyleOptionViewItemV2::WrapText; + } + QPainter painter(viewport()); QRect area = event->rect(); const bool focus = (hasFocus() || viewport()->hasFocus()) && @@ -643,7 +642,7 @@ void KCategorizedView::paintEvent(QPaintEvent *event) foreach (const QModelIndex &index, dirtyIndexes) { option.state = state; - option.rect = d->visualRect(index); + option.rect = visualRect(index); if (selectionModel() && selectionModel()->isSelected(index)) { @@ -943,7 +942,7 @@ void KCategorizedView::mouseReleaseEvent(QMouseEvent *event) d->lastSelection = selectionModel()->selection(); if (d->hovered.isValid()) - viewport()->update(d->visualRect(d->hovered)); + viewport()->update(visualRect(d->hovered)); else if (!d->hoveredCategory.isEmpty()) viewport()->update(d->categoryVisualRect(d->hoveredCategory)); } @@ -1001,8 +1000,11 @@ void KCategorizedView::dragLeaveEvent(QDragLeaveEvent *event) QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) { - if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel || - !d->itemCategorizer) + if ( (viewMode() != KCategorizedView::IconMode) || + !d->proxyModel || + !d->itemCategorizer || + d->categories.isEmpty() + ) { return QListView::moveCursor(cursorAction, modifiers); } @@ -1024,9 +1026,10 @@ QModelIndex KCategorizedView::moveCursor(CursorAction cursorAction, int itemWidthPlusSeparation = spacing() + itemWidth; int elementsPerRow = viewportWidth / itemWidthPlusSeparation; - QString lastCategory = d->categories[0]; - QString theCategory = d->categories[0]; - QString afterCategory = d->categories[0]; + QString lastCategory = d->categories.first(); + QString theCategory = d->categories.first(); + QString afterCategory = d->categories.first(); + bool hasToBreak = false; foreach (const QString &category, d->categories) { @@ -1246,8 +1249,6 @@ void KCategorizedView::rowsInsertedArtifficial(const QModelIndex &parent, qStableSort(indexList.begin(), indexList.end(), categoryLessThan); } - d->lastIndex = d->categoriesIndexes[d->categories[d->categories.count() - 1]][d->categoriesIndexes[d->categories[d->categories.count() - 1]].count() - 1]; - // Finally, fill data information of items situation. This will help when // trying to compute an item place in the viewport int i = 0; // position relative to the category beginning