Elide the texts if the user shrinks the column-widths

This commit is contained in:
Peter Penz 2011-10-02 17:33:41 +02:00
parent 5b015f037c
commit af3c3a4328
3 changed files with 38 additions and 10 deletions

View file

@ -119,12 +119,29 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
painter->setPen(textColor());
painter->drawStaticText(m_textPos[Name], m_text[Name]);
bool clipAdditionalInfoBounds = false;
if (m_layout == DetailsLayout) {
// Prevent a possible overlapping of the additional-information texts
// with the icon. This can happen if the user has minimized the width
// of the name-column to a very small value.
const qreal minX = m_pixmapPos.x() + m_pixmap.width() + 4 * itemListStyleOption.margin;
if (m_textPos[Name + 1].x() < minX) {
clipAdditionalInfoBounds = true;
painter->save();
painter->setClipRect(minX, 0, size().width() - minX, size().height(), Qt::IntersectClip);
}
}
painter->setPen(m_additionalInfoTextColor);
painter->setFont(itemListStyleOption.font);
for (int i = Name + 1; i < TextIdCount; ++i) {
painter->drawStaticText(m_textPos[i], m_text[i]);
}
if (clipAdditionalInfoBounds) {
painter->restore();
}
#ifdef KFILEITEMLISTWIDGET_DEBUG
painter->setPen(Qt::red);
painter->setBrush(Qt::NoBrush);
@ -631,13 +648,23 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
foreach (const QByteArray& role, m_sortedVisibleRoles) {
const TextId textId = roleTextId(role);
const QString text = roleText(role, values);
m_text[textId].setText(text);
const qreal requiredWidth = option.fontMetrics.width(text);
m_textPos[textId] = QPointF(x + columnMargin, y);
QString text = roleText(role, values);
// Elide the text in case it does not fit into the available column-width
qreal requiredWidth = option.fontMetrics.width(text);
const qreal columnWidth = visibleRolesSizes().value(role, QSizeF(0, 0)).width();
qreal availableTextWidth = columnWidth - 2 * columnMargin;
if (textId == Name) {
availableTextWidth -= firstColumnInc;
}
if (requiredWidth > availableTextWidth) {
text = option.fontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
requiredWidth = option.fontMetrics.width(text);
}
m_text[textId].setText(text);
m_textPos[textId] = QPointF(x + columnMargin, y);
x += columnWidth;
switch (textId) {

View file

@ -337,7 +337,7 @@ bool KItemListHeader::isAboveRoleGrip(const QPointF& pos, int roleIndex) const
qreal KItemListHeader::minimumRoleWidth() const
{
QFontMetricsF fontMetrics(font());
return fontMetrics.averageCharWidth() * 5;
return fontMetrics.averageCharWidth() * 8;
}
#include "kitemlistheader_p.moc"

View file

@ -227,16 +227,17 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
m_sizeHintResolver->clearCache();
m_layouter->markAsDirty();
onVisibleRolesChanged(roles, previousRoles);
updateVisibleRolesSizes();
updateLayout();
if (m_header) {
m_header->setVisibleRoles(roles);
m_header->setVisibleRolesWidths(headerRolesWidths());
m_useHeaderWidths = false;
}
updateVisibleRolesSizes();
updateLayout();
onVisibleRolesChanged(roles, previousRoles);
}
QList<QByteArray> KItemListView::visibleRoles() const