KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
plaintextedit.h
1#ifndef PLAINTEXTEDIT_H
2#define PLAINTEXTEDIT_H
3
4#include <QPlainTextEdit>
5#include <Kanoop/gui/libkanoopgui.h>
6
7/**
8 * @brief QPlainTextEdit subclass with HTML-formatted and color-styled append helpers.
9 *
10 * PlainTextEdit adds appendText() for appending plain text with optional
11 * per-call foreground and background colors, and appendFormattedText() which
12 * additionally accepts TextFlags for bold/strong formatting.
13 */
14class LIBKANOOPGUI_EXPORT PlainTextEdit : public QPlainTextEdit
15{
16 Q_OBJECT
17public:
18 /**
19 * @brief Construct with an optional parent.
20 * @param parent Optional QWidget parent
21 */
22 explicit PlainTextEdit(QWidget *parent = nullptr) :
23 QPlainTextEdit(parent) {}
24
25 /**
26 * @brief Construct with initial text content.
27 * @param text Initial plain text
28 * @param parent Optional QWidget parent
29 */
30 explicit PlainTextEdit(const QString& text, QWidget *parent = nullptr) :
31 QPlainTextEdit(text, parent) {}
32
33 /**
34 * @brief Flags controlling text formatting for appendFormattedText().
35 */
37 {
38 NoTextFlags = 0x0000, ///< No formatting
39 BoldText = 0x0001, ///< Render text in bold
40 StrongText = 0x0002, ///< Render text wrapped in &lt;strong&gt;
41 };
42 Q_DECLARE_FLAGS(TextFlags, TextFlag)
43
44 /**
45 * @brief Append a line of text with optional per-call colors.
46 * @param text Text to append
47 * @param foregroundColor Text color (invalid QColor = default)
48 * @param backgroundColor Background color (invalid QColor = default)
49 */
50 void appendText(const QString& text, const QColor& foregroundColor = QColor(), const QColor& backgroundColor = QColor());
51
52 /**
53 * @brief Append a formatted line of text with flags and optional colors.
54 * @param text Text to append
55 * @param flags Combination of TextFlag values
56 * @param foregroundColor Text color (invalid QColor = default)
57 * @param backgroundColor Background color (invalid QColor = default)
58 */
59 void appendFormattedText(const QString& text, TextFlags flags, const QColor& foregroundColor = QColor(), const QColor& backgroundColor = QColor());
60};
61
62Q_DECLARE_OPERATORS_FOR_FLAGS(PlainTextEdit::TextFlags)
63
64#endif // PLAINTEXTEDIT_H
QPlainTextEdit subclass with HTML-formatted and color-styled append helpers.
PlainTextEdit(const QString &text, QWidget *parent=nullptr)
Construct with initial text content.
PlainTextEdit(QWidget *parent=nullptr)
Construct with an optional parent.
TextFlag
Flags controlling text formatting for appendFormattedText().