┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemlistwidget.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-10-02 17:33:41 +0200
committerPeter Penz <[email protected]>2011-10-02 17:34:18 +0200
commitaf3c3a43281db7d7b6a3045c94836a746b031f51 (patch)
tree2b2f9153ddd2cdf80d2d056d48bd265f3b873557 /src/kitemviews/kfileitemlistwidget.cpp
parent5b015f037c934563ae316b76d2c84cfb1b912f94 (diff)
Elide the texts if the user shrinks the column-widths
Diffstat (limited to 'src/kitemviews/kfileitemlistwidget.cpp')
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 7cf1b4df1..3d4728521 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -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) {