|
Grantlee 0.1.9
|
The TextHTMLBuilder creates a clean html markup output. More...
#include <grantlee/texthtmlbuilder.h>

Public Member Functions | |
| TextHTMLBuilder () | |
| void | addNewline () |
| void | appendLiteralText (const QString &text) |
| void | appendRawText (const QString &text) |
| void | beginAnchor (const QString &href=QString(), const QString &name=QString()) |
| void | beginBackground (const QBrush &brush) |
| void | beginEmph () |
| void | beginFontFamily (const QString &family) |
| void | beginFontPointSize (int size) |
| void | beginForeground (const QBrush &brush) |
| void | beginHeader (int level) |
| void | beginList (QTextListFormat::Style type) |
| void | beginListItem () |
| void | beginParagraph (Qt::Alignment al=Qt::AlignLeft, qreal topMargin=0.0, qreal bottomMargin=0.0, qreal leftMargin=0.0, qreal rightMargin=0.0) |
| void | beginStrikeout () |
| void | beginStrong () |
| void | beginSubscript () |
| void | beginSuperscript () |
| void | beginTable (qreal cellpadding, qreal cellspacing, const QString &width) |
| void | beginTableCell (const QString &width, int colspan, int rowspan) |
| void | beginTableHeaderCell (const QString &width, int colspan, int rowspan) |
| void | beginTableRow () |
| void | beginUnderline () |
| void | endAnchor () |
| void | endBackground () |
| void | endEmph () |
| void | endFontFamily () |
| void | endFontPointSize () |
| void | endForeground () |
| void | endHeader (int level) |
| void | endList () |
| void | endListItem () |
| void | endParagraph () |
| void | endStrikeout () |
| void | endStrong () |
| void | endSubscript () |
| void | endSuperscript () |
| void | endTable () |
| void | endTableCell () |
| void | endTableHeaderCell () |
| void | endTableRow () |
| void | endUnderline () |
| QString | getResult () |
| void | insertHorizontalRule (int width=-1) |
| void | insertImage (const QString &src, qreal width, qreal height) |
This class creates html output which is as minimal as possible and restricted to the rich text features supported in Qt. (http://doc.trolltech.com/4.4/richtext-html-subset.htm)
The output contains only the body content, not the head element or other metadata.
eg:
<p>
This is some <strong>formatted content</strong> in a paragraph.
</p>
instead of the content produced by qt:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;"> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is some <span style=" font-weight:600;">formatted content</span> in a paragraph. </p></body></html>
Such tags should be created separately. For example:
AbstractMarkupBuilder *b = new TextHTMLBuilder(); MarkupDirector *md = new MarkupDirector(b); md->constructContent(); QString cleanHtml("<head>\n<title>%1</title>\n</head>\n<body>%2</body>\n</html>") .arg(document.metaInformation(QTextDocument::DocumentTitle)) .arg(b->getOutput()); QFile.write(cleanHtml);
Font formatting information on elements is represented by individual span elements. eg:
<span style"color:blue;"><span style="background-color:red;">Blue text on red background</span></span>
instead of
<span style="color:blue;background-color:red;">Blue text on red background</span>
It my be possible to change this if necessary.
Definition at line 90 of file texthtmlbuilder.h.
| Grantlee::TextHTMLBuilder::TextHTMLBuilder | ( | ) |
Creates a new TextHTMLBuilder.
| void Grantlee::TextHTMLBuilder::addNewline | ( | ) | [virtual] |
Add a newline to the markup.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::appendLiteralText | ( | const QString & | text | ) | [virtual] |
Reimplemented from AbstractMarkupBuilder.
This implementation escapes the text before appending so that
A sample <b>bold</b> word.
becomes
A sample <b>bold</b> word.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::appendRawText | ( | const QString & | text | ) | [virtual] |
Append text without escaping.
This is useful if extending MarkupDirector
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginAnchor | ( | const QString & | href = QString(), |
| const QString & | name = QString() |
||
| ) | [virtual] |
Begin a url anchor element in the markup
| href | The href of the anchor. |
| name | The name of the anchor. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginBackground | ( | const QBrush & | brush | ) | [virtual] |
Begin a decorarated background element in the markup (A text background color) using brush
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginEmph | ( | ) | [virtual] |
Begin an emphasised element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginFontFamily | ( | const QString & | family | ) | [virtual] |
Begin a new font familiy element in the markup
| family | The name of the font family to begin. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginFontPointSize | ( | int | size | ) | [virtual] |
Begin a new font point size
| size | The new size to begin. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginForeground | ( | const QBrush & | brush | ) | [virtual] |
Begin a decorarated foreground element in the markup (A text color) using brush
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginHeader | ( | int | level | ) | [virtual] |
Begin a new header element.
| level | The new level to begin. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginList | ( | QTextListFormat::Style | style | ) | [virtual] |
Begin a new list element in the markup. A list element contains list items, and may contain other lists.
| style | The style of list to create. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginListItem | ( | ) | [virtual] |
Begin a new list item in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginParagraph | ( | Qt::Alignment | al = Qt::AlignLeft, |
| qreal | topMargin = 0.0, |
||
| qreal | bottomMargin = 0.0, |
||
| qreal | leftMargin = 0.0, |
||
| qreal | rightMargin = 0.0 |
||
| ) | [virtual] |
Begin a new paragraph
| al | The new paragraph alignment |
| topMargin | The new paragraph topMargin |
| bottomMargin | The new paragraph bottomMargin |
| leftMargin | The new paragraph leftMargin |
| rightMargin | The new paragraph rightMargin |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginStrikeout | ( | ) | [virtual] |
Begin a struck out element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginStrong | ( | ) | [virtual] |
Begin a bold element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginSubscript | ( | ) | [virtual] |
Begin a subscript element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginSuperscript | ( | ) | [virtual] |
Begin a superscript element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginTable | ( | qreal | cellpadding, |
| qreal | cellspacing, | ||
| const QString & | width | ||
| ) | [virtual] |
Begin a table element.
| cellpadding | The padding attribute for the table. |
| cellspacing | The spacing attribute for the table. |
| width | The width of the table. May be either an integer, or a percentage value. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginTableCell | ( | const QString & | width, |
| int | colSpan, | ||
| int | rowSpan | ||
| ) | [virtual] |
Begin a new table cell.
| width | The width of the cell. |
| colSpan | The column span of the cell. |
| rowSpan | The row span of the cell. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginTableHeaderCell | ( | const QString & | width, |
| int | colSpan, | ||
| int | rowSpan | ||
| ) | [virtual] |
Begin a new table header cell.
| width | The width of the cell. |
| colSpan | The column span of the cell. |
| rowSpan | The row span of the cell. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginTableRow | ( | ) | [virtual] |
Begins a new table row.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::beginUnderline | ( | ) | [virtual] |
Begin an underlined element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endAnchor | ( | ) | [virtual] |
Close the anchor element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endBackground | ( | ) | [virtual] |
Close the decorarated background element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endEmph | ( | ) | [virtual] |
Close the emphasised element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endFontFamily | ( | ) | [virtual] |
End font family element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endFontPointSize | ( | ) | [virtual] |
End font point size element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endForeground | ( | ) | [virtual] |
Close the decorarated foreground element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endHeader | ( | int | level | ) | [virtual] |
End a header element.
| level | The new level to end. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endList | ( | ) | [virtual] |
Close the list.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endListItem | ( | ) | [virtual] |
End the list item
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endParagraph | ( | ) | [virtual] |
Close the paragraph in the markup.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endStrikeout | ( | ) | [virtual] |
Close the struck out element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endStrong | ( | ) | [virtual] |
Close the bold element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endSubscript | ( | ) | [virtual] |
End subscript element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endSuperscript | ( | ) | [virtual] |
End superscript element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endTable | ( | ) | [virtual] |
End a table element
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endTableCell | ( | ) | [virtual] |
End a table cell
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endTableHeaderCell | ( | ) | [virtual] |
End a table header cell
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endTableRow | ( | ) | [virtual] |
End a table row
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::endUnderline | ( | ) | [virtual] |
Close the underlined element in the markup
Implements Grantlee::AbstractMarkupBuilder.
| QString Grantlee::TextHTMLBuilder::getResult | ( | ) | [virtual] |
Return the fully marked up result of the building process. This may contain metadata etc, such as a head element in html.
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::insertHorizontalRule | ( | int | width = -1 | ) | [virtual] |
Insert a horizontal rule into the markup.
| width | The width of the rule. Default is full width. |
Implements Grantlee::AbstractMarkupBuilder.
| void Grantlee::TextHTMLBuilder::insertImage | ( | const QString & | url, |
| qreal | width, | ||
| qreal | height | ||
| ) | [virtual] |
Insert a new image element into the markup.
| url | The url of the image |
| width | The width of the image |
| height | The height of the image. |
Implements Grantlee::AbstractMarkupBuilder.
1.7.4