m_scrollOrientation(Qt::Vertical),
m_size(),
m_itemSize(128, 128),
+ m_itemMargin(),
m_headerHeight(0),
m_model(0),
m_sizeHintResolver(0),
return m_itemSize;
}
+void KItemListViewLayouter::setItemMargin(const QSizeF& margin)
+{
+ if (m_itemMargin != margin) {
+ m_itemMargin = margin;
+ m_dirty = true;
+ }
+}
+
+QSizeF KItemListViewLayouter::itemMargin() const
+{
+ return m_itemMargin;
+}
+
void KItemListViewLayouter::setHeaderHeight(qreal height)
{
if (m_headerHeight != height) {
m_visibleIndexesDirty = true;
QSizeF itemSize = m_itemSize;
+ QSizeF itemMargin = m_itemMargin;
QSizeF size = m_size;
+
+ const bool grouped = createGroupHeaders();
const bool horizontalScrolling = (m_scrollOrientation == Qt::Horizontal);
if (horizontalScrolling) {
+ // Flip everything so that the layout logically can work like having
+ // a vertical scrolling
itemSize.setWidth(m_itemSize.height());
itemSize.setHeight(m_itemSize.width());
+ itemMargin.setWidth(m_itemMargin.height());
+ itemMargin.setHeight(m_itemMargin.width());
size.setWidth(m_size.height());
size.setHeight(m_size.width());
+
+ if (grouped) {
+ // In the horizontal scrolling case all groups are aligned
+ // at the top, which decreases the available height. For the
+ // flipped data this means that the width must be decreased.
+ size.rwidth() -= m_groupHeaderHeight;
+ }
}
- m_columnWidth = itemSize.width();
- m_columnCount = qMax(1, int(size.width() / m_columnWidth));
- m_xPosInc = 0;
+ m_columnWidth = itemSize.width() + itemMargin.width();
+ const qreal widthForColumns = size.width() - itemMargin.width();
+ m_columnCount = qMax(1, int(widthForColumns / m_columnWidth));
+ m_xPosInc = itemMargin.width();
const int itemCount = m_model->count();
- if (itemCount > m_columnCount) {
+ if (itemCount > m_columnCount && m_columnWidth >= 32) {
// Apply the unused width equally to each column
const qreal unusedWidth = size.width() - m_columnCount * m_columnWidth;
if (unusedWidth > 0) {
m_itemRects.reserve(itemCount);
- qreal y = m_headerHeight;
+ qreal y = m_headerHeight + itemMargin.height();
int rowIndex = 0;
- const bool grouped = createGroupHeaders();
-
int index = 0;
while (index < itemCount) {
qreal x = m_xPosInc;
}
}
- y += maxItemHeight;
+ y += maxItemHeight + itemMargin.height();
++rowIndex;
}
if (m_itemRects.count() > itemCount) {
m_itemRects.erase(m_itemRects.begin() + itemCount,
- m_itemRects.end());
+ m_itemRects.end());
}
if (itemCount > 0) {