[calamares] Fit text into sidepane
- Shrink the font in an attempt to fit into the box, but only up to 4pt smaller; after that just clip on one line.
This commit is contained in:
parent
0f30acc13f
commit
dc8cfd2fce
@ -109,6 +109,32 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
|
||||
painter->setBrush( QColor( textHighlight ) );
|
||||
}
|
||||
|
||||
|
||||
// Draw the text at least once. If it doesn't fit, then shrink the font
|
||||
// being used by 1 pt on each iteration, up to a maximum of maximumShrink
|
||||
// times. On each loop, we'll have to blank out the rectangle again, so this
|
||||
// is an expensive (in terms of drawing operations) thing to do.
|
||||
//
|
||||
// (The loop uses <= because the counter is incremented at the start).
|
||||
static constexpr int const maximumShrink = 4;
|
||||
int shrinkSteps = 0;
|
||||
do
|
||||
{
|
||||
painter->fillRect( option.rect, painter->brush().color() );
|
||||
painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString() );
|
||||
shrinkSteps++;
|
||||
|
||||
QRectF boundingBox;
|
||||
painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox );
|
||||
|
||||
// The extra check here is to avoid the changing-font-size if we're not going to use
|
||||
// it in the next iteration of the loop anyway.
|
||||
if ( ( shrinkSteps <= maximumShrink ) && (boundingBox.width() > textRect.width() ) )
|
||||
{
|
||||
font.setPointSize( item_fontsize() - shrinkSteps );
|
||||
painter->setFont( font );
|
||||
}
|
||||
else
|
||||
break; // It fits
|
||||
}
|
||||
while ( shrinkSteps <= maximumShrink );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user