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