bool Converter::convertHeader( QTextCursor *cursor, const QDomElement &element ) { const QString styleName = element.attribute( QStringLiteral("style-name") ); const StyleFormatProperty property = mStyleInformation->styleProperty( styleName ); QTextBlockFormat blockFormat; QTextCharFormat textFormat; property.applyBlock( &blockFormat ); property.applyText( &textFormat ); cursor->setBlockFormat( blockFormat ); QDomNode child = element.firstChild(); while ( !child.isNull() ) { if ( child.isElement() ) { const QDomElement childElement = child.toElement(); if ( childElement.tagName() == QLatin1String( "span" ) ) { if ( !convertSpan( cursor, childElement, textFormat ) ) return false; } } else if ( child.isText() ) { const QDomText childText = child.toText(); if ( !convertTextNode( cursor, childText, textFormat ) ) return false; } child = child.nextSibling(); } emit addTitle( element.attribute( QStringLiteral("outline-level"), QStringLiteral("0") ).toInt(), element.text(), cursor->block() ); return true; }
bool Converter::convertParagraph( QTextCursor *cursor, const QDomElement &element, const QTextBlockFormat &parentFormat, bool merge ) { const QString styleName = element.attribute( QStringLiteral("style-name") ); const StyleFormatProperty property = mStyleInformation->styleProperty( styleName ); QTextBlockFormat blockFormat( parentFormat ); QTextCharFormat textFormat; property.applyBlock( &blockFormat ); property.applyText( &textFormat ); if ( merge ) cursor->mergeBlockFormat( blockFormat ); else cursor->setBlockFormat( blockFormat ); QDomNode child = element.firstChild(); while ( !child.isNull() ) { if ( child.isElement() ) { const QDomElement childElement = child.toElement(); if ( childElement.tagName() == QLatin1String( "span" ) ) { if ( !convertSpan( cursor, childElement, textFormat ) ) return false; } else if ( childElement.tagName() == QLatin1String( "tab" ) ) { mCursor->insertText( QStringLiteral(" ") ); } else if ( childElement.tagName() == QLatin1String( "s" ) ) { QString spaces; spaces.fill( QLatin1Char(' '), childElement.attribute( QStringLiteral("c") ).toInt() ); mCursor->insertText( spaces ); } else if ( childElement.tagName() == QLatin1String( "frame" ) ) { if ( !convertFrame( childElement ) ) return false; } else if ( childElement.tagName() == QLatin1String( "a" ) ) { if ( !convertLink( cursor, childElement, textFormat ) ) return false; } else if ( childElement.tagName() == QLatin1String( "annotation" ) ) { if ( !convertAnnotation( cursor, childElement ) ) return false; } } else if ( child.isText() ) { const QDomText childText = child.toText(); if ( !convertTextNode( cursor, childText, textFormat ) ) return false; } child = child.nextSibling(); } return true; }