KTextWidgets 5.109.0
krichtextedit.h
1/*
2 krichtextedit.h
3 SPDX-FileCopyrightText: 2007 Laurent Montel <montel@kde.org>
4 SPDX-FileCopyrightText: 2008 Thomas McGuire <thomas.mcguire@gmx.net>
5 SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
6
7 SPDX-License-Identifier: LGPL-2.1-or-later
8*/
9
10#ifndef KRICHTEXTEDIT_H
11#define KRICHTEXTEDIT_H
12
13#include <ktextedit.h>
14
15class QKeyEvent;
16
17class KRichTextEditPrivate;
18
19#include <ktextwidgets_export.h>
20
50class KTEXTWIDGETS_EXPORT KRichTextEdit : public KTextEdit
51{
52 Q_OBJECT
53
54public:
58 enum Mode {
61 };
62
70 explicit KRichTextEdit(const QString &text, QWidget *parent = nullptr);
71
77 explicit KRichTextEdit(QWidget *parent = nullptr);
78
82 ~KRichTextEdit() override;
83
89
93 Mode textMode() const;
94
99 QString textOrHtml() const;
100
108 void setTextOrHtml(const QString &text);
109
117 QString currentLinkText() const;
118
126 QString currentLinkUrl() const;
127
136 void selectLinkText(QTextCursor *cursor) const;
137
143 void selectLinkText() const;
144
156 void updateLink(const QString &linkUrl, const QString &linkText);
157
163 bool canIndentList() const;
164
170 bool canDedentList() const;
171
172public Q_SLOTS:
173
177 void alignLeft();
178
183
188
193
200
207
214 void setListStyle(int _styleIndex);
215
222
229
235 void setFontFamily(const QString &fontFamily);
236
242 void setFontSize(int size);
243
249 void setFont(const QFont &font);
250
257 void setTextBold(bool bold);
258
265 void setTextItalic(bool italic);
266
273 void setTextUnderline(bool underline);
274
281 void setTextStrikeOut(bool strikeOut);
282
288 void setTextForegroundColor(const QColor &color);
289
295 void setTextBackgroundColor(const QColor &color);
296
301
307
313 QString toCleanHtml() const;
314
321 void setTextSuperScript(bool superscript);
322
329 void setTextSubScript(bool subscript);
330
339 void setHeadingLevel(int level);
340
347
348Q_SIGNALS:
349
356
357#if KTEXTWIDGETS_ENABLE_DEPRECATED_SINCE(5, 101)
362 KTEXTWIDGETS_DEPRECATED_VERSION_BELATED(5, 101, 4, 1, "No longer emitted")
363 void selectionFinished();
364#endif
365
366protected:
371 void keyPressEvent(QKeyEvent *event) override;
372
373protected:
374 KTEXTWIDGETS_NO_EXPORT KRichTextEdit(KRichTextEditPrivate &dd, const QString &text, QWidget *parent);
375 KTEXTWIDGETS_NO_EXPORT KRichTextEdit(KRichTextEditPrivate &dd, QWidget *parent);
376
377private:
378 //@cond PRIVATE
379 Q_DECLARE_PRIVATE_D(KTextEdit::d, KRichTextEdit)
380#if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(5, 79)
381 QT_WARNING_PUSH
382 QT_WARNING_DISABLE_CLANG("-Wunused-private-field")
383 // Unused, kept for ABI compatibility
384 const void *__ktextwidgets_d_do_not_use;
385 QT_WARNING_POP
386#endif
387 //@endcond
388};
389
390#endif
The KRichTextEdit class provides a widget to edit and display rich text.
Definition krichtextedit.h:51
void insertPlainTextImplementation()
KRichTextEdit(QWidget *parent=nullptr)
Constructs a KRichTextEdit object.
void setTextStrikeOut(bool strikeOut)
Toggles the strikeout formatting of the current word or selection at the current cursor position.
void setTextSubScript(bool subscript)
Toggles the subscript formatting of the current word or selection at the current cursor position.
void alignRight()
Sets the alignment of the current block to Right Aligned.
void setTextForegroundColor(const QColor &color)
Sets the foreground color of the current word or selection to color.
void setTextBackgroundColor(const QColor &color)
Sets the background color of the current word or selection to color.
void insertHorizontalRule()
Inserts a horizontal rule below the current block.
void enableRichTextMode()
This enables rich text mode.
bool canDedentList() const
Returns true if the list item at the current position can be dedented.
QString currentLinkText() const
Returns the text of the link at the current position or an empty string if the cursor is not on a lin...
void setFont(const QFont &font)
Sets the current word or selection to the font font.
void selectLinkText(QTextCursor *cursor) const
If the cursor is on a link, sets the cursor to a selection of the text of the link.
void alignJustify()
Sets the alignment of the current block to Justified.
void switchToPlainText()
This will switch the editor to plain text mode.
void setTextOrHtml(const QString &text)
Replaces all the content of the text edit with the given string.
void setTextUnderline(bool underline)
Toggles the underline formatting of the current word or selection at the current cursor position.
Mode textMode() const
void textModeChanged(KRichTextEdit::Mode mode)
Emitted whenever the text mode is changed.
void setHeadingLevel(int level)
Sets the heading level of a current block or selection.
QString toCleanHtml() const
This will clean some of the bad html produced by the underlying QTextEdit It walks over all lines and...
QString textOrHtml() const
void selectLinkText() const
Convenience function to select the link text using the active cursor.
Mode
The mode the edit widget is in.
Definition krichtextedit.h:58
@ Plain
Plain text mode.
Definition krichtextedit.h:59
@ Rich
Rich text mode.
Definition krichtextedit.h:60
void setFontSize(int size)
Sets the current word or selection to the font size size.
void indentListLess()
Decreases the nesting level of the current block or selected blocks.
void setFontFamily(const QString &fontFamily)
Sets the current word or selection to the font family fontFamily.
void makeLeftToRight()
Sets the direction of the current block to Left-To-Right.
KRichTextEdit(const QString &text, QWidget *parent=nullptr)
Constructs a KRichTextEdit object.
~KRichTextEdit() override
Destructor.
void keyPressEvent(QKeyEvent *event) override
Reimplemented.
QString currentLinkUrl() const
Returns the URL target (href) of the link at the current position or an empty string if the cursor is...
void setListStyle(int _styleIndex)
Sets the list style of the current list, or creates a new list using the current block.
void indentListMore()
Increases the nesting level of the current block or selected blocks.
void alignLeft()
Sets the alignment of the current block to Left Aligned.
void setTextSuperScript(bool superscript)
Toggles the superscript formatting of the current word or selection at the current cursor position.
void setTextBold(bool bold)
Toggles the bold formatting of the current word or selection at the current cursor position.
void setTextItalic(bool italic)
Toggles the italic formatting of the current word or selection at the current cursor position.
void makeRightToLeft()
Sets the direction of the current block to Right-To-Left.
bool canIndentList() const
Returns true if the list item at the current position can be indented.
void alignCenter()
Sets the alignment of the current block to Centered.
void updateLink(const QString &linkUrl, const QString &linkText)
Replaces the current selection with a hyperlink with the link URL linkUrl and the link text linkText.
A KDE'ified QTextEdit.
Definition ktextedit.h:46