KPimTextEdit

richtextcomposer.h
1/*
2 SPDX-FileCopyrightText: 2015-2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kpimtextedit_export.h"
10
11#include <TextCustomEditor/RichTextEditor>
13
14namespace KPIMTextEdit
15{
19class RichTextComposerEmailQuoteHighlighter;
20/**
21 * @brief The RichTextComposer class
22 * @author Laurent Montel <montel@kde.org>
23 */
24class KPIMTEXTEDIT_EXPORT RichTextComposer : public TextCustomEditor::RichTextEditor
25{
27public:
28 explicit RichTextComposer(QWidget *parent = nullptr);
29 ~RichTextComposer() override;
30
31 enum Mode {
32 Plain, ///< Plain text mode
33 Rich ///< Rich text mode
34 };
35
36 /**
37 * @return The current text mode
38 */
39 [[nodiscard]] Mode textMode() const;
40
41 /**
42 * Enables word wrap. Words will be wrapped at the specified column.
43 *
44 * @param wrapColumn the column where words will be wrapped
45 */
46 void enableWordWrap(int wrapColumn);
47
48 /**
49 * Disables word wrap.
50 * Note that words are still wrapped at the end of the editor; no scrollbar
51 * will appear.
52 */
53 void disableWordWrap();
54
55 /**
56 * @return the line number where the cursor is. This takes word-wrapping
57 * into account. Line numbers start at 0.
58 */
59 [[nodiscard]] int linePosition() const;
60
61 /**
62 * @return the column number where the cursor is.
63 */
64 [[nodiscard]] int columnNumber() const;
65
66 void forcePlainTextMarkup(bool force);
67
68 void activateRichText();
69 void switchToPlainText();
70
71 void setTextOrHtml(const QString &text);
72 [[nodiscard]] QString textOrHtml() const;
73
74 virtual void setHighlighterColors(KPIMTextEdit::RichTextComposerEmailQuoteHighlighter *highlighter);
75
76 void setUseExternalEditor(bool use);
77 void setExternalEditorPath(const QString &path);
78 [[nodiscard]] bool checkExternalEditorFinished();
79 void killExternalEditor();
80
81 // Redefine it for each apps
82 virtual QString smartQuote(const QString &msg); // need by kmail
83
84 void setQuotePrefixName(const QString &quotePrefix);
85 [[nodiscard]] QString quotePrefixName() const;
86
87 void setCursorPositionFromStart(unsigned int pos);
88 [[nodiscard]] int quoteLength(const QString &line, bool oneQuote = false) const;
89 [[nodiscard]] bool isLineQuoted(const QString &line) const;
90 const QString defaultQuoteSign() const;
91 void createActions(KActionCollection *ac);
92
93 [[nodiscard]] QList<QAction *> richTextActionList() const;
94 void setEnableActions(bool state);
95
96 KPIMTextEdit::RichTextComposerControler *composerControler() const;
97 KPIMTextEdit::RichTextExternalComposer *externalComposer() const;
98 KPIMTextEdit::RichTextComposerActions *composerActions() const;
99 void createHighlighter() override;
100 [[nodiscard]] virtual bool processModifyText(QKeyEvent *event);
101
102public Q_SLOTS:
103 void insertPlainTextImplementation();
104 void slotChangeInsertMode();
105
106Q_SIGNALS:
107 void insertModeChanged();
108 /**
109 * Emitted whenever the text mode is changed.
110 *
111 * @param mode The new text mode
112 */
114 /**
115 * Emitted when the user uses the up arrow in the first line. The application
116 * should then put the focus on the widget above the text edit.
117 */
118 void focusUp();
119
120 void externalEditorStarted();
121 void externalEditorClosed();
122 void insertEmoticon(const QString &str);
123
124protected:
125 void keyPressEvent(QKeyEvent *event) override;
126 Sonnet::SpellCheckDecorator *createSpellCheckDecorator() override;
127 void insertFromMimeData(const QMimeData *source) override;
128 bool canInsertFromMimeData(const QMimeData *source) const override;
129 void mouseReleaseEvent(QMouseEvent *event) override;
130 void clearDecorator() override;
131 void updateHighLighter() override;
132 bool processKeyEvent(QKeyEvent *e);
133
134private:
135 KPIMTEXTEDIT_NO_EXPORT void slotTextModeChanged(KPIMTextEdit::RichTextComposer::Mode mode);
136 KPIMTEXTEDIT_NO_EXPORT void evaluateListSupport(QKeyEvent *event);
137 KPIMTEXTEDIT_NO_EXPORT void evaluateReturnKeySupport(QKeyEvent *event);
138 class RichTextComposerPrivate;
139 std::unique_ptr<RichTextComposerPrivate> const d;
140};
141}
The RichTextComposerActions class.
The RichTextComposerControler class.
void textModeChanged(KPIMTextEdit::RichTextComposer::Mode mode)
Emitted whenever the text mode is changed.
void focusUp()
Emitted when the user uses the up arrow in the first line.
The RichTextExternalComposer class.
virtual bool event(QEvent *event) override
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:57:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.