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 spellcheckdecorator.h <Sonnet/SpellCheckDecorator>
27 *
28 * @short Connects a Sonnet::Highlighter to a QTextEdit extending the context menu
29 * of the text edit with spell check suggestions
30 * @author Aurélien Gâteau <agateau@kde.org>
31 * @since 5.0
32 **/
33
34class SONNETUI_EXPORT SpellCheckDecorator : public QObject
35{
36 Q_OBJECT
37public:
38 /**
39 * Creates a spell-check decorator.
40 *
41 * @param textEdit the QTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
42 */
43 explicit SpellCheckDecorator(QTextEdit *textEdit);
44
45 /**
46 * Creates a spell-check decorator.
47 *
48 * @param textEdit the QPlainTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
49 * @since 5.12
50 */
51 explicit SpellCheckDecorator(QPlainTextEdit *textEdit);
52
53 ~SpellCheckDecorator() override;
54
55 /**
56 * Set a custom highlighter on the decorator.
57 *
58 * SpellCheckDecorator does not take ownership of the new highlighter,
59 * and you must manually delete the old highlighter.
60 */
61 void setHighlighter(Highlighter *highlighter);
62
63 /**
64 * Returns the hightlighter used by the decorator
65 */
66 Highlighter *highlighter() const;
67
68protected:
69 bool eventFilter(QObject *obj, QEvent *event) override;
70
71 /**
72 * Returns true if the spell checking should be enabled for a given block of text
73 * The default implementation always returns true.
74 */
75 virtual bool isSpellCheckingEnabledForBlock(const QString &textBlock) const;
76
77private:
78 friend SpellCheckDecoratorPrivate;
79 const std::unique_ptr<SpellCheckDecoratorPrivate> d;
80
81 Q_DISABLE_COPY(SpellCheckDecorator)
82};
83}
84
85#endif /* SPELLCHECKDECORATOR_H */
86

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