KPIMTextEdit::TextHTMLBuilder

Search for usage in LXR

KPIMTextEdit::TextHTMLBuilder Class Reference

#include <grantlee/texthtmlbuilder.h>

Inheritance diagram for KPIMTextEdit::TextHTMLBuilder:

Public Member Functions

void addNewline () override
 
void addSingleBreakLine () override
 
void appendLiteralText (const QString &text) override
 
void appendRawText (const QString &text) override
 
void beginAnchor (const QString &href={}, const QString &name={}) override
 
void beginBackground (const QBrush &brush) override
 
void beginEmph () override
 
void beginFontFamily (const QString &family) override
 
void beginFontPointSize (int size) override
 
void beginForeground (const QBrush &brush) override
 
void beginHeader (int level) override
 
void beginList (QTextListFormat::Style type) override
 
void beginListItem () override
 
void beginParagraph (Qt::Alignment al=Qt::AlignLeft, qreal topMargin=0.0, qreal bottomMargin=0.0, qreal leftMargin=0.0, qreal rightMargin=0.0, bool leftToRightText=false) override
 
void beginStrikeout () override
 
void beginStrong () override
 
void beginSubscript () override
 
void beginSuperscript () override
 
void beginTable (qreal cellpadding, qreal cellspacing, const QString &width) override
 
void beginTableCell (const QString &width, int colspan, int rowspan) override
 
void beginTableHeaderCell (const QString &width, int colspan, int rowspan) override
 
void beginTableRow () override
 
void beginUnderline () override
 
void endAnchor () override
 
void endBackground () override
 
void endEmph () override
 
void endFontFamily () override
 
void endFontPointSize () override
 
void endForeground () override
 
void endHeader (int level) override
 
void endList () override
 
void endListItem () override
 
void endParagraph () override
 
void endStrikeout () override
 
void endStrong () override
 
void endSubscript () override
 
void endSuperscript () override
 
void endTable () override
 
void endTableCell () override
 
void endTableHeaderCell () override
 
void endTableRow () override
 
void endUnderline () override
 
QString getResult () override
 
void insertHorizontalRule (int width=-1) override
 
void insertImage (const QString &src, qreal width, qreal height) override
 
- Public Member Functions inherited from KPIMTextEdit::AbstractMarkupBuilder
virtual ~AbstractMarkupBuilder ()=default
 

Detailed Description

The TextHTMLBuilder creates a clean html markup output.

This class creates html output which is as minimal as possible and restricted to the rich text features supported in Qt. (https://doc.qt.io/qt-5/richtext-html-subset.html)

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:

auto b = new TextHTMLBuilder();
auto 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());
file.write(cleanHtml);
Instructs a builder object to create markup output.
The TextHTMLBuilder creates a clean html markup output.
QString arg(Args &&... args) const const

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 steve.nosp@m.ire@.nosp@m.gmail.nosp@m..com

Definition at line 85 of file texthtmlbuilder.h.

Constructor & Destructor Documentation

◆ TextHTMLBuilder()

TextHTMLBuilder::TextHTMLBuilder ( )

Definition at line 34 of file texthtmlbuilder.cpp.

◆ ~TextHTMLBuilder()

TextHTMLBuilder::~TextHTMLBuilder ( )
override

Definition at line 40 of file texthtmlbuilder.cpp.

Member Function Documentation

◆ addNewline()

void TextHTMLBuilder::addNewline ( )
overridevirtual

Add a newline to the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 261 of file texthtmlbuilder.cpp.

◆ addSingleBreakLine()

void KPIMTextEdit::TextHTMLBuilder::addSingleBreakLine ( )
overridevirtual

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 472 of file texthtmlbuilder.cpp.

◆ appendLiteralText()

void TextHTMLBuilder::appendLiteralText ( const QString & text)
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 431 of file texthtmlbuilder.cpp.

◆ appendRawText()

void TextHTMLBuilder::appendRawText ( const QString & text)
overridevirtual

Append text without escaping.

This is useful if extending MarkupDirector

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 458 of file texthtmlbuilder.cpp.

◆ beginAnchor()

void TextHTMLBuilder::beginAnchor ( const QString & href = {},
const QString & name = {} )
overridevirtual

Begin a url anchor element in the markup.

Parameters
hrefThe href of the anchor.
nameThe name of the anchor.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 117 of file texthtmlbuilder.cpp.

◆ beginBackground()

void TextHTMLBuilder::beginBackground ( const QBrush & brush)
overridevirtual

Begin a decorarated background element in the markup (A text background color) using brush.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 105 of file texthtmlbuilder.cpp.

◆ beginEmph()

void TextHTMLBuilder::beginEmph ( )
overridevirtual

Begin an emphasised element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 57 of file texthtmlbuilder.cpp.

◆ beginFontFamily()

void TextHTMLBuilder::beginFontFamily ( const QString & family)
overridevirtual

Begin a new font family element in the markup.

Parameters
familyThe name of the font family to begin.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 139 of file texthtmlbuilder.cpp.

◆ beginFontPointSize()

void TextHTMLBuilder::beginFontPointSize ( int size)
overridevirtual

Begin a new font point size.

Parameters
sizeThe new size to begin.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 151 of file texthtmlbuilder.cpp.

◆ beginForeground()

void TextHTMLBuilder::beginForeground ( const QBrush & brush)
overridevirtual

Begin a decorarated foreground element in the markup (A text color) using brush.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 93 of file texthtmlbuilder.cpp.

◆ beginHeader()

void TextHTMLBuilder::beginHeader ( int level)
overridevirtual

Begin a new header element.

Parameters
levelThe new level to begin.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 201 of file texthtmlbuilder.cpp.

◆ beginList()

void TextHTMLBuilder::beginList ( QTextListFormat::Style style)
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 289 of file texthtmlbuilder.cpp.

◆ beginListItem()

void TextHTMLBuilder::beginListItem ( )
overridevirtual

Begin a new list item in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 343 of file texthtmlbuilder.cpp.

◆ beginParagraph()

void TextHTMLBuilder::beginParagraph ( Qt::Alignment al = Qt::AlignLeft,
qreal topMargin = 0.0,
qreal bottomMargin = 0.0,
qreal leftMargin = 0.0,
qreal rightMargin = 0.0,
bool leftToRightText = false )
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 163 of file texthtmlbuilder.cpp.

◆ beginStrikeout()

void TextHTMLBuilder::beginStrikeout ( )
overridevirtual

Begin a struck out element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 81 of file texthtmlbuilder.cpp.

◆ beginStrong()

void TextHTMLBuilder::beginStrong ( )
overridevirtual

Begin a bold element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 45 of file texthtmlbuilder.cpp.

◆ beginSubscript()

void TextHTMLBuilder::beginSubscript ( )
overridevirtual

Begin a subscript element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 367 of file texthtmlbuilder.cpp.

◆ beginSuperscript()

void TextHTMLBuilder::beginSuperscript ( )
overridevirtual

Begin a superscript element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 355 of file texthtmlbuilder.cpp.

◆ beginTable()

void TextHTMLBuilder::beginTable ( qreal cellpadding,
qreal cellspacing,
const QString & width )
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 379 of file texthtmlbuilder.cpp.

◆ beginTableCell()

void TextHTMLBuilder::beginTableCell ( const QString & width,
int colSpan,
int rowSpan )
overridevirtual

Begin a new table cell.

Parameters
widthThe width of the cell.
colSpanThe column span of the cell.
rowSpanThe row span of the cell.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 401 of file texthtmlbuilder.cpp.

◆ beginTableHeaderCell()

void TextHTMLBuilder::beginTableHeaderCell ( const QString & width,
int colSpan,
int rowSpan )
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 395 of file texthtmlbuilder.cpp.

◆ beginTableRow()

void TextHTMLBuilder::beginTableRow ( )
overridevirtual

Begin a new table row.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 389 of file texthtmlbuilder.cpp.

◆ beginUnderline()

void TextHTMLBuilder::beginUnderline ( )
overridevirtual

Begin an underlined element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 69 of file texthtmlbuilder.cpp.

◆ endAnchor()

void TextHTMLBuilder::endAnchor ( )
overridevirtual

Close the anchor element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 133 of file texthtmlbuilder.cpp.

◆ endBackground()

void TextHTMLBuilder::endBackground ( )
overridevirtual

Close the decorarated background element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 111 of file texthtmlbuilder.cpp.

◆ endEmph()

void TextHTMLBuilder::endEmph ( )
overridevirtual

Close the emphasised element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 63 of file texthtmlbuilder.cpp.

◆ endFontFamily()

void TextHTMLBuilder::endFontFamily ( )
overridevirtual

End font family element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 145 of file texthtmlbuilder.cpp.

◆ endFontPointSize()

void TextHTMLBuilder::endFontPointSize ( )
overridevirtual

End font point size element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 157 of file texthtmlbuilder.cpp.

◆ endForeground()

void TextHTMLBuilder::endForeground ( )
overridevirtual

Close the decorarated foreground element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 99 of file texthtmlbuilder.cpp.

◆ endHeader()

void TextHTMLBuilder::endHeader ( int level)
overridevirtual

End a header element.

Parameters
levelThe new level to end.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 228 of file texthtmlbuilder.cpp.

◆ endList()

void TextHTMLBuilder::endList ( )
overridevirtual

Close the list.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 322 of file texthtmlbuilder.cpp.

◆ endListItem()

void TextHTMLBuilder::endListItem ( )
overridevirtual

End the list item.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 349 of file texthtmlbuilder.cpp.

◆ endParagraph()

void TextHTMLBuilder::endParagraph ( )
overridevirtual

Close the paragraph in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 255 of file texthtmlbuilder.cpp.

◆ endStrikeout()

void TextHTMLBuilder::endStrikeout ( )
overridevirtual

Close the struck out element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 87 of file texthtmlbuilder.cpp.

◆ endStrong()

void TextHTMLBuilder::endStrong ( )
overridevirtual

Close the bold element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 51 of file texthtmlbuilder.cpp.

◆ endSubscript()

void TextHTMLBuilder::endSubscript ( )
overridevirtual

End subscript element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 373 of file texthtmlbuilder.cpp.

◆ endSuperscript()

void TextHTMLBuilder::endSuperscript ( )
overridevirtual

End superscript element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 361 of file texthtmlbuilder.cpp.

◆ endTable()

void TextHTMLBuilder::endTable ( )
overridevirtual

End a table element.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 407 of file texthtmlbuilder.cpp.

◆ endTableCell()

void TextHTMLBuilder::endTableCell ( )
overridevirtual

End a table cell.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 425 of file texthtmlbuilder.cpp.

◆ endTableHeaderCell()

void TextHTMLBuilder::endTableHeaderCell ( )
overridevirtual

End a table header cell.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 419 of file texthtmlbuilder.cpp.

◆ endTableRow()

void TextHTMLBuilder::endTableRow ( )
overridevirtual

End a table row.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 413 of file texthtmlbuilder.cpp.

◆ endUnderline()

void TextHTMLBuilder::endUnderline ( )
overridevirtual

Close the underlined element in the markup.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 75 of file texthtmlbuilder.cpp.

◆ getResult()

QString TextHTMLBuilder::getResult ( )
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 464 of file texthtmlbuilder.cpp.

◆ insertHorizontalRule()

void TextHTMLBuilder::insertHorizontalRule ( int width = -1)
overridevirtual

Insert a horizontal rule into the markup.

Parameters
widthThe width of the rule. Default is full width.

Implements KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 267 of file texthtmlbuilder.cpp.

◆ insertImage()

void TextHTMLBuilder::insertImage ( const QString & url,
qreal width,
qreal height )
overridevirtual

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 KPIMTextEdit::AbstractMarkupBuilder.

Definition at line 276 of file texthtmlbuilder.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.