handling of '\n' in texts fixed
This commit is contained in:
parent
270c94f89f
commit
9ea7409f68
|
@ -82,7 +82,7 @@ int QskTextOptions::textFlags() const
|
||||||
{
|
{
|
||||||
case QskTextOptions::NoWrap:
|
case QskTextOptions::NoWrap:
|
||||||
{
|
{
|
||||||
flags |= Qt::TextSingleLine;
|
// flags |= Qt::TextSingleLine;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QskTextOptions::WordWrap:
|
case QskTextOptions::WordWrap:
|
||||||
|
|
|
@ -210,14 +210,15 @@ QFont QskTextLabel::font() const
|
||||||
|
|
||||||
QSizeF QskTextLabel::contentsSizeHint() const
|
QSizeF QskTextLabel::contentsSizeHint() const
|
||||||
{
|
{
|
||||||
|
const auto font = effectiveFont( Text );
|
||||||
|
|
||||||
if ( !m_data->text.isEmpty() )
|
if ( !m_data->text.isEmpty() )
|
||||||
{
|
{
|
||||||
const auto font = effectiveFont( Text );
|
|
||||||
return QskTextRenderer::textSize(
|
return QskTextRenderer::textSize(
|
||||||
m_data->text, font, m_data->effectiveOptions() );
|
m_data->text, font, m_data->effectiveOptions() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSizeF( 0, 0 );
|
return QSizeF( 0, QFontMetricsF( font ).height() );
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QskTextLabel::heightForWidth( qreal width ) const
|
qreal QskTextLabel::heightForWidth( qreal width ) const
|
||||||
|
@ -225,12 +226,25 @@ qreal QskTextLabel::heightForWidth( qreal width ) const
|
||||||
const auto font = effectiveFont( Text );
|
const auto font = effectiveFont( Text );
|
||||||
const qreal lineHeight = QFontMetricsF( font ).height();
|
const qreal lineHeight = QFontMetricsF( font ).height();
|
||||||
|
|
||||||
if ( m_data->text.isEmpty() ||
|
qreal h = 0;
|
||||||
( m_data->textOptions.wrapMode() == QskTextOptions::NoWrap ) )
|
|
||||||
{
|
|
||||||
return lineHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const auto m = margins();
|
||||||
|
|
||||||
|
if ( m_data->text.isEmpty() )
|
||||||
|
{
|
||||||
|
h = lineHeight;
|
||||||
|
}
|
||||||
|
else if ( m_data->textOptions.effectiveElideMode() != Qt::ElideNone )
|
||||||
|
{
|
||||||
|
h = lineHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
In case of QskTextOptions::NoWrap we could count
|
||||||
|
the line numbers and calculate the height from
|
||||||
|
lineHeight. TODO ...
|
||||||
|
*/
|
||||||
qreal maxHeight = std::numeric_limits< qreal >::max();
|
qreal maxHeight = std::numeric_limits< qreal >::max();
|
||||||
if ( maxHeight / lineHeight > m_data->textOptions.maximumLineCount() )
|
if ( maxHeight / lineHeight > m_data->textOptions.maximumLineCount() )
|
||||||
{
|
{
|
||||||
|
@ -238,17 +252,23 @@ qreal QskTextLabel::heightForWidth( qreal width ) const
|
||||||
maxHeight = m_data->textOptions.maximumLineCount() * lineHeight;
|
maxHeight = m_data->textOptions.maximumLineCount() * lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF size( width, maxHeight );
|
qreal w = width - m.left() + m.right();
|
||||||
|
|
||||||
|
QSizeF size( w, maxHeight );
|
||||||
size = QskTextRenderer::textSize(
|
size = QskTextRenderer::textSize(
|
||||||
m_data->text, font, m_data->effectiveOptions(), size );
|
m_data->text, font, m_data->effectiveOptions(), size );
|
||||||
|
|
||||||
return qCeil( size.height() );
|
h = size.height();
|
||||||
|
}
|
||||||
|
|
||||||
|
h += m.top() + m.bottom();
|
||||||
|
|
||||||
|
return qCeil( h );
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QskTextLabel::widthForHeight( qreal height ) const
|
qreal QskTextLabel::widthForHeight( qreal height ) const
|
||||||
{
|
{
|
||||||
if ( m_data->text.isEmpty() ||
|
if ( m_data->text.isEmpty() )
|
||||||
( m_data->textOptions.wrapMode() == QskTextOptions::NoWrap ) )
|
|
||||||
{
|
{
|
||||||
return Inherited::widthForHeight( height );
|
return Inherited::widthForHeight( height );
|
||||||
}
|
}
|
||||||
|
@ -256,11 +276,13 @@ qreal QskTextLabel::widthForHeight( qreal height ) const
|
||||||
const auto font = effectiveFont( Text );
|
const auto font = effectiveFont( Text );
|
||||||
const qreal maxWidth = std::numeric_limits< qreal >::max();
|
const qreal maxWidth = std::numeric_limits< qreal >::max();
|
||||||
|
|
||||||
QSizeF size( maxWidth, height );
|
const auto m = margins();
|
||||||
|
|
||||||
|
QSizeF size( maxWidth, height - m.top() + m.bottom() );
|
||||||
size = QskTextRenderer::textSize( m_data->text, font,
|
size = QskTextRenderer::textSize( m_data->text, font,
|
||||||
m_data->effectiveOptions(), size );
|
m_data->effectiveOptions(), size );
|
||||||
|
|
||||||
return qCeil( size.width() );
|
return qCeil( size.width() + m.left() + m.right() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskTextLabel::changeEvent( QEvent* event )
|
void QskTextLabel::changeEvent( QEvent* event )
|
||||||
|
|
|
@ -29,7 +29,7 @@ QSK_QT_PRIVATE_END
|
||||||
QSizeF QskPlainTextRenderer::textSize(
|
QSizeF QskPlainTextRenderer::textSize(
|
||||||
const QString& text, const QFont& font, const QskTextOptions& options )
|
const QString& text, const QFont& font, const QskTextOptions& options )
|
||||||
{
|
{
|
||||||
// result differs from QskTextRenderer::implicitSizeHint ???
|
// result differs from QQuickText::implicitSizeHint ???
|
||||||
return textRect( text, font, options, QSizeF( 10e6, 10e6 ) ).size();
|
return textRect( text, font, options, QSizeF( 10e6, 10e6 ) ).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,14 @@ QRectF QskPlainTextRenderer::textRect(
|
||||||
static qreal qskLayoutText( QTextLayout* layout,
|
static qreal qskLayoutText( QTextLayout* layout,
|
||||||
qreal lineWidth, const QskTextOptions& options )
|
qreal lineWidth, const QskTextOptions& options )
|
||||||
{
|
{
|
||||||
const auto maxLineCount = ( options.wrapMode() == QskTextOptions::NoWrap )
|
auto maxLineCount = options.maximumLineCount();
|
||||||
? 1 : options.maximumLineCount();
|
|
||||||
|
const auto elideMode = options.effectiveElideMode();
|
||||||
|
if ( elideMode != Qt::ElideNone )
|
||||||
|
{
|
||||||
|
// What about strings with newlines and elide mode
|
||||||
|
maxLineCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
int characterPosition = 0;
|
int characterPosition = 0;
|
||||||
|
@ -60,7 +66,6 @@ static qreal qskLayoutText( QTextLayout* layout,
|
||||||
|
|
||||||
if ( lineNumber == maxLineCount )
|
if ( lineNumber == maxLineCount )
|
||||||
{
|
{
|
||||||
const auto elideMode = options.elideMode();
|
|
||||||
const auto engine = layout->engine();
|
const auto engine = layout->engine();
|
||||||
|
|
||||||
const auto textLength = engine->text.length();
|
const auto textLength = engine->text.length();
|
||||||
|
@ -172,10 +177,29 @@ void QskPlainTextRenderer::updateNode( const QString& text,
|
||||||
QTextOption textOption( alignment );
|
QTextOption textOption( alignment );
|
||||||
textOption.setWrapMode( static_cast< QTextOption::WrapMode >( options.wrapMode() ) );
|
textOption.setWrapMode( static_cast< QTextOption::WrapMode >( options.wrapMode() ) );
|
||||||
|
|
||||||
|
QString tmp = text;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
const int pos = tmp.indexOf( QLatin1Char( '\x9c' ) );
|
||||||
|
if ( pos != -1 )
|
||||||
|
{
|
||||||
|
// ST: string termination
|
||||||
|
|
||||||
|
tmp = tmp.mid( 0, pos );
|
||||||
|
tmp.replace( QLatin1Char( '\n' ), QChar::LineSeparator );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if ( tmp.contains( QLatin1Char( '\n' ) ) )
|
||||||
|
{
|
||||||
|
tmp.replace( QLatin1Char('\n'), QChar::LineSeparator );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTextLayout layout;
|
QTextLayout layout;
|
||||||
layout.setFont( font );
|
layout.setFont( font );
|
||||||
layout.setTextOption( textOption );
|
layout.setTextOption( textOption );
|
||||||
layout.setText( text );
|
layout.setText( tmp );
|
||||||
|
|
||||||
layout.beginLayout();
|
layout.beginLayout();
|
||||||
const qreal textHeight = qskLayoutText( &layout, rect.width(), options );
|
const qreal textHeight = qskLayoutText( &layout, rect.width(), options );
|
||||||
|
|
Loading…
Reference in New Issue