Grantlee 0.1.9
Public Member Functions
Grantlee::TextHTMLBuilder Class Reference

The TextHTMLBuilder creates a clean html markup output. More...

#include <grantlee/texthtmlbuilder.h>

Inheritance diagram for Grantlee::TextHTMLBuilder:
Inheritance graph
[legend]

List of all members.

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)

Detailed Description

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.

Author:
Stephen Kelly <steveire@gmail.com>

Definition at line 90 of file texthtmlbuilder.h.


Constructor & Destructor Documentation

Grantlee::TextHTMLBuilder::TextHTMLBuilder ( )

Creates a new TextHTMLBuilder.


Member Function Documentation

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 &lt;b&gt;bold&lt;/b&gt; 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

Parameters:
hrefThe href of the anchor.
nameThe 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

Parameters:
familyThe name of the font family to begin.

Implements Grantlee::AbstractMarkupBuilder.

void Grantlee::TextHTMLBuilder::beginFontPointSize ( int  size) [virtual]

Begin a new font point size

Parameters:
sizeThe 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.

Parameters:
levelThe 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.

Parameters:
styleThe 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

Parameters:
alThe new paragraph alignment
topMarginThe new paragraph topMargin
bottomMarginThe new paragraph bottomMargin
leftMarginThe new paragraph leftMargin
rightMarginThe 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.

Parameters:
cellpaddingThe padding attribute for the table.
cellspacingThe spacing attribute for the table.
widthThe 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.

Parameters:
widthThe width of the cell.
colSpanThe column span of the cell.
rowSpanThe 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.

Parameters:
widthThe width of the cell.
colSpanThe column span of the cell.
rowSpanThe 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.

Parameters:
levelThe 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.

Returns:
The fully marked up text.

Implements Grantlee::AbstractMarkupBuilder.

void Grantlee::TextHTMLBuilder::insertHorizontalRule ( int  width = -1) [virtual]

Insert a horizontal rule into the markup.

Parameters:
widthThe 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.

Parameters:
urlThe url of the image
widthThe width of the image
heightThe height of the image.

Implements Grantlee::AbstractMarkupBuilder.