Review Request 119546: Fix wrong text eliding in some corner cases.

Frank Reininghaus frank78ac at googlemail.com
Thu Jul 31 19:19:02 BST 2014


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/119546/#review63590
-----------------------------------------------------------

Ship it!


Thanks for analyzing this strange bug! As discussed in the bug report already (btw, there is a typo in the number, it's actually 337104), this is probably the best way to fix the problem.

One small idea for a possible change: one could also solve this like this:

            if (textLength < nameText.length()) {
                // Elide the last line of the text
                qreal elidingWidth = maxWidth;
                qreal lastLineWidth;
                do {
                    QString lastTextLine = nameText.mid(line.textStart());
                    lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
                                                                      Qt::ElideRight,
                                                                      elidingWidth);
                    const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
                    nameTextInfo->staticText.setText(elidedText);

                    lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();

                    // We do the text eliding in a loop with decreasing width (1 px / iteration)
                    // to avoid problems related to different width calculation code paths
                    // within Qt. (see bug 337104)
                    elidingWidth -= 1.0;
                } while (lastLineWidth > maxWidth);

                nameWidth = qMax(nameWidth, lastLineWidth);
            }
            
right? The advantage is that we don't modiy nameWidth twice inside the loop, which I found a bit confusing at first sight. However, the number of code lines is slightly larger. I guess it's mostly a matter of taste - just use the solution that you prefer. Thanks!

- Frank Reininghaus


On July 30, 2014, 6:54 p.m., Emmanuel Pescosta wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/119546/
> -----------------------------------------------------------
> 
> (Updated July 30, 2014, 6:54 p.m.)
> 
> 
> Review request for Dolphin.
> 
> 
> Bugs: 437104
>     http://bugs.kde.org/show_bug.cgi?id=437104
> 
> 
> Repository: kde-baseapps
> 
> 
> Description
> -------
> 
> The problem is in KStandardItemListWidget::updateIconsLayoutTextCache().
> 
> m_customizedFontMetrics.elidedText(lastTextLine, Qt::ElideRight, maxWidth) returns a non-elided text (which is wrong in thi case) and the resulting nameWidth is bigger than maxWidth. When I replace maxWidth by "maxWidth - 1" the eliding is correct and it works fine. 
> 
> I have solved it with a loop, which decreases the eliding width as long as the bounding rect width is bigger than the allowed maximum width.
> 
> 
> Diffs
> -----
> 
>   dolphin/src/kitemviews/kstandarditemlistwidget.cpp 998acc0 
> 
> Diff: https://git.reviewboard.kde.org/r/119546/diff/
> 
> 
> Testing
> -------
> 
> No wrong text eliding anymore :)
> 
> 
> Thanks,
> 
> Emmanuel Pescosta
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20140731/b8d2f688/attachment.htm>


More information about the kfm-devel mailing list