layout code fixed

This commit is contained in:
Uwe Rathmann 2018-01-05 09:36:55 +01:00
parent 277d8dd8d6
commit 2df8d81174

View File

@ -42,6 +42,28 @@ namespace
#endif #endif
} }
inline void setGeometry( const QRectF& rect )
{
auto d = QQuickTextPrivate::get( this );
d->heightValid = true;
d->widthValid = true;
if ( ( d->x != rect.x() ) || ( d->y != rect.y() ) )
{
d->x = rect.x();
d->y = rect.y();
d->dirty( QQuickItemPrivate::Position );
}
if ( ( d->width != rect.width() ) || ( d->height != rect.height() ) )
{
d->height = rect.height();
d->width = rect.width();
d->dirty( QQuickItemPrivate::Size );
}
}
inline void setAlignment( Qt::Alignment alignment ) inline void setAlignment( Qt::Alignment alignment )
{ {
setHAlign( ( QQuickText::HAlignment ) ( int( alignment ) & 0x0f ) ); setHAlign( ( QQuickText::HAlignment ) ( int( alignment ) & 0x0f ) );
@ -57,8 +79,16 @@ namespace
setWrapMode( static_cast< QQuickText::WrapMode >( options.wrapMode() ) ); setWrapMode( static_cast< QQuickText::WrapMode >( options.wrapMode() ) );
} }
void begin() { classBegin(); } void begin()
void end() { componentComplete(); } {
classBegin();
QQuickTextPrivate::get( this )->updateOnComponentComplete = true;
}
void end()
{
componentComplete();
}
QRectF layedOutTextRect() const QRectF layedOutTextRect() const
{ {
@ -71,7 +101,7 @@ namespace
QQuickItemPrivate::get( this )->refWindow( window ); QQuickItemPrivate::get( this )->refWindow( window );
while ( parentNode->firstChild() ) while ( parentNode->firstChild() )
delete parentNode->firstChild(); delete parentNode->firstChild();
auto node = QQuickText::updatePaintNode( nullptr, nullptr ); auto node = QQuickText::updatePaintNode( nullptr, nullptr );
node->reparentChildNodesTo( parentNode ); node->reparentChildNodesTo( parentNode );
@ -144,34 +174,20 @@ void QskRichTextRenderer::updateNode( const QString& text,
const QQuickItem* item, QSGTransformNode* node ) const QQuickItem* item, QSGTransformNode* node )
{ {
// are we killing internal caches of QQuickText, when always using // are we killing internal caches of QQuickText, when always using
// the same item for the creation the text nodes. TODO ... // the same item for the creation the text nodes. TODO ...
auto& textItem = *qskRenderHelper; auto& textItem = *qskRenderHelper;
textItem.begin(); textItem.begin();
textItem.setGeometry( rect );
textItem.setBottomPadding( 0 ); textItem.setBottomPadding( 0 );
textItem.setTopPadding( 0 ); textItem.setTopPadding( 0 );
textItem.setFont( font ); textItem.setFont( font );
textItem.setOptions( options ); textItem.setOptions( options );
textItem.setAlignment( alignment ); textItem.setAlignment( alignment );
#if 0
// the position of textItem seems to have no effect
// on the position of the node. We do it by translation later.
textItem.setX( rect.x() );
textItem.setY( rect.y() );
#endif
if ( rect.width() != item->width() ||
rect.height() != item->height() )
{
textItem.setWidth( rect.width() );
textItem.setHeight( rect.height() );
textItem.doLayout();
}
textItem.setColor( colors.textColor ); textItem.setColor( colors.textColor );
textItem.setStyle( static_cast< QQuickText::TextStyle >( style ) ); textItem.setStyle( static_cast< QQuickText::TextStyle >( style ) );
textItem.setStyleColor( colors.styleColor ); textItem.setStyleColor( colors.styleColor );
@ -187,7 +203,7 @@ void QskRichTextRenderer::updateNode( const QString& text,
We need to have a stable algo for rounding the text base line, We need to have a stable algo for rounding the text base line,
so that texts don't start wobbling, when processing transitions so that texts don't start wobbling, when processing transitions
between margins/paddings. We manipulate the layout code between margins/paddings. We manipulate the layout code
by adding some padding, so that the position of base line by adding some padding, so that the position of base line
gets always floored. gets always floored.
*/ */
auto d = QQuickTextPrivate::get( &textItem ); auto d = QQuickTextPrivate::get( &textItem );
@ -196,7 +212,7 @@ void QskRichTextRenderer::updateNode( const QString& text,
if ( static_cast< int >( rect.height() - h ) % 2 ) if ( static_cast< int >( rect.height() - h ) % 2 )
{ {
if ( static_cast<int>( h ) % 2 ) if ( static_cast< int >( h ) % 2 )
d->extra.value().bottomPadding = 1; d->extra.value().bottomPadding = 1;
else else
d->extra.value().topPadding = 1; d->extra.value().topPadding = 1;