Details-view: Fix column-width issue

The column-width must respect the minimum width of the
header-roles.
This commit is contained in:
Peter Penz 2011-10-08 22:46:37 +02:00
parent 0e8ba413f4
commit 8d44ebc148
3 changed files with 22 additions and 9 deletions

View file

@ -112,6 +112,12 @@ QHash<QByteArray, qreal> KItemListHeader::visibleRolesWidths() const
return m_visibleRolesWidths;
}
qreal KItemListHeader::minimumRoleWidth() const
{
QFontMetricsF fontMetrics(font());
return fontMetrics.height() * 4;
}
void KItemListHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
@ -340,10 +346,4 @@ bool KItemListHeader::isAboveRoleGrip(const QPointF& pos, int roleIndex) const
return pos.x() >= (x - grip) && pos.x() <= x;
}
qreal KItemListHeader::minimumRoleWidth() const
{
QFontMetricsF fontMetrics(font());
return fontMetrics.height() * 4;
}
#include "kitemlistheader_p.moc"

View file

@ -47,6 +47,8 @@ public:
void setVisibleRolesWidths(const QHash<QByteArray, qreal> rolesWidths);
QHash<QByteArray, qreal> visibleRolesWidths() const;
qreal minimumRoleWidth() const;
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
signals:
@ -77,7 +79,6 @@ private:
void updateHoveredRoleIndex(const QPointF& pos);
int roleIndexAt(const QPointF& pos) const;
bool isAboveRoleGrip(const QPointF& pos, int roleIndex) const;
qreal minimumRoleWidth() const;
private:
enum RoleOperation

View file

@ -1459,8 +1459,20 @@ void KItemListView::updateVisibleRolesSizes(const KItemRangeList& itemRanges)
}
if (itemCount == rangesItemCount) {
// The sizes of all roles need to be determined
m_visibleRolesSizes = visibleRolesSizes(itemRanges);
// Assure the the sizes are not smaller than the minimum defined by the header
// TODO: Currently only implemented for a top-aligned header
const qreal minHeaderRoleWidth = m_header->minimumRoleWidth();
QMutableHashIterator<QByteArray, QSizeF> it (m_visibleRolesSizes);
while (it.hasNext()) {
it.next();
const QSizeF& size = it.value();
if (size.width() < minHeaderRoleWidth) {
const QSizeF newSize(minHeaderRoleWidth, size.height());
m_visibleRolesSizes.insert(it.key(), newSize);
}
}
} else {
// Only a sub range of the roles need to be determined.
// The chances are good that the sizes of the sub ranges
@ -1483,7 +1495,7 @@ void KItemListView::updateVisibleRolesSizes(const KItemRangeList& itemRanges)
if (!updateRequired) {
// All the updated sizes are smaller than the current sizes and no change
// of the roles-widths is required
// of the stretched roles-widths is required
return;
}
}