Commit 5099b615 authored by Andrey Yashkin's avatar Andrey Yashkin Committed by Albert Astals Cid

Fix an incorrect text bounding rectangle calculation inside the sidebar

Summary:
Now //fontBoundaries// always has smaller width than //boundingRect// from
```
void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, QRect *boundingRect = nullptr)
```
which is required to enclose the whole text. The difference is only several pixels, but sometimes it can cause visual problems. You can see the sidebar without and with this patch in Russian language with Noto Sans 10pt font on a picture below.
{F7177644}
Now the first and the last symbols are fully visible.

Reviewers: #okular

Subscribers: okular-devel

Tags: #okular

Differential Revision: https://phabricator.kde.org/D23012
parent 7e2e5a4a
......@@ -189,7 +189,7 @@ void SidebarDelegate::paint( QPainter *painter, const QStyleOptionViewItem &opti
if ( m_showText )
{
QString text = index.data( Qt::DisplayRole ).toString();
QRect fontBoundaries = QFontMetrics( option.font ).boundingRect( text );
QRect fontBoundaries = QFontMetrics( option.font ).boundingRect( QRect(), Qt::AlignCenter, text );
QPoint textPos(
ITEM_MARGIN_LEFT + ( option.rect.width() - ITEM_MARGIN_LEFT - ITEM_MARGIN_RIGHT - fontBoundaries.width() ) / 2,
ITEM_MARGIN_TOP + option.decorationSize.height() + ITEM_PADDING
......@@ -207,7 +207,7 @@ QSize SidebarDelegate::sizeHint( const QStyleOptionViewItem &option, const QMode
QSize baseSize( option.decorationSize.width(), option.decorationSize.height() );
if ( m_showText )
{
QRect fontBoundaries = QFontMetrics( option.font ).boundingRect( index.data( Qt::DisplayRole ).toString() );
QRect fontBoundaries = QFontMetrics( option.font ).boundingRect( QRect(), Qt::AlignCenter, index.data( Qt::DisplayRole ).toString() );
baseSize.setWidth( qMax( fontBoundaries.width(), baseSize.width() ) );
baseSize.setHeight( baseSize.height() + fontBoundaries.height() + ITEM_PADDING );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment