]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix filename trucation issues in Icons View with maximum number of lines
authorFrank Reininghaus <frank78ac@googlemail.com>
Sun, 25 Aug 2013 14:24:20 +0000 (16:24 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 25 Aug 2013 14:27:36 +0000 (16:27 +0200)
When the name of a file is too long to be shown inside the maximum
number of lines, the last line is elided. However, there were several
problems before this commit:

(a) "lastTextLine", which contains the text to be elided, was not
    assigned the complete remaining text, but only the part that would
    be put into the last line if there were more lines following. This
    may be less than what would fit into the line because we try to not
    break the text at random points.

(b) QFontMetrics::elidedText() was not given the width that is available
    for the last line (that would be maxWidth), but only the width that
    would be occupied by the text if there were more lines following
    (line.naturalTextWidth()).

(c) The variable "nameWidth", which is required to calculate the QRectF
    that is reserved for the name, was not updated correctly.

The result is that the text was sometimes trucated too early (especially
if there would be a line break early in the text if we had more lines
available), that there may be insufficient space to show the "...", and
that the hover/selection rectangle might be too narrow.

BUG: 304558
BUG: 321882
FIXED-IN: 4.11.1
REVIEW: 112265

src/kitemviews/kstandarditemlistwidget.cpp

index 483517ecc6f08de7f44eda242cc7fc77233d212b..bc0503663bceb1dfdb1065731bbaf6110838c084 100644 (file)
@@ -1030,12 +1030,15 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
             const int textLength = line.textStart() + line.textLength();
             if (textLength < nameText.length()) {
                 // Elide the last line of the text
-                QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
+                QString lastTextLine = nameText.mid(line.textStart());
                 lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
                                                                   Qt::ElideRight,
-                                                                  line.naturalTextWidth() - 1);
+                                                                  maxWidth);
                 const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
                 nameTextInfo->staticText.setText(elidedText);
+
+                const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+                nameWidth = qMax(nameWidth, lastLineWidth);
             }
             break;
         }