Warning, file /frameworks/sonnet/src/core/backgroundchecker.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * backgroundchecker.h
0003  *
0004  * SPDX-FileCopyrightText: 2004 Zack Rusin <zack@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-or-later
0007  */
0008 #ifndef SONNET_BACKGROUNDCHECKER_H
0009 #define SONNET_BACKGROUNDCHECKER_H
0010 
0011 #include "speller.h"
0012 
0013 #include "sonnetcore_export.h"
0014 
0015 #include <QObject>
0016 
0017 #include <memory>
0018 
0019 /**
0020  * The sonnet namespace.
0021  */
0022 namespace Sonnet
0023 {
0024 class BackgroundCheckerPrivate;
0025 class Speller;
0026 
0027 /**
0028  * @class Sonnet::BackgroundChecker backgroundchecker.h <Sonnet/BackgroundChecker>
0029  *
0030  * BackgroundChecker is used to perform spell checking without
0031  * blocking the application. You can use it as is by calling
0032  * the checkText function or subclass it and reimplement
0033  * getMoreText function.
0034  *
0035  * The misspelling signal is emitted whenever a misspelled word
0036  * is found. The background checker stops right before emitting
0037  * the signal. So the parent has to call continueChecking function
0038  * to resume the checking.
0039  *
0040  * done signal is emitted when whole text is spell checked.
0041  *
0042  * @author Zack Rusin <zack@kde.org>
0043  * @short class used for spell checking in the background
0044  */
0045 class SONNETCORE_EXPORT BackgroundChecker : public QObject
0046 {
0047     Q_OBJECT
0048 public:
0049     explicit BackgroundChecker(QObject *parent = nullptr);
0050     explicit BackgroundChecker(const Speller &speller, QObject *parent = nullptr);
0051     ~BackgroundChecker() override;
0052 
0053     /**
0054      * This method is used to spell check static text.
0055      * It automatically invokes start().
0056      *
0057      * Use fetchMoreText() with start() to spell check a stream.
0058      */
0059     void setText(const QString &text);
0060     QString text() const;
0061 
0062     QString currentContext() const;
0063 
0064     Speller speller() const;
0065     void setSpeller(const Speller &speller);
0066 
0067     bool checkWord(const QString &word);
0068     QStringList suggest(const QString &word) const;
0069     bool addWordToPersonal(const QString &word);
0070 
0071     /**
0072      * This method is used to add a word to the session of the
0073      * speller currently set in BackgroundChecker.
0074      *
0075      * @since 5.55
0076      */
0077     bool addWordToSession(const QString &word);
0078 
0079     /**
0080      * Returns whether the automatic language detection is disabled,
0081      * overriding the Sonnet settings.
0082      *
0083      * @return true if the automatic language detection is disabled
0084      * @since 5.71
0085      */
0086     bool autoDetectLanguageDisabled() const;
0087 
0088     /**
0089      * Sets whether to disable the automatic language detection.
0090      *
0091      * @param autoDetectDisabled if true, the language will not be
0092      * detected automatically by the spell checker, even if the option
0093      * is enabled in the Sonnet settings.
0094      * @since 5.71
0095      */
0096     void setAutoDetectLanguageDisabled(bool autoDetectDisabled);
0097 
0098 public Q_SLOTS:
0099     virtual void start();
0100     virtual void stop();
0101     void replace(int start, const QString &oldText, const QString &newText);
0102     void changeLanguage(const QString &lang);
0103 
0104     /**
0105      * After emitting misspelling signal the background
0106      * checker stops. The catcher is responsible for calling
0107      * continueChecking function to resume checking.
0108      */
0109     virtual void continueChecking();
0110 
0111 Q_SIGNALS:
0112     /**
0113      * Emitted whenever a misspelled word is found
0114      */
0115     void misspelling(const QString &word, int start);
0116 
0117     /**
0118      * Emitted after the whole text has been spell checked.
0119      */
0120     void done();
0121 
0122 protected:
0123     /**
0124      * This function is called to get the text to spell check.
0125      * It will be called continuesly until it returns QString()
0126      * in which case the done() signal is emitted.
0127      * Note: the start parameter in misspelling() is not a combined
0128      * position but a position in the last string returned
0129      * by fetchMoreText. You need to store the state in the derivatives.
0130      */
0131     virtual QString fetchMoreText();
0132 
0133     /**
0134      * This function will be called whenever the background checker
0135      * will be finished text which it got from fetchMoreText.
0136      */
0137     virtual void finishedCurrentFeed();
0138 
0139 protected Q_SLOTS:
0140     void slotEngineDone();
0141 
0142 private:
0143     std::unique_ptr<BackgroundCheckerPrivate> const d;
0144 };
0145 }
0146 
0147 #endif