diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 15 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentfragment.cpp | 36 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentfragment_p.h | 1 | ||||
-rw-r--r-- | src/gui/text/qtextformat.h | 6 |
4 files changed, 54 insertions, 4 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index d95932f4db..e58cd02af5 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2906,7 +2906,11 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) html += QLatin1Char('>'); html += QLatin1String("<pre"); } else if (!list) { - html += QLatin1String("<p"); + int headingLevel = blockFormat.headingLevel(); + if (headingLevel > 0 && headingLevel <= 6) + html += QLatin1String("<h") + QString::number(headingLevel); + else + html += QLatin1String("<p"); } emitBlockAttributes(block); @@ -2929,8 +2933,13 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) html += QLatin1String("</pre>"); else if (list) html += QLatin1String("</li>"); - else - html += QLatin1String("</p>"); + else { + int headingLevel = blockFormat.headingLevel(); + if (headingLevel > 0 && headingLevel <= 6) + html += QLatin1String("</h") + QString::number(headingLevel) + QLatin1Char('>'); + else + html += QLatin1String("</p>"); + } if (list) { if (list->itemNumber(block) == list->count() - 1) { // last item? close list diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index ea37695f4e..3ad49b3f88 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -420,7 +420,7 @@ static QTextListFormat::Style nextListStyle(QTextListFormat::Style style) } QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html, ImportMode mode, const QTextDocument *resourceProvider) - : indent(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(mode) + : indent(0), headingLevel(0), compressNextWhitespace(PreserveWhiteSpace), doc(_doc), importMode(mode) { cursor = QTextCursor(doc); wsm = QTextHtmlParserNode::WhiteSpaceNormal; @@ -747,8 +747,28 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() return ContinueWithNextNode; } + case Html_h1: + headingLevel = 1; + break; + case Html_h2: + headingLevel = 2; + break; + case Html_h3: + headingLevel = 3; + break; + case Html_h4: + headingLevel = 4; + break; + case Html_h5: + headingLevel = 5; + break; + case Html_h6: + headingLevel = 6; + break; + default: break; } + return ContinueWithCurrentNode; } @@ -832,6 +852,15 @@ bool QTextHtmlImporter::closeTag() } } break; + case Html_h1: + case Html_h2: + case Html_h3: + case Html_h4: + case Html_h5: + case Html_h6: + headingLevel = 0; + blockTagClosed = true; + break; default: if (closedNode->isBlock()) blockTagClosed = true; @@ -1093,6 +1122,11 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() modifiedBlockFormat = true; } + if (headingLevel) { + block.setHeadingLevel(headingLevel); + modifiedBlockFormat = true; + } + if (currentNode->blockFormat.propertyCount() > 0) { modifiedBlockFormat = true; block.merge(currentNode->blockFormat); diff --git a/src/gui/text/qtextdocumentfragment_p.h b/src/gui/text/qtextdocumentfragment_p.h index e8699545f7..02a6a429fa 100644 --- a/src/gui/text/qtextdocumentfragment_p.h +++ b/src/gui/text/qtextdocumentfragment_p.h @@ -152,6 +152,7 @@ private: friend class QTypeInfo<List>; QVector<List> lists; int indent; + int headingLevel; // insert a named anchor the next time we emit a char format, // either in a block or in regular text diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 28c3035537..8f8d3d4299 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -175,6 +175,7 @@ public: LineHeightType = 0x1049, BlockNonBreakableLines = 0x1050, BlockTrailingHorizontalRulerWidth = 0x1060, + HeadingLevel = 0x1070, // character properties FirstFontProperty = 0x1FE0, @@ -624,6 +625,11 @@ public: inline int indent() const { return intProperty(BlockIndent); } + inline void setHeadingLevel(int alevel) + { setProperty(HeadingLevel, alevel); } + inline int headingLevel() const + { return intProperty(HeadingLevel); } + inline void setLineHeight(qreal height, int heightType) { setProperty(LineHeight, height); setProperty(LineHeightType, heightType); } inline qreal lineHeight(qreal scriptLineHeight, qreal scaling) const; |