#include <kstyle.h>
#include "kitemcategorizer.h"
-#include "ksortfilterproxymodel.h"
+#include "dolphinsortfilterproxymodel.h"
class LessThan
{
CategoryPurpose
};
- inline LessThan(const KSortFilterProxyModel *proxyModel,
+ inline LessThan(const DolphinSortFilterProxyModel *proxyModel,
Purpose purpose)
: proxyModel(proxyModel)
, purpose(purpose)
}
private:
- const KSortFilterProxyModel *proxyModel;
+ const DolphinSortFilterProxyModel *proxyModel;
const Purpose purpose;
};
, isDragging(false)
, dragLeftViewport(false)
, proxyModel(0)
- , lastIndex(QModelIndex())
{
}
intersectedIndexes.clear();
+ int itemHeight;
+
+ if (listView->gridSize().isEmpty())
+ {
+ itemHeight = biggestItemSize.height();
+ }
+ else
+ {
+ itemHeight = listView->gridSize().height();
+ }
+
// Lets find out where we should start
int top = proxyModel->rowCount() - 1;
int bottom = 0;
index = elementDictionary[proxyModel->index(middle, 0)];
indexVisualRect = visualRect(index);
+ // We need the whole height (not only the visualRect). This will help us to update
+ // all needed indexes correctly (ereslibre)
+ indexVisualRect.setHeight(indexVisualRect.height() + (itemHeight - indexVisualRect.height()));
if (qMax(indexVisualRect.topLeft().y(),
indexVisualRect.bottomRight().y()) < qMin(rect.topLeft().y(),
- rect.bottomRight().y()))
+ rect.bottomRight().y()))
{
bottom = middle + 1;
}
if (rows - trunc(rows)) rowsInt++;
retRect.setTop(retRect.top() +
- (rowsInt * listView->spacing()) +
(rowsInt * itemHeight) +
itemCategorizer->categoryHeight(listView->viewOptions()) +
listView->spacing() * 2);
+
+ if (listView->gridSize().isEmpty())
+ {
+ retRect.setTop(retRect.top() +
+ (rowsInt * listView->spacing()));
+ }
}
- retRect.setTop(retRect.top() + row * listView->spacing() +
- row * itemHeight);
+
+ if (listView->gridSize().isEmpty())
+ {
+ retRect.setTop(retRect.top() + row * listView->spacing() +
+ (row * itemHeight));
+ }
+ else
+ {
+ retRect.setTop(retRect.top() + (row * itemHeight));
+ }
retRect.setWidth(itemWidth);
if (rows - trunc(rows)) rowsInt++;
retRect.setTop(retRect.top() +
- (rowsInt * listView->spacing()) +
(rowsInt * itemHeight) +
itemCategorizer->categoryHeight(listView->viewOptions()) +
listView->spacing() * 2);
+
+ if (listView->gridSize().isEmpty())
+ {
+ retRect.setTop(retRect.top() +
+ (rowsInt * listView->spacing()));
+ }
}
retRect.setHeight(itemCategorizer->categoryHeight(listView->viewOptions()));
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();
QListView::setModel(model);
- d->proxyModel = dynamic_cast<KSortFilterProxyModel*>(model);
+ d->proxyModel = dynamic_cast<DolphinSortFilterProxyModel*>(model);
if (d->proxyModel)
{
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()) &&
foreach (const QModelIndex &index, dirtyIndexes)
{
option.state = state;
- option.rect = d->visualRect(index);
+ option.rect = visualRect(index);
if (selectionModel() && selectionModel()->isSelected(index))
{
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));
}
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);
}
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)
{
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