Compact view: Padding- and margin-improvements for grouped alignments

This commit is contained in:
Peter Penz 2012-02-16 15:13:23 +01:00
parent 1a4ca3edb1
commit 613758b5ec
3 changed files with 60 additions and 32 deletions

View file

@ -131,15 +131,17 @@ void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsIt
updateCache();
}
if (m_itemIndex == 0) {
// No top- or left-line should be drawn for the first group-header
return;
}
painter->setPen(m_lineColor);
if (m_scrollOrientation == Qt::Horizontal) {
painter->setPen(m_lineColor);
const qreal x = m_roleBounds.x() - 2 * m_styleOption.padding;
painter->drawLine(x, 0, x, size().height() - 1);
} else if (m_itemIndex > 0) {
painter->setPen(m_lineColor);
const qreal y = m_roleBounds.y() - m_styleOption.padding;
painter->drawLine(0, y, size().width() - 1, y);
painter->drawLine(0, 0, 0, size().height() - 1);
} else {
painter->drawLine(0, 0, size().width() - 1, 0);
}
}
@ -202,22 +204,17 @@ void KItemListGroupHeader::updateCache()
m_lineColor = mixedColor(c1, c2, 10);
m_roleColor = mixedColor(c1, c2, 70);
int padding = m_styleOption.padding;
int horizontalMargin = 0;
if (m_scrollOrientation == Qt::Vertical) {
// The x-position of the group-header-widget will always be 0,
// Add a minimum margin.
horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
} else {
padding *= 2;
}
const int padding = qMax(1, m_styleOption.padding);
const int horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
const QFontMetrics fontMetrics(m_styleOption.font);
const qreal roleHeight = fontMetrics.height();
const int y = (m_scrollOrientation == Qt::Vertical) ? padding : horizontalMargin;
m_roleBounds = QRectF(horizontalMargin + padding,
size().height() - roleHeight - padding,
size().width() - 2 * (horizontalMargin + padding),
y,
size().width() - 2 * padding - horizontalMargin,
roleHeight);
m_dirtyCache = false;

View file

@ -1720,7 +1720,7 @@ void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget)
groupHeader->setPos(-widget->x(), -groupHeaderRect.height());
groupHeader->resize(size().width(), groupHeaderRect.size().height());
} else {
groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -groupHeaderRect.height());
groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
groupHeader->resize(groupHeaderRect.size());
}
}
@ -1976,15 +1976,21 @@ bool KItemListView::scrollBarRequired(const QSizeF& size) const
void KItemListView::updateGroupHeaderHeight()
{
const qreal groupHeaderHeight = m_styleOption.fontMetrics.height() + m_styleOption.padding * 2;
qreal groupHeaderHeight = m_styleOption.fontMetrics.height();
qreal groupHeaderMargin = 0;
if (scrollOrientation() == Qt::Horizontal) {
// The vertical margin above and below the header should be
// equal to the horizontal margin, not the vertical margin
// from m_styleOption.
groupHeaderHeight += 2 * m_styleOption.horizontalMargin;
groupHeaderMargin = m_styleOption.horizontalMargin;
} else if (m_itemSize.isEmpty()){
groupHeaderMargin = groupHeaderHeight / 2;
groupHeaderHeight += 2 * m_styleOption.padding;
groupHeaderMargin = m_styleOption.iconSize / 2;
} else {
groupHeaderMargin = m_styleOption.verticalMargin * 2;
groupHeaderHeight += 2 * m_styleOption.padding;
groupHeaderMargin = m_styleOption.iconSize / 4;
}
m_layouter->setGroupHeaderHeight(groupHeaderHeight);
m_layouter->setGroupHeaderMargin(groupHeaderMargin);

View file

@ -257,14 +257,36 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
return QRectF();
}
pos.ry() -= m_groupHeaderHeight;
QSizeF size;
if (m_scrollOrientation == Qt::Vertical) {
pos.rx() = 0;
pos.ry() -= m_groupHeaderHeight;
size = QSizeF(m_size.width(), m_groupHeaderHeight);
} else {
size = QSizeF(minimumGroupHeaderWidth(), m_groupHeaderHeight);
pos.rx() -= m_itemMargin.width();
pos.ry() = 0;
// Determine the maximum width used in the
// current column. As the scroll-direction is
// Qt::Horizontal and m_itemRects is accessed directly,
// the logical height represents the visual width.
qreal width = minimumGroupHeaderWidth();
const qreal y = m_itemRects[index].y();
const int maxIndex = m_itemRects.count() - 1;
while (index <= maxIndex) {
QRectF bounds = m_itemRects[index];
if (bounds.y() != y) {
break;
}
if (bounds.height() > width) {
width = bounds.height();
}
++index;
}
size = QSizeF(width, m_size.height());
}
return QRectF(pos, size);
}
@ -324,7 +346,7 @@ void KItemListViewLayouter::doLayout()
// 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_groupHeaderMargin + m_groupHeaderHeight;
size.rwidth() -= m_groupHeaderHeight;
}
}
@ -363,10 +385,10 @@ void KItemListViewLayouter::doLayout()
if (horizontalScrolling) {
// All group headers will always be aligned on the top and not
// flipped like the other properties
x += m_groupHeaderMargin + m_groupHeaderHeight;
x += m_groupHeaderHeight;
}
if (m_groupItemIndexes.contains(index) && !horizontalScrolling) {
if (m_groupItemIndexes.contains(index)) {
// The item is the first item of a group.
// Increase the y-position to provide space
// for the group header.
@ -378,7 +400,10 @@ void KItemListViewLayouter::doLayout()
// group already before
y += m_groupHeaderMargin;
}
y += m_groupHeaderHeight;
if (!horizontalScrolling) {
y += m_groupHeaderHeight;
}
}
}
@ -561,7 +586,7 @@ bool KItemListViewLayouter::createGroupHeaders()
qreal KItemListViewLayouter::minimumGroupHeaderWidth() const
{
return m_groupHeaderHeight * 15 / 2;
return 100;
}
#include "kitemlistviewlayouter_p.moc"