QRect retRect;
- if (listView->layoutDirection() == Qt::LeftToRight)
+ if (listView->flow() == QListView::LeftToRight)
{
- retRect = QRect(listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ if (listView->layoutDirection() == Qt::LeftToRight)
+ {
+ retRect = QRect(listView->spacing(), listView->spacing() * 2 +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
+ }
+ else
+ {
+ retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
+ }
}
else
{
- retRect = QRect(listView->viewport()->width() - listView->spacing(), listView->spacing() * 2 +
- categoryDrawer->categoryHeight(listView->viewOptions()), 0, 0);
+ retRect = QRect(listView->spacing(), listView->spacing() * 2 +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()), 0, 0);
}
int viewportWidth = listView->viewport()->width() - listView->spacing();
int itemHeight;
int itemWidth;
- if (listView->gridSize().isEmpty())
+ if (listView->gridSize().isEmpty() && (listView->flow() == QListView::LeftToRight))
{
itemHeight = biggestItemSize.height();
itemWidth = biggestItemSize.width();
}
- else
+ else if (listView->flow() == QListView::LeftToRight)
{
itemHeight = listView->gridSize().height();
itemWidth = listView->gridSize().width();
}
+ else if (listView->gridSize().isEmpty() && (listView->flow() == QListView::TopToBottom))
+ {
+ itemHeight = biggestItemSize.height();
+ itemWidth = listView->viewport()->width() - listView->spacing() * 2;
+ }
+ else
+ {
+ itemHeight = listView->gridSize().height();
+ itemWidth = listView->gridSize().width() - listView->spacing() * 2;
+ }
int itemWidthPlusSeparation = listView->spacing() + itemWidth;
+ if (!itemWidthPlusSeparation)
+ itemWidthPlusSeparation++;
int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
if (!elementsPerRow)
elementsPerRow++;
- int column = elementsInfo[index.row()].relativeOffsetToCategory % elementsPerRow;
- int row = elementsInfo[index.row()].relativeOffsetToCategory / elementsPerRow;
+ int column;
+ int row;
- if (listView->layoutDirection() == Qt::LeftToRight)
+ if (listView->flow() == QListView::LeftToRight)
{
- retRect.setLeft(retRect.left() + column * listView->spacing() +
- column * itemWidth);
+ column = elementsInfo[index.row()].relativeOffsetToCategory % elementsPerRow;
+ row = elementsInfo[index.row()].relativeOffsetToCategory / elementsPerRow;
+
+ if (listView->layoutDirection() == Qt::LeftToRight)
+ {
+ retRect.setLeft(retRect.left() + column * listView->spacing() +
+ column * itemWidth);
+ }
+ else
+ {
+ retRect.setLeft(retRect.right() - column * listView->spacing() -
+ column * itemWidth - itemWidth);
+
+ retRect.setRight(retRect.right() - column * listView->spacing() -
+ column * itemWidth);
+ }
}
else
{
- retRect.setLeft(retRect.right() - column * listView->spacing() -
- column * itemWidth - itemWidth);
-
- retRect.setRight(retRect.right() - column * listView->spacing() -
- column * itemWidth);
+ elementsPerRow = 1;
+ column = elementsInfo[index.row()].relativeOffsetToCategory % elementsPerRow;
+ row = elementsInfo[index.row()].relativeOffsetToCategory / elementsPerRow;
}
foreach (const QString &category, categories)
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
return retRect;
}
-QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &category)
- const
+QRect KCategorizedView::Private::visualCategoryRectInViewport(const QString &category) const
{
QRect retRect(listView->spacing(),
listView->spacing(),
if (!elementsPerRow)
elementsPerRow++;
+ if (listView->flow() == QListView::TopToBottom)
+ {
+ elementsPerRow = 1;
+ }
+
foreach (const QString &itCategory, categories)
{
if (itCategory == category)
retRect.setTop(retRect.top() +
(rowsInt * itemHeight) +
- categoryDrawer->categoryHeight(listView->viewOptions()) +
+ categoryDrawer->categoryHeight(index, listView->viewOptions()) +
listView->spacing() * 2);
if (listView->gridSize().isEmpty())
}
}
- retRect.setHeight(categoryDrawer->categoryHeight(listView->viewOptions()));
+ retRect.setHeight(categoryDrawer->categoryHeight(index, listView->viewOptions()));
return retRect;
}
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);
void KCategorizedView::Private::layoutChanged(bool forceItemReload)
{
- if ((listView->viewMode() == KCategorizedView::IconMode) && proxyModel &&
- categoryDrawer && proxyModel->isCategorizedModel() &&
+ if (proxyModel && categoryDrawer && proxyModel->isCategorizedModel() &&
((forceItemReload ||
(modelSortRole != proxyModel->sortRole()) ||
(modelSortColumn != proxyModel->sortColumn()) ||
modelCategorized = proxyModel->isCategorizedModel();
}
}
- else if ((listView->viewMode() == KCategorizedView::IconMode) && proxyModel &&
- categoryDrawer && proxyModel->isCategorizedModel())
+ else if (proxyModel && categoryDrawer && proxyModel->isCategorizedModel())
{
updateScrollbars();
}
: QListView(parent)
, d(new Private(this))
{
+ setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+ setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
}
KCategorizedView::~KCategorizedView()
QRect KCategorizedView::visualRect(const QModelIndex &index) const
{
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return QListView::visualRect(index);
}
QModelIndex KCategorizedView::indexAt(const QPoint &point) const
{
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return QListView::indexAt(point);
}
void KCategorizedView::paintEvent(QPaintEvent *event)
{
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
QListView::paintEvent(event);
return;
d->categoriesPosition.clear();
d->forcedSelectionPosition = 0;
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return;
}
void KCategorizedView::setSelection(const QRect &rect,
QItemSelectionModel::SelectionFlags flags)
{
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
QListView::setSelection(rect, flags);
return;
}
int itemWidthPlusSeparation = spacing() + itemWidth;
+ if (!itemWidthPlusSeparation)
+ itemWidthPlusSeparation++;
int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
if (!elementsPerRow)
elementsPerRow++;
{
QListView::mouseMoveEvent(event);
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return;
}
QListView::mouseReleaseEvent(event);
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return;
}
{
if (d->categoryVisualRect(category).contains(event->pos()))
{
- QItemSelection selection;
+ QItemSelection selection = selectionModel()->selection();
QModelIndexList indexList = d->categoriesIndexes[category];
foreach (const QModelIndex &index, indexList)
selection << QItemSelectionRange(selectIndex);
}
- selectionModel()->select(selection, QItemSelectionModel::Select);
+ selectionModel()->select(selection, QItemSelectionModel::SelectCurrent);
break;
}
QListView::dragMoveEvent(event);
#endif
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
return;
}
Qt::KeyboardModifiers modifiers)
{
if ((viewMode() != KCategorizedView::IconMode) ||
- !d->proxyModel ||
- !d->categoryDrawer ||
- d->categories.isEmpty() ||
- !d->proxyModel->isCategorizedModel()
- )
+ !d->proxyModel ||
+ !d->categoryDrawer ||
+ d->categories.isEmpty() ||
+ !d->proxyModel->isCategorizedModel())
{
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;
}
int itemWidthPlusSeparation = spacing() + itemWidth;
+ if (!itemWidthPlusSeparation)
+ itemWidthPlusSeparation++;
int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
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();
{
QListView::rowsInserted(parent, start, end);
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
d->forcedSelectionPosition = 0;
d->elementsInfo.clear();
int start,
int end)
{
- if ((viewMode() == KCategorizedView::IconMode) && d->proxyModel &&
- d->categoryDrawer && d->proxyModel->isCategorizedModel())
+ if (d->proxyModel && d->categoryDrawer && d->proxyModel->isCategorizedModel())
{
// Force the view to update all elements
rowsInsertedArtifficial(QModelIndex(), 0, d->proxyModel->rowCount() - 1);
void KCategorizedView::updateGeometries()
{
- if ((viewMode() != KCategorizedView::IconMode) || !d->proxyModel ||
- !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
+ if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
QListView::updateGeometries();
return;
}
int itemWidthPlusSeparation = spacing() + itemWidth;
+ if (!itemWidthPlusSeparation)
+ itemWidthPlusSeparation++;
int elementsPerRow = viewportWidth / itemWidthPlusSeparation;
if (!elementsPerRow)
elementsPerRow++;