Sonnet

settings.h
1 /*
2  * SPDX-FileCopyrightText: 2020 Benjamin Port <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 #ifndef SONNET_SETTINGS_H
7 #define SONNET_SETTINGS_H
8 
9 #include <QAbstractListModel>
10 #include <QString>
11 #include <QStringList>
12 #include <QtCore/QObject>
13 
14 #include "sonnetcore_export.h"
15 
16 namespace Sonnet
17 {
18 class Loader;
19 class SettingsPrivate;
20 
21 class SONNETCORE_EXPORT Settings : public QObject
22 {
23  Q_OBJECT
24  /// This property holds whether Sonnet should skip checkign words starting with an uppercase letter.
25  Q_PROPERTY(bool skipUppercase READ skipUppercase WRITE setSkipUppercase NOTIFY skipUppercaseChanged)
26  /// This property holds whether Sonnet should autodetect language.
27  Q_PROPERTY(bool autodetectLanguage READ autodetectLanguage WRITE setAutodetectLanguage NOTIFY autodetectLanguageChanged)
28  /// This property holds whether Sonnet should run spellchecking checks in the background.
29  Q_PROPERTY(bool backgroundCheckerEnabled READ backgroundCheckerEnabled WRITE setBackgroundCheckerEnabled NOTIFY backgroundCheckerEnabledChanged)
30  /// This property holds whether Sonnet should be enabled by default.
31  Q_PROPERTY(bool checkerEnabledByDefault READ checkerEnabledByDefault WRITE setCheckerEnabledByDefault NOTIFY checkerEnabledByDefaultChanged)
32  /// This property holds whether Sonnet should skip checking compounds words.
33  Q_PROPERTY(bool skipRunTogether READ skipRunTogether WRITE setSkipRunTogether NOTIFY skipRunTogetherChanged)
34  /// This property holds the list of ignored words.
35  Q_PROPERTY(QStringList currentIgnoreList READ currentIgnoreList WRITE setCurrentIgnoreList NOTIFY currentIgnoreListChanged)
36  /// This property holds the list of preferred languages.
37  Q_PROPERTY(QStringList preferredLanguages READ preferredLanguages WRITE setPreferredLanguages NOTIFY preferredLanguagesChanged)
38  /// This property holds the default language for spell checking.
39  Q_PROPERTY(QString defaultLanguage READ defaultLanguage WRITE setDefaultLanguage NOTIFY defaultLanguageChanged)
40 
41  /// This property holds a Qt Model containing all the preferred dictionaries
42  /// with language description and theirs codes. This model makes the
43  /// Qt::DisplayRole as well as the roles defined in \ref DictionaryRoles
44  /// available.
45  /// \since 5.88
46  Q_PROPERTY(QAbstractListModel *dictionaryModel READ dictionaryModel CONSTANT)
47 
48  Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged)
49 
50 public:
51  /// Roles for \ref dictionaryModel
52  enum DictionaryRoles {
53  LanguageCodeRole = Qt::UserRole + 1, //< Language code of the language. This uses "languageCode" as roleNames.
54  PreferredRole, //< This role holds whether the language is one of the preferred languages. This uses "isPreferred" as roleNames.
55  DefaultRole //< This role holds whether the language is the default language. This uses "isDefault" as roleNames.
56  };
57 
58  explicit Settings(QObject *parent = nullptr);
59  ~Settings() override;
60 
61  void setDefaultLanguage(const QString &lang);
62  QString defaultLanguage() const;
63 
64  void setPreferredLanguages(const QStringList &lang);
65  QStringList preferredLanguages() const;
66 
67  void setDefaultClient(const QString &client);
68  QString defaultClient() const;
69 
70  void setSkipUppercase(bool);
71  bool skipUppercase() const;
72 
73  void setAutodetectLanguage(bool);
74  bool autodetectLanguage() const;
75 
76  void setSkipRunTogether(bool);
77  bool skipRunTogether() const;
78 
79  void setBackgroundCheckerEnabled(bool);
80  bool backgroundCheckerEnabled() const;
81 
82  void setCheckerEnabledByDefault(bool);
83  bool checkerEnabledByDefault() const;
84 
85  void setCurrentIgnoreList(const QStringList &ignores);
86  QStringList currentIgnoreList() const;
87 
88  QStringList clients() const;
89  bool modified() const;
90 
91  QAbstractListModel *dictionaryModel();
92 
93  Q_INVOKABLE void save();
94 
95  static QStringList defaultIgnoreList();
96  static bool defaultSkipUppercase();
97  static bool defaultAutodetectLanguage();
98  static bool defaultBackgroundCheckerEnabled();
99  static bool defaultCheckerEnabledByDefault();
100  static bool defauktSkipRunTogether();
101  static QString defaultDefaultLanguage();
102  static QStringList defaultPreferredLanguages();
103 
104 Q_SIGNALS:
105  void skipUppercaseChanged();
106  void autodetectLanguageChanged();
107  void backgroundCheckerEnabledChanged();
108  void defaultClientChanged();
109  void defaultLanguageChanged();
110  void preferredLanguagesChanged();
111  void skipRunTogetherChanged();
112  void checkerEnabledByDefaultChanged();
113  void currentIgnoreListChanged();
114  void modifiedChanged();
115 
116 private:
117  friend class Loader;
118  SettingsPrivate *const d;
119 };
120 }
121 Q_DECLARE_METATYPE(QAbstractListModel *)
122 
123 #endif // SONNET_SETTINGS_H
UserRole
The sonnet namespace.
const QList< QKeySequence > & save()
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.