File indexing completed on 2024-04-21 04:00:58

0001 /*
0002  * spellcheckdecorator.h
0003  *
0004  * SPDX-FileCopyrightText: 2013 Aurélien Gâteau <agateau@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-or-later
0007  */
0008 #ifndef SPELLCHECKDECORATOR_H
0009 #define SPELLCHECKDECORATOR_H
0010 
0011 #include <QObject>
0012 
0013 #include <memory>
0014 
0015 #include "sonnetui_export.h"
0016 
0017 class QTextEdit;
0018 class QPlainTextEdit;
0019 
0020 namespace Sonnet
0021 {
0022 class SpellCheckDecoratorPrivate;
0023 class Highlighter;
0024 
0025 /**
0026  * @class Sonnet::SpellCheckDecorator spellcheckdecorator.h <Sonnet/SpellCheckDecorator>
0027  *
0028  * @short Connects a Sonnet::Highlighter to a QTextEdit extending the context menu
0029  * of the text edit with spell check suggestions
0030  * @author Aurélien Gâteau <agateau@kde.org>
0031  * @since 5.0
0032  **/
0033 
0034 class SONNETUI_EXPORT SpellCheckDecorator : public QObject
0035 {
0036     Q_OBJECT
0037 public:
0038     /**
0039      * Creates a spell-check decorator.
0040      *
0041      * @param textEdit the QTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
0042      */
0043     explicit SpellCheckDecorator(QTextEdit *textEdit);
0044 
0045     /**
0046      * Creates a spell-check decorator.
0047      *
0048      * @param textEdit the QPlainTextEdit in need of spell-checking. It also is used as the QObject parent for the decorator.
0049      * @since 5.12
0050      */
0051     explicit SpellCheckDecorator(QPlainTextEdit *textEdit);
0052 
0053     ~SpellCheckDecorator() override;
0054 
0055     /**
0056      * Set a custom highlighter on the decorator.
0057      *
0058      * SpellCheckDecorator does not take ownership of the new highlighter,
0059      * and you must manually delete the old highlighter.
0060      */
0061     void setHighlighter(Highlighter *highlighter);
0062 
0063     /**
0064      * Returns the hightlighter used by the decorator
0065      */
0066     Highlighter *highlighter() const;
0067 
0068 protected:
0069     bool eventFilter(QObject *obj, QEvent *event) override;
0070 
0071     /**
0072      * Returns true if the spell checking should be enabled for a given block of text
0073      * The default implementation always returns true.
0074      */
0075     virtual bool isSpellCheckingEnabledForBlock(const QString &textBlock) const;
0076 
0077 private:
0078     friend SpellCheckDecoratorPrivate;
0079     const std::unique_ptr<SpellCheckDecoratorPrivate> d;
0080 
0081     Q_DISABLE_COPY(SpellCheckDecorator)
0082 };
0083 }
0084 
0085 #endif /* SPELLCHECKDECORATOR_H */