KTextWidgets 5.109.0
ktextedit.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KTEXTEDIT_H
9#define KTEXTEDIT_H
10
11#include "ktextwidgets_export.h"
12
13#include <QTextEdit>
14#include <memory>
15#include <sonnet/highlighter.h>
16
17namespace Sonnet
18{
19class SpellCheckDecorator;
20}
21
22class KTextEditPrivate;
23
45class KTEXTWIDGETS_EXPORT KTextEdit : public QTextEdit // krazy:exclude=qclasses
46{
47 Q_OBJECT
48#if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(5, 0)
49 Q_PROPERTY(QString clickMessage READ clickMessage WRITE setClickMessage)
50#endif
51 Q_PROPERTY(bool checkSpellingEnabled READ checkSpellingEnabled WRITE setCheckSpellingEnabled)
52 Q_PROPERTY(QString spellCheckingLanguage READ spellCheckingLanguage WRITE setSpellCheckingLanguage)
53
54public:
59 explicit KTextEdit(const QString &text, QWidget *parent = nullptr);
60
65 explicit KTextEdit(QWidget *parent = nullptr);
66
70 ~KTextEdit() override;
71
75 virtual void setReadOnly(bool readOnly);
76
88 virtual void setCheckSpellingEnabled(bool check);
89
98 virtual bool checkSpellingEnabled() const;
99
109 virtual bool shouldBlockBeSpellChecked(const QString &block) const;
110
119 void highlightWord(int length, int pos);
120
135 virtual void createHighlighter();
136
145 Sonnet::Highlighter *highlighter() const;
146
162 void setHighlighter(Sonnet::Highlighter *_highLighter);
163
168 virtual QMenu *mousePopupMenu();
169
174 void enableFindReplace(bool enabled);
175
182 const QString &spellCheckingLanguage() const;
183
184#if KTEXTWIDGETS_ENABLE_DEPRECATED_SINCE(5, 0)
191 KTEXTWIDGETS_DEPRECATED_VERSION(5, 0, "Use QTextEdit::setPlaceholderText(const QString&)")
192 inline void setClickMessage(const QString &msg)
193 {
194 setPlaceholderText(msg);
195 }
196#endif
197
198#if KTEXTWIDGETS_ENABLE_DEPRECATED_SINCE(5, 0)
203 KTEXTWIDGETS_DEPRECATED_VERSION(5, 0, "Use QTextEdit::placeholderText()")
204 inline QString clickMessage() const
205 {
206 return placeholderText();
207 }
208#endif
209
213 void showTabAction(bool show);
214
218 void showAutoCorrectButton(bool show);
219
226
227Q_SIGNALS:
234
239 void spellCheckStatus(const QString &);
240
248 void languageChanged(const QString &language);
249
263 void aboutToShowContextMenu(QMenu *menu);
264
268 void spellCheckerAutoCorrect(const QString &currentWord, const QString &autoCorrectWord);
269
275
281
282public Q_SLOTS:
283
292 void setSpellCheckingLanguage(const QString &language);
293
299
313 void showSpellConfigDialog(const QString &windowIcon = QString());
314
319 void replace();
320
325 void addTextDecorator(Sonnet::SpellCheckDecorator *decorator);
326
332
333protected Q_SLOTS:
338 void slotReplaceNext();
339 void slotDoFind();
340 void slotFind();
341 void slotFindNext();
346 void slotReplace();
351
352protected:
356 bool event(QEvent *) override;
357
361 void keyPressEvent(QKeyEvent *) override;
362
367 void focusInEvent(QFocusEvent *) override;
368
373 virtual void deleteWordBack();
374
379 virtual void deleteWordForward();
380
385 void contextMenuEvent(QContextMenuEvent *) override;
386
387protected:
388 KTEXTWIDGETS_NO_EXPORT KTextEdit(KTextEditPrivate &dd, const QString &text, QWidget *parent);
389 KTEXTWIDGETS_NO_EXPORT KTextEdit(KTextEditPrivate &dd, QWidget *parent);
390
391private:
392 friend class KRichTextEdit;
393 friend class KRichTextWidget;
394 Q_DECLARE_PRIVATE_D(d, KTextEdit)
395 std::unique_ptr<class KTextEditPrivate> const d;
396 // KF6 TODO: change private d to protected d_ptr, use normal Q_DECLARE_PRIVATE, remove friend
397};
398
399#endif // KTEXTEDIT_H
The KRichTextEdit class provides a widget to edit and display rich text.
Definition krichtextedit.h:51
A KRichTextEdit with common actions.
Definition krichtextwidget.h:40
A KDE'ified QTextEdit.
Definition ktextedit.h:46
void forceSpellChecking()
void clearDecorator()
clearDecorator clear the spellcheckerdecorator
virtual void setCheckSpellingEnabled(bool check)
Turns background spell checking for this text edit on or off.
void setSpellCheckingLanguage(const QString &language)
Set the spell check language which will be used for highlighting spelling mistakes and for the spellc...
virtual QMenu * mousePopupMenu()
Return standard KTextEdit popupMenu.
void slotSpeakText()
void checkSpelling()
Show a dialog to check the spelling.
void slotDoReplace()
void addTextDecorator(Sonnet::SpellCheckDecorator *decorator)
Add custom spell checker decorator.
void spellCheckingCanceled()
signal spellCheckingCanceled is sent when we cancel spell checking.
virtual void deleteWordBack()
Deletes a word backwards from the current cursor position, if available.
void showSpellConfigDialog(const QString &windowIcon=QString())
Opens a Sonnet::ConfigDialog for this text edit.
void highlightWord(int length, int pos)
Selects the characters at the specified position.
virtual bool shouldBlockBeSpellChecked(const QString &block) const
Returns true if the given paragraph or block should be spellcheck.
virtual bool checkSpellingEnabled() const
Returns true if background spell checking is enabled for this text edit.
KTextEdit(const QString &text, QWidget *parent=nullptr)
Constructs a KTextEdit object.
void replace()
Create replace dialogbox.
void enableFindReplace(bool enabled)
Enable find replace action.
void showAutoCorrectButton(bool show)
~KTextEdit() override
Destroys the KTextEdit object.
virtual void deleteWordForward()
Deletes a word forwards from the current cursor position, if available.
bool event(QEvent *) override
Reimplemented to catch "delete word" shortcut events.
virtual void createHighlighter()
Allows to create a specific highlighter if reimplemented.
void contextMenuEvent(QContextMenuEvent *) override
Reimplemented from QTextEdit to add spelling related items when appropriate.
void keyPressEvent(QKeyEvent *) override
Reimplemented for internal reasons.
void spellCheckingFinished()
signal spellCheckingFinished is sent when we finish spell check or we click on "Terminate" button in ...
void focusInEvent(QFocusEvent *) override
Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
const QString & spellCheckingLanguage() const
KTextEdit(QWidget *parent=nullptr)
Constructs a KTextEdit object.
void showTabAction(bool show)
void spellCheckerAutoCorrect(const QString &currentWord, const QString &autoCorrectWord)
void slotFindPrevious()
void setHighlighter(Sonnet::Highlighter *_highLighter)
Sets a custom background spell highlighter for this text edit.
void checkSpellingChanged(bool)
emit signal when we activate or not autospellchecking
void spellCheckStatus(const QString &)
Signal sends when spell checking is finished/stopped/completed.
void aboutToShowContextMenu(QMenu *menu)
Emitted before the context menu is displayed.
Sonnet::Highlighter * highlighter() const
Returns the current highlighter, which is 0 if spell checking is disabled.
virtual void setReadOnly(bool readOnly)
Reimplemented to set a proper "deactivated" background color.
void languageChanged(const QString &language)
Emitted when the user changes the language in the spellcheck dialog shown by checkSpelling() or when ...