KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
htmlbuilder.h
1/******************************************************************************************
2**
3** htmlbuilder.h
4**
5** This is the very early start on an HTML builder class.
6**
7** Author: Stephen Punak
8** Created: Sun Feb 22 2025
9**
10******************************************************************************************/
11#ifndef HTMLBUILDER_H
12#define HTMLBUILDER_H
13#include <Kanoop/gui/libkanoopgui.h>
14#include <Kanoop/gui/utility/htmlutil.h>
15
16#include <QTextStream>
17
18/**
19 * @brief Streaming HTML fragment builder.
20 *
21 * HtmlBuilder accumulates HTML into an internal string via a QTextStream.
22 * Call the open/close methods in order, then retrieve the result with toString().
23 */
24class LIBKANOOPGUI_EXPORT HtmlBuilder
25{
26public:
27 /** @brief Construct an empty builder. */
29
30 /**
31 * @brief Append an opening &lt;p&gt; tag with optional foreground and background colors.
32 * @param color Foreground text color (invalid QColor = none)
33 * @param backgroundColor Background color (invalid QColor = none)
34 */
35 void startParagraph(const QColor& color = QColor(), const QColor& backgroundColor = QColor());
36
37 /** @brief Append a closing &lt;/p&gt; tag. */
39
40 /** @brief Append an opening &lt;b&gt; tag. */
41 void startBold();
42 /** @brief Append a closing &lt;/b&gt; tag. */
43 void endBold();
44
45 /** @brief Append an opening &lt;strong&gt; tag. */
47 /** @brief Append a closing &lt;/strong&gt; tag. */
48 void endStrong();
49
50 /**
51 * @brief Append plain text to the output.
52 * @param text Text to append (not HTML-escaped)
53 */
54 void appendText(const QString& text);
55
56 /**
57 * @brief Return the accumulated HTML string.
58 * @return HTML fragment built so far
59 */
60 QString toString() const { return _result; }
61
62private:
63 QString _result;
64 QTextStream _output;
65};
66
67#endif // HTMLBUILDER_H
Streaming HTML fragment builder.
Definition htmlbuilder.h:25
void startStrong()
Append an opening <strong> tag.
void appendText(const QString &text)
Append plain text to the output.
void endParagraph()
Append a closing </p> tag.
QString toString() const
Return the accumulated HTML string.
Definition htmlbuilder.h:60
void endBold()
Append a closing </b> tag.
void endStrong()
Append a closing </strong> tag.
void startParagraph(const QColor &color=QColor(), const QColor &backgroundColor=QColor())
Append an opening <p> tag with optional foreground and background colors.
void startBold()
Append an opening <b> tag.
HtmlBuilder()
Construct an empty builder.