QtSpell 1.0.1
Spell checking for Qt text widgets
QtSpell.hpp
1/* QtSpell - Spell checking for Qt text widgets.
2 * Copyright (c) 2014-2022 Sandro Mani
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#ifndef QTSPELL_HPP
20#define QTSPELL_HPP
21
22#include "QtSpellExport.hpp"
23
24#include <QObject>
25
26class QMenu;
27class QPlainTextEdit;
28class QPoint;
29class QTextEdit;
30
34namespace QtSpell {
35
36class CheckerPrivate;
37class TextEditCheckerPrivate;
38
42bool QTSPELL_API checkLanguageInstalled(const QString& lang);
43
45
49class QTSPELL_API Checker : public QObject
50{
51 Q_OBJECT
52public:
56 Checker(QObject* parent = 0);
57
61 virtual ~Checker();
62
68 virtual void checkSpelling(int start = 0, int end = -1) = 0;
69
76 bool setLanguage(const QString& lang);
77
82 QString getLanguage() const;
83
89 void setDecodeLanguageCodes(bool decode);
90
95 bool getDecodeLanguageCodes() const;
96
101 void setShowCheckSpellingCheckbox(bool show);
102
107 bool getShowCheckSpellingCheckbox() const;
108
113 bool getSpellingEnabled() const;
114
119 void addWordToDictionary(const QString& word);
120
126 bool checkWord(const QString& word) const;
127
132 void ignoreWord(const QString& word) const;
133
139 QList<QString> getSpellingSuggestions(const QString& word) const;
140
141
146 static QList<QString> getLanguageList();
147
156 static QString decodeLanguageCode(const QString& lang);
157
158public slots:
163 void setSpellingEnabled(bool enabled);
164
165signals:
171 void languageChanged(const QString& newLang);
172
173protected:
174 void showContextMenu(QMenu* menu, const QPoint& pos, int wordPos);
175
176private slots:
177 void slotAddWord();
178 void slotIgnoreWord();
179 void slotReplaceWord();
180 void slotSetLanguage(bool checked);
181
182private:
190 virtual QString getWord(int pos, int* start = 0, int* end = 0) const = 0;
191
198 virtual void insertWord(int start, int end, const QString& word) = 0;
199
204 virtual bool isAttached() const = 0;
205
206protected:
207 Checker(CheckerPrivate& dd, QObject* parent = 0);
208 CheckerPrivate* d_ptr;
209
210private:
211 Q_DECLARE_PRIVATE(Checker)
212};
213
215
220class QTSPELL_API TextEditChecker : public Checker
221{
222 Q_OBJECT
223public:
227 TextEditChecker(QObject* parent = 0);
228
233
238 void setTextEdit(QTextEdit* textEdit);
239
244 void setTextEdit(QPlainTextEdit* textEdit);
245
255 void setNoSpellingPropertyId(int propertyId);
256
262 int noSpellingPropertyId() const;
263
264 void checkSpelling(int start = 0, int end = -1);
265
273 void setUndoRedoEnabled(bool enabled);
274
275public slots:
283 void undo();
290 void redo();
291
298 void clearUndoRedo();
299
300signals:
308 void undoAvailable(bool available);
309
317 void redoAvailable(bool available);
318
319private:
320 QString getWord(int pos, int* start = 0, int* end = 0) const;
321 void insertWord(int start, int end, const QString& word);
322 bool isAttached() const;
323 bool eventFilter(QObject *obj, QEvent *event);
324
325private slots:
326 void slotShowContextMenu(const QPoint& pos);
327 void slotCheckDocumentChanged();
328 void slotDetachTextEdit();
329 void slotCheckRange(int pos, int removed, int added);
330
331private:
332 Q_DECLARE_PRIVATE(TextEditChecker)
333};
334
335} // QtSpell
336
337#endif // QTSPELL_HPP
An abstract class providing spell checking support.
Definition QtSpell.hpp:50
virtual bool isAttached() const =0
Returns whether a widget is attached to the checker.
void languageChanged(const QString &newLang)
This signal is emitted when the user selects a new language from the spellchecker UI.
virtual void checkSpelling(int start=0, int end=-1)=0
Check the spelling.
virtual QString getWord(int pos, int *start=0, int *end=0) const =0
Get the word at the specified cursor position.
virtual void insertWord(int start, int end, const QString &word)=0
Replaces the specified range with the specified word.
Checker class for QTextEdit widgets.
Definition QtSpell.hpp:221
void redoAvailable(bool available)
Emitted when the redo stak changes.
void undoAvailable(bool available)
Emitted when the undo stack changes.
QtSpell namespace.
Definition Checker.cpp:77
bool checkLanguageInstalled(const QString &lang)
Check whether the dictionary for a language is installed.
Definition Checker.cpp:96