KPimTextEdit

abstractmarkupbuilder.h
1/*
2 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel.org>
3 SPDX-FileCopyrightText: 2008, 2010 Stephen Kelly <steveire@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6
7*/
8
9#pragma once
10#include "kpimtextedit_export.h"
11
12#include <QString>
13#include <QTextListFormat>
14
15class QBrush;
16
17namespace KPIMTextEdit
18{
19class AbstractMarkupBuilderPrivate;
20
21/// @headerfile abstractmarkupbuilder.h grantlee/abstractmarkupbuilder.h
22
23/**
24 @brief Interface for creating marked-up text output.
25
26 The **%AbstractMarkupBuilder** is used by a MarkupDirector to create marked-up
27 output such as html or markdown.
28
29 See PlainTextMarkupBuilder and TextHTMLBuilder for example implementations.
30
31 This interface can be extended to handle custom format types in a
32 QTextDocument. @see @ref custom_qtextobject
33
34 @author Stephen Kelly <steveire@gmail.com>
35*/
36class KPIMTEXTEDIT_EXPORT AbstractMarkupBuilder
37{
38public:
39 /** Destructor */
40 virtual ~AbstractMarkupBuilder() = default;
41
42 /** Begin a bold element in the markup */
43 virtual void beginStrong() = 0;
44
45 /** Close the bold element in the markup */
46 virtual void endStrong() = 0;
47
48 /** Begin an emphasised element in the markup */
49 virtual void beginEmph() = 0;
50
51 /** Close the emphasised element in the markup */
52 virtual void endEmph() = 0;
53
54 /** Begin an underlined element in the markup */
55 virtual void beginUnderline() = 0;
56
57 /** Close the underlined element in the markup */
58 virtual void endUnderline() = 0;
59
60 /** Begin a struck out element in the markup */
61 virtual void beginStrikeout() = 0;
62
63 /** Close the struck out element in the markup */
64 virtual void endStrikeout() = 0;
65
66 /**
67 Begin a decorarated foreground element in the markup (A text color)
68 using @p brush
69 */
70 virtual void beginForeground(const QBrush &brush) = 0;
71
72 /** Close the decorarated foreground element in the markup */
73 virtual void endForeground() = 0;
74
75 /**
76 Begin a decorarated background element in the markup (A text background
77 color) using @p brush
78 */
79 virtual void beginBackground(const QBrush &brush) = 0;
80
81 /** Close the decorarated background element in the markup */
82 virtual void endBackground() = 0;
83
84 /**
85 Begin a url anchor element in the markup
86 @param href The href of the anchor.
87 @param name The name of the anchor.
88 */
89 virtual void beginAnchor(const QString &href = {}, const QString &name = {}) = 0;
90
91 /** Close the anchor element */
92 virtual void endAnchor() = 0;
93
94 /**
95 Begin a new font family element in the markup
96 @param family The name of the font family to begin.
97 */
98 virtual void beginFontFamily(const QString &family) = 0;
99
100 /** End font family element */
101 virtual void endFontFamily() = 0;
102
103 /**
104 Begin a new font point size element in the markup
105 @param size The point size to begin.
106 */
107 virtual void beginFontPointSize(int size) = 0;
108
109 /** End font point size element */
110 virtual void endFontPointSize() = 0;
111
112 /**
113 Begin a new paragraph in the markup
114 @param a The alignment of the new paragraph.
115 @param top The top margin of the new paragraph.
116 @param bottom The bottom margin of the new paragraph.
117 @param left The left margin of the new paragraph.
118 @param right The right margin of the new paragraph.
119 */
120 virtual void
121 beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0, bool leftToRightText = false) = 0;
122
123 /** Close the paragraph in the markup. */
124 virtual void endParagraph() = 0;
125 /** Add a newline to the markup. */
126 virtual void addNewline() = 0;
127
128 /**
129 Insert a horizontal rule into the markup.
130 @param width The width of the rule. Default is full width.
131 */
132 virtual void insertHorizontalRule(int width = -1) = 0;
133
134 /**
135 Insert a new image element into the markup.
136 @param url The url of the image
137 @param width The width of the image
138 @param height The height of the image.
139 */
140 virtual void insertImage(const QString &url, qreal width, qreal height) = 0;
141
142 /**
143 Begin a new list element in the markup.
144 A list element contains list items, and may contain other lists.
145 @param style The style of list to create.
146 */
147 virtual void beginList(QTextListFormat::Style style) = 0;
148
149 /**
150 Close the list.
151 */
152 virtual void endList() = 0;
153
154 /** Begin a new list item in the markup */
155 virtual void beginListItem() = 0;
156
157 /** End the list item */
158 virtual void endListItem() = 0;
159
160 /** Begin a superscript element */
161 virtual void beginSuperscript() = 0;
162
163 /** End superscript element */
164 virtual void endSuperscript() = 0;
165
166 /** Begin a subscript element */
167 virtual void beginSubscript() = 0;
168
169 /** End subscript element */
170 virtual void endSubscript() = 0;
171
172 /**
173 Begin a table element.
174
175 @param cellpadding The padding attribute for the table.
176 @param cellspacing The spacing attribute for the table.
177 @param width The width of the table. May be either an integer, or a
178 percentage value.
179 */
180 virtual void beginTable(qreal cellpadding, qreal cellspacing, const QString &width) = 0;
181
182 /**
183 Begin a new table row
184 */
185 virtual void beginTableRow() = 0;
186
187 /**
188 Begin a new table header cell.
189 @param width The width of the cell.
190 @param colSpan The column span of the cell.
191 @param rowSpan The row span of the cell.
192 */
193 virtual void beginTableHeaderCell(const QString &width, int colSpan, int rowSpan) = 0;
194
195 /**
196 Begin a new table cell.
197 @param width The width of the cell.
198 @param colSpan The column span of the cell.
199 @param rowSpan The row span of the cell.
200 */
201 virtual void beginTableCell(const QString &width, int colSpan, int rowSpan) = 0;
202
203 /** End a table element */
204 virtual void endTable() = 0;
205
206 /** End a table row */
207 virtual void endTableRow() = 0;
208
209 /** End a table header cell */
210 virtual void endTableHeaderCell() = 0;
211
212 /** End a table cell */
213 virtual void endTableCell() = 0;
214
215 /**
216 Begin a level @p level header
217 @param level An integer between 1 and 6
218 */
219 virtual void beginHeader(int level) = 0;
220
221 /**
222 End a level @p level header
223 @param level An integer between 1 and 6
224 */
225 virtual void endHeader(int level) = 0;
226
227 /**
228 Append the plain text @p text to the markup
229
230 @param text The text to append.
231 */
232 virtual void appendLiteralText(const QString &text) = 0;
233
234 /**
235 Append the raw text @p text to the markup. @p text is added unescaped
236 */
237 virtual void appendRawText(const QString &text) = 0;
238
239 /**
240 Return the fully marked up result of the building process.
241
242 This may contain metadata etc, such as a head element in html.
243
244 @return The fully marked up text.
245 */
246 [[nodiscard]] virtual QString getResult() = 0;
247
248 virtual void addSingleBreakLine() = 0;
249};
250}
Interface for creating marked-up text output.
virtual void beginFontPointSize(int size)=0
Begin a new font point size element in the markup.
virtual ~AbstractMarkupBuilder()=default
Destructor.
virtual void beginSubscript()=0
Begin a subscript element.
virtual void beginList(QTextListFormat::Style style)=0
Begin a new list element in the markup.
virtual QString getResult()=0
Return the fully marked up result of the building process.
virtual void endTableHeaderCell()=0
End a table header cell.
virtual void endParagraph()=0
Close the paragraph in the markup.
virtual void endSuperscript()=0
End superscript element.
virtual void beginEmph()=0
Begin an emphasised element in the markup.
virtual void endForeground()=0
Close the decorarated foreground element in the markup.
virtual void beginUnderline()=0
Begin an underlined element in the markup.
virtual void beginSuperscript()=0
Begin a superscript element.
virtual void beginBackground(const QBrush &brush)=0
Begin a decorarated background element in the markup (A text background color) using brush.
virtual void beginStrikeout()=0
Begin a struck out element in the markup.
virtual void beginTableCell(const QString &width, int colSpan, int rowSpan)=0
Begin a new table cell.
virtual void endTable()=0
End a table element.
virtual void beginParagraph(Qt::Alignment a=Qt::AlignLeft, qreal top=0.0, qreal bottom=0.0, qreal left=0.0, qreal right=0.0, bool leftToRightText=false)=0
Begin a new paragraph in the markup.
virtual void endTableRow()=0
End a table row.
virtual void endStrong()=0
Close the bold element in the markup.
virtual void appendLiteralText(const QString &text)=0
Append the plain text text to the markup.
virtual void endList()=0
Close the list.
virtual void endBackground()=0
Close the decorarated background element in the markup.
virtual void insertHorizontalRule(int width=-1)=0
Insert a horizontal rule into the markup.
virtual void endFontFamily()=0
End font family element.
virtual void beginTable(qreal cellpadding, qreal cellspacing, const QString &width)=0
Begin a table element.
virtual void endAnchor()=0
Close the anchor element.
virtual void endSubscript()=0
End subscript element.
virtual void beginStrong()=0
Begin a bold element in the markup.
virtual void beginForeground(const QBrush &brush)=0
Begin a decorarated foreground element in the markup (A text color) using brush.
virtual void endHeader(int level)=0
End a level level header.
virtual void insertImage(const QString &url, qreal width, qreal height)=0
Insert a new image element into the markup.
virtual void endFontPointSize()=0
End font point size element.
virtual void endEmph()=0
Close the emphasised element in the markup.
virtual void beginHeader(int level)=0
Begin a level level header.
virtual void beginFontFamily(const QString &family)=0
Begin a new font family element in the markup.
virtual void endListItem()=0
End the list item.
virtual void endTableCell()=0
End a table cell.
virtual void beginTableHeaderCell(const QString &width, int colSpan, int rowSpan)=0
Begin a new table header cell.
virtual void endStrikeout()=0
Close the struck out element in the markup.
virtual void appendRawText(const QString &text)=0
Append the raw text text to the markup.
virtual void beginAnchor(const QString &href={}, const QString &name={})=0
Begin a url anchor element in the markup.
virtual void beginTableRow()=0
Begin a new table row.
virtual void addNewline()=0
Add a newline to the markup.
virtual void endUnderline()=0
Close the underlined element in the markup.
virtual void beginListItem()=0
Begin a new list item in the markup.
typedef Alignment
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.