Sonnet

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

KDE's Doxygen guidelines are available online.