Sonnet

backgroundchecker.h
1 /*
2  * backgroundchecker.h
3  *
4  * SPDX-FileCopyrightText: 2004 Zack Rusin <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8 #ifndef SONNET_BACKGROUNDCHECKER_H
9 #define SONNET_BACKGROUNDCHECKER_H
10 
11 #include "speller.h"
12 
13 #include "sonnetcore_export.h"
14 
15 #include <QObject>
16 class BackgroundCheckerPrivate;
17 
18 /**
19  * The sonnet namespace.
20  */
21 namespace Sonnet
22 {
23 class Speller;
24 
25 /**
26  * @class Sonnet::BackgroundChecker backgroundchecker.h <Sonnet/BackgroundChecker>
27  *
28  * BackgroundChecker is used to perform spell checking without
29  * blocking the application. You can use it as is by calling
30  * the checkText function or subclass it and reimplement
31  * getMoreText function.
32  *
33  * The misspelling signal is emitted whenever a misspelled word
34  * is found. The background checker stops right before emitting
35  * the signal. So the parent has to call continueChecking function
36  * to resume the checking.
37  *
38  * done signal is emitted when whole text is spell checked.
39  *
40  * @author Zack Rusin <[email protected]>
41  * @short class used for spell checking in the background
42  */
43 class SONNETCORE_EXPORT BackgroundChecker : public QObject
44 {
45  Q_OBJECT
46 public:
47  explicit BackgroundChecker(QObject *parent = nullptr);
48  explicit BackgroundChecker(const Speller &speller, QObject *parent = nullptr);
49  ~BackgroundChecker() override;
50 
51  /**
52  * This method is used to spell check static text.
53  * It automatically invokes start().
54  *
55  * Use fetchMoreText() with start() to spell check a stream.
56  */
57  void setText(const QString &text);
58  QString text() const;
59 
60  QString currentContext() const;
61 
62  Speller speller() const;
63  void setSpeller(const Speller &speller);
64 
65  bool checkWord(const QString &word);
66  QStringList suggest(const QString &word) const;
67  bool addWordToPersonal(const QString &word);
68 
69  /**
70  * This method is used to add a word to the session of the
71  * speller currently set in BackgroundChecker.
72  *
73  * @since 5.55
74  */
75  bool addWordToSession(const QString &word);
76 
77  /**
78  * Returns whether the automatic language detection is disabled,
79  * overriding the Sonnet settings.
80  *
81  * @return true if the automatic language detection is disabled
82  * @since 5.71
83  */
84  bool autoDetectLanguageDisabled() const;
85 
86  /**
87  * Sets whether to disable the automatic language detection.
88  *
89  * @param autoDetectDisabled if true, the language will not be
90  * detected automatically by the spell checker, even if the option
91  * is enabled in the Sonnet settings.
92  * @since 5.71
93  */
94  void setAutoDetectLanguageDisabled(bool autoDetectDisabled);
95 
96 public Q_SLOTS:
97  virtual void start();
98  virtual void stop();
99  void replace(int start, const QString &oldText, const QString &newText);
100  void changeLanguage(const QString &lang);
101 
102  /**
103  * After emitting misspelling signal the background
104  * checker stops. The catcher is responsible for calling
105  * continueChecking function to resume checking.
106  */
107  virtual void continueChecking();
108 
109 Q_SIGNALS:
110  /**
111  * Emitted whenever a misspelled word is found
112  */
113  void misspelling(const QString &word, int start);
114 
115  /**
116  * Emitted after the whole text has been spell checked.
117  */
118  void done();
119 
120 protected:
121  /**
122  * This function is called to get the text to spell check.
123  * It will be called continuesly until it returns QString()
124  * in which case the done() signal is emitted.
125  * Note: the start parameter in misspelling() is not a combined
126  * position but a position in the last string returned
127  * by fetchMoreText. You need to store the state in the derivatives.
128  */
129  virtual QString fetchMoreText();
130 
131  /**
132  * This function will be called whenever the background checker
133  * will be finished text which it got from fetchMoreText.
134  */
135  virtual void finishedCurrentFeed();
136 
137 protected Q_SLOTS:
138  void slotEngineDone();
139 
140 private:
141  BackgroundCheckerPrivate *const d;
142 };
143 }
144 
145 #endif
class used for spell checking in the background
void stop(Ekos::AlignState mode)
Q_SCRIPTABLE Q_NOREPLY void start()
class used for actual spell checking
Definition: speller.h:25
The sonnet namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:14:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.