Sonnet

speller.h
1 /*
2  * SPDX-FileCopyrightText: 2007 Zack Rusin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 #ifndef SONNET_SPELLER_H
7 #define SONNET_SPELLER_H
8 
9 #include <QMap>
10 #include <QString>
11 #include <QStringList>
12 
13 #include "sonnetcore_export.h"
14 
15 namespace Sonnet
16 {
17 class SpellerPrivate;
18 /**
19  * @class Sonnet::Speller speller.h <Sonnet/Speller>
20  *
21  * Spell checker object.
22  *
23  * @short class used for actual spell checking
24  */
25 class SONNETCORE_EXPORT Speller
26 {
27 public:
28  explicit Speller(const QString &lang = QString());
29  ~Speller();
30 
31  Speller(const Speller &speller);
32  Speller &operator=(const Speller &speller);
33 
34  /**
35  * @return @c true if the speller supports currently selected
36  * language.
37  */
38  bool isValid() const;
39 
40  /**
41  * Sets the language supported by this speller.
42  */
43  void setLanguage(const QString &lang);
44 
45  /**
46  * @return language supported by this speller.
47  */
48  QString language() const;
49 
50  /**
51  * Checks the given word.
52  * @return false if the word is misspelled. true otherwise
53  */
54  bool isCorrect(const QString &word) const;
55 
56  /**
57  * Checks the given word.
58  * @return true if the word is misspelled. false otherwise
59  */
60  bool isMisspelled(const QString &word) const;
61 
62  /**
63  * Fetches suggestions for the word.
64  *
65  * @return list of all suggestions for the word
66  */
67  QStringList suggest(const QString &word) const;
68 
69  /**
70  * Convenience method calling isCorrect() and suggest()
71  * if the word isn't correct.
72  */
73  bool checkAndSuggest(const QString &word, QStringList &suggestions) const;
74 
75  /**
76  * Stores user defined good replacement for the bad word.
77  * @return @c true on success
78  */
79  bool storeReplacement(const QString &bad, const QString &good);
80 
81  /**
82  * Adds word to the list of of personal words.
83  * @return true on success
84  */
85  bool addToPersonal(const QString &word);
86 
87  /**
88  * Adds word to the words recognizable in the current session.
89  * @return true on success
90  */
91  bool addToSession(const QString &word);
92 
93 public: // Configuration API
94  enum Attribute {
95  CheckUppercase,
96  SkipRunTogether,
97  AutoDetectLanguage,
98  };
99  void save();
100  void restore();
101 
102  /**
103  * @return names of all supported backends (e.g. ISpell, ASpell)
104  */
105  QStringList availableBackends() const;
106 
107  /**
108  * @return a list of supported languages.
109  *
110  * Note: use availableDictionaries
111  */
112  QStringList availableLanguages() const;
113 
114  /**
115  * @return a localized list of names of supported languages.
116  *
117  * Note: use availableDictionaries
118  */
119  QStringList availableLanguageNames() const;
120 
121  /**
122  * @return a map of all available dictionaries with language descriptions and
123  * their codes. The key is the description, the code the value.
124  */
125  QMap<QString, QString> availableDictionaries() const;
126 
127  /**
128  * @return a map of user preferred dictionaries with language descriptions and
129  * their codes. The key is the description, the code the value.
130  * @since 5.54
131  */
132  QMap<QString, QString> preferredDictionaries() const;
133 
134  void setDefaultLanguage(const QString &lang);
135  QString defaultLanguage() const;
136 
137  void setDefaultClient(const QString &client);
138  QString defaultClient() const;
139 
140  void setAttribute(Attribute attr, bool b = true);
141  bool testAttribute(Attribute attr) const;
142 
143 private:
144  SpellerPrivate *const d;
145 };
146 }
147 #endif
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.