avoid layout issues when creating a QTextLayout with eliding and wrapping
This commit is contained in:
parent
943e2b6de8
commit
37fb088111
@ -46,58 +46,50 @@ QRectF QskPlainTextRenderer::textRect(
|
|||||||
static qreal qskLayoutText( QTextLayout* layout,
|
static qreal qskLayoutText( QTextLayout* layout,
|
||||||
qreal lineWidth, const QskTextOptions& options )
|
qreal lineWidth, const QskTextOptions& options )
|
||||||
{
|
{
|
||||||
auto maxLineCount = options.maximumLineCount();
|
if ( layout->text().isEmpty() )
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
const auto elideMode = options.effectiveElideMode();
|
|
||||||
if ( elideMode != Qt::ElideNone )
|
|
||||||
{
|
|
||||||
// What about strings with newlines and elide mode
|
|
||||||
maxLineCount = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int lineNumber = 0;
|
|
||||||
int characterPosition = 0;
|
|
||||||
qreal y = 0;
|
qreal y = 0;
|
||||||
|
|
||||||
Q_FOREVER
|
const auto elideMode = options.effectiveElideMode();
|
||||||
|
|
||||||
|
if ( elideMode == Qt::ElideNone )
|
||||||
{
|
{
|
||||||
if ( ++lineNumber > maxLineCount )
|
for ( int i = 0; i < options.maximumLineCount(); i++ )
|
||||||
break;
|
|
||||||
|
|
||||||
if ( lineNumber == maxLineCount )
|
|
||||||
{
|
{
|
||||||
const auto engine = layout->engine();
|
auto line = layout->createLine();
|
||||||
|
if ( !line.isValid() )
|
||||||
|
break;
|
||||||
|
|
||||||
const auto textLength = engine->text.length();
|
line.setPosition( QPointF( 0, y ) );
|
||||||
if ( elideMode != Qt::ElideNone && textLength > characterPosition )
|
line.setLineWidth( lineWidth );
|
||||||
{
|
|
||||||
if ( lineNumber == 1 || elideMode == Qt::ElideRight )
|
|
||||||
{
|
|
||||||
auto option = layout->textOption();
|
|
||||||
option.setWrapMode( QTextOption::WrapAnywhere );
|
|
||||||
layout->setTextOption( option );
|
|
||||||
|
|
||||||
auto elidedText = engine->elidedText(
|
y += line.leading() + line.height();
|
||||||
elideMode, QFixed::fromReal( lineWidth ),
|
|
||||||
Qt::TextShowMnemonic, characterPosition );
|
|
||||||
|
|
||||||
elidedText = elidedText.leftJustified( textLength - characterPosition );
|
|
||||||
|
|
||||||
engine->text.replace( characterPosition, elidedText.length(), elidedText );
|
|
||||||
Q_ASSERT( engine->text.length() == textLength );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto engine = layout->engine();
|
||||||
|
|
||||||
|
auto text = engine->elidedText(
|
||||||
|
elideMode, QFixed::fromReal( lineWidth ),
|
||||||
|
Qt::TextShowMnemonic, 0 );
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// why do we need this padding ???
|
||||||
|
text = text.leftJustified( engine->text.length() );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
engine->text = text;
|
||||||
|
|
||||||
auto line = layout->createLine();
|
auto line = layout->createLine();
|
||||||
if ( !line.isValid() )
|
if ( line.isValid() )
|
||||||
break;
|
{
|
||||||
|
line.setPosition( QPointF( 0, y ) );
|
||||||
|
line.setLineWidth( lineWidth );
|
||||||
|
|
||||||
line.setPosition( QPointF( 0, y ) );
|
y += line.leading() + line.height();
|
||||||
line.setLineWidth( lineWidth );
|
}
|
||||||
characterPosition = line.textStart() + line.textLength();
|
|
||||||
|
|
||||||
y += line.leading() + line.height();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user