File indexing completed on 2024-05-19 05:21:45
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel.org> 0003 SPDX-FileCopyrightText: 2008, 2010 Stephen Kelly <steveire@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 0007 */ 0008 0009 #pragma once 0010 #include "kpimtextedit_export.h" 0011 0012 #include <QString> 0013 #include <QTextListFormat> 0014 0015 class QBrush; 0016 0017 namespace KPIMTextEdit 0018 { 0019 class AbstractMarkupBuilderPrivate; 0020 0021 /// @headerfile abstractmarkupbuilder.h grantlee/abstractmarkupbuilder.h 0022 0023 /** 0024 @brief Interface for creating marked-up text output. 0025 0026 The **%AbstractMarkupBuilder** is used by a MarkupDirector to create marked-up 0027 output such as html or markdown. 0028 0029 See PlainTextMarkupBuilder and TextHTMLBuilder for example implementations. 0030 0031 This interface can be extended to handle custom format types in a 0032 QTextDocument. @see @ref custom_qtextobject 0033 0034 @author Stephen Kelly <steveire@gmail.com> 0035 */ 0036 class KPIMTEXTEDIT_EXPORT AbstractMarkupBuilder 0037 { 0038 public: 0039 /** Destructor */ 0040 virtual ~AbstractMarkupBuilder() = default; 0041 0042 /** Begin a bold element in the markup */ 0043 virtual void beginStrong() = 0; 0044 0045 /** Close the bold element in the markup */ 0046 virtual void endStrong() = 0; 0047 0048 /** Begin an emphasised element in the markup */ 0049 virtual void beginEmph() = 0; 0050 0051 /** Close the emphasised element in the markup */ 0052 virtual void endEmph() = 0; 0053 0054 /** Begin an underlined element in the markup */ 0055 virtual void beginUnderline() = 0; 0056 0057 /** Close the underlined element in the markup */ 0058 virtual void endUnderline() = 0; 0059 0060 /** Begin a struck out element in the markup */ 0061 virtual void beginStrikeout() = 0; 0062 0063 /** Close the struck out element in the markup */ 0064 virtual void endStrikeout() = 0; 0065 0066 /** 0067 Begin a decorarated foreground element in the markup (A text color) 0068 using @p brush 0069 */ 0070 virtual void beginForeground(const QBrush &brush) = 0; 0071 0072 /** Close the decorarated foreground element in the markup */ 0073 virtual void endForeground() = 0; 0074 0075 /** 0076 Begin a decorarated background element in the markup (A text background 0077 color) using @p brush 0078 */ 0079 virtual void beginBackground(const QBrush &brush) = 0; 0080 0081 /** Close the decorarated background element in the markup */ 0082 virtual void endBackground() = 0; 0083 0084 /** 0085 Begin a url anchor element in the markup 0086 @param href The href of the anchor. 0087 @param name The name of the anchor. 0088 */ 0089 virtual void beginAnchor(const QString &href = {}, const QString &name = {}) = 0; 0090 0091 /** Close the anchor element */ 0092 virtual void endAnchor() = 0; 0093 0094 /** 0095 Begin a new font family element in the markup 0096 @param family The name of the font family to begin. 0097 */ 0098 virtual void beginFontFamily(const QString &family) = 0; 0099 0100 /** End font family element */ 0101 virtual void endFontFamily() = 0; 0102 0103 /** 0104 Begin a new font point size element in the markup 0105 @param size The point size to begin. 0106 */ 0107 virtual void beginFontPointSize(int size) = 0; 0108 0109 /** End font point size element */ 0110 virtual void endFontPointSize() = 0; 0111 0112 /** 0113 Begin a new paragraph in the markup 0114 @param a The alignment of the new paragraph. 0115 @param top The top margin of the new paragraph. 0116 @param bottom The bottom margin of the new paragraph. 0117 @param left The left margin of the new paragraph. 0118 @param right The right margin of the new paragraph. 0119 */ 0120 virtual void 0121 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; 0122 0123 /** Close the paragraph in the markup. */ 0124 virtual void endParagraph() = 0; 0125 /** Add a newline to the markup. */ 0126 virtual void addNewline() = 0; 0127 0128 /** 0129 Insert a horizontal rule into the markup. 0130 @param width The width of the rule. Default is full width. 0131 */ 0132 virtual void insertHorizontalRule(int width = -1) = 0; 0133 0134 /** 0135 Insert a new image element into the markup. 0136 @param url The url of the image 0137 @param width The width of the image 0138 @param height The height of the image. 0139 */ 0140 virtual void insertImage(const QString &url, qreal width, qreal height) = 0; 0141 0142 /** 0143 Begin a new list element in the markup. 0144 A list element contains list items, and may contain other lists. 0145 @param style The style of list to create. 0146 */ 0147 virtual void beginList(QTextListFormat::Style style) = 0; 0148 0149 /** 0150 Close the list. 0151 */ 0152 virtual void endList() = 0; 0153 0154 /** Begin a new list item in the markup */ 0155 virtual void beginListItem() = 0; 0156 0157 /** End the list item */ 0158 virtual void endListItem() = 0; 0159 0160 /** Begin a superscript element */ 0161 virtual void beginSuperscript() = 0; 0162 0163 /** End superscript element */ 0164 virtual void endSuperscript() = 0; 0165 0166 /** Begin a subscript element */ 0167 virtual void beginSubscript() = 0; 0168 0169 /** End subscript element */ 0170 virtual void endSubscript() = 0; 0171 0172 /** 0173 Begin a table element. 0174 0175 @param cellpadding The padding attribute for the table. 0176 @param cellspacing The spacing attribute for the table. 0177 @param width The width of the table. May be either an integer, or a 0178 percentage value. 0179 */ 0180 virtual void beginTable(qreal cellpadding, qreal cellspacing, const QString &width) = 0; 0181 0182 /** 0183 Begin a new table row 0184 */ 0185 virtual void beginTableRow() = 0; 0186 0187 /** 0188 Begin a new table header cell. 0189 @param width The width of the cell. 0190 @param colSpan The column span of the cell. 0191 @param rowSpan The row span of the cell. 0192 */ 0193 virtual void beginTableHeaderCell(const QString &width, int colSpan, int rowSpan) = 0; 0194 0195 /** 0196 Begin a new table cell. 0197 @param width The width of the cell. 0198 @param colSpan The column span of the cell. 0199 @param rowSpan The row span of the cell. 0200 */ 0201 virtual void beginTableCell(const QString &width, int colSpan, int rowSpan) = 0; 0202 0203 /** End a table element */ 0204 virtual void endTable() = 0; 0205 0206 /** End a table row */ 0207 virtual void endTableRow() = 0; 0208 0209 /** End a table header cell */ 0210 virtual void endTableHeaderCell() = 0; 0211 0212 /** End a table cell */ 0213 virtual void endTableCell() = 0; 0214 0215 /** 0216 Begin a level @p level header 0217 @param level An integer between 1 and 6 0218 */ 0219 virtual void beginHeader(int level) = 0; 0220 0221 /** 0222 End a level @p level header 0223 @param level An integer between 1 and 6 0224 */ 0225 virtual void endHeader(int level) = 0; 0226 0227 /** 0228 Append the plain text @p text to the markup 0229 0230 @param text The text to append. 0231 */ 0232 virtual void appendLiteralText(const QString &text) = 0; 0233 0234 /** 0235 Append the raw text @p text to the markup. @p text is added unescaped 0236 */ 0237 virtual void appendRawText(const QString &text) = 0; 0238 0239 /** 0240 Return the fully marked up result of the building process. 0241 0242 This may contain metadata etc, such as a head element in html. 0243 0244 @return The fully marked up text. 0245 */ 0246 [[nodiscard]] virtual QString getResult() = 0; 0247 0248 virtual void addSingleBreakLine() = 0; 0249 }; 0250 }