1/*
2 * spellcheckdecorator.h
3 *
4 * SPDX-FileCopyrightText: 2013 Aurélien Gâteau <agateau@kde.org>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8#ifndef SPELLCHECKDECORATOR_H
9#define SPELLCHECKDECORATOR_H
10
11#include <QObject>
12
13#include <memory>
14
15#include "sonnetui_export.h"
16
17class QTextEdit;
18class QPlainTextEdit;
19
20namespace Sonnet
21{
22class SpellCheckDecoratorPrivate;
23class Highlighter;
24
25/*!
26 * \class Sonnet::SpellCheckDecorator
27 * \inheaderfile Sonnet/SpellCheckDecorator
28 * \inmodule KF6Sonnet
29 *
30 * \brief Connects a Sonnet::Highlighter to a QTextEdit extending the context menu
31 * of the text edit with spell check suggestions.
32 * \since 5.0
33 */
34
35class SONNETUI_EXPORT SpellCheckDecorator : public QObject
36{
37 Q_OBJECT
38public:
39 /*!
40 * Creates a spell-check decorator.
41 *
42 * \a textEdit the QTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
43 */
44 explicit SpellCheckDecorator(QTextEdit *textEdit);
45
46 /*!
47 * Creates a spell-check decorator.
48 *
49 * \a textEdit the QPlainTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
50 * \since 5.12
51 */
52 explicit SpellCheckDecorator(QPlainTextEdit *textEdit);
53
54 ~SpellCheckDecorator() override;
55
56 /*!
57 * Set a custom highlighter on the decorator.
58 *
59 * SpellCheckDecorator does not take ownership of the new highlighter,
60 * and you must manually delete the old highlighter.
61 */
62 void setHighlighter(Highlighter *highlighter);
63
64 /*!
65 * Returns the hightlighter used by the decorator
66 */
67 Highlighter *highlighter() const;
68
69protected:
70 bool eventFilter(QObject *obj, QEvent *event) override;
71
72 /*!
73 * Returns true if the spell checking should be enabled for a given block of text
74 * The default implementation always returns true.
75 */
76 virtual bool isSpellCheckingEnabledForBlock(const QString &textBlock) const;
77
78private:
79 friend SpellCheckDecoratorPrivate;
80 const std::unique_ptr<SpellCheckDecoratorPrivate> d;
81
82 Q_DISABLE_COPY(SpellCheckDecorator)
83};
84}
85
86#endif /* SPELLCHECKDECORATOR_H */
87

source code of sonnet/src/ui/spellcheckdecorator.h