Pimcommon

autocorrection.h
1 /*
2  SPDX-FileCopyrightText: 2012-2020 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef AutoCorrection_H
8 #define AutoCorrection_H
9 
10 #include "pimcommon_export.h"
11 #include <QTextCursor>
12 #include <QHash>
13 #include <QSet>
14 
15 namespace PimCommon {
20 class PIMCOMMON_EXPORT AutoCorrection
21 {
22 public:
23  struct TypographicQuotes {
24  QChar begin;
25  QChar end;
26  };
27 
28  explicit AutoCorrection();
29  ~AutoCorrection();
30 
31  void setLanguage(const QString &lang, bool forceGlobal = false);
32  void setEnabledAutoCorrection(bool b);
33  void setUppercaseFirstCharOfSentence(bool b);
34  void setFixTwoUppercaseChars(bool b);
35  void setSingleSpaces(bool b);
36  void setAutoFractions(bool b);
37  void setCapitalizeWeekDays(bool b);
38  void setReplaceDoubleQuotes(bool b);
39  void setReplaceSingleQuotes(bool b);
40  void setAdvancedAutocorrect(bool b);
41  void setTypographicSingleQuotes(TypographicQuotes singleQuote);
42  void setTypographicDoubleQuotes(TypographicQuotes doubleQuote);
43  void setUpperCaseExceptions(const QSet<QString> &exceptions);
44  void setTwoUpperLetterExceptions(const QSet<QString> &exceptions);
45  void setAutocorrectEntries(const QHash<QString, QString> &entries);
46  void setAutoFormatUrl(bool b);
47  void setAutoBoldUnderline(bool b);
48  void setSuperScript(bool b);
49  void setAddNonBreakingSpace(bool b);
50 
51  Q_REQUIRED_RESULT bool isEnabledAutoCorrection() const;
52  Q_REQUIRED_RESULT bool isUppercaseFirstCharOfSentence() const;
53  Q_REQUIRED_RESULT bool isFixTwoUppercaseChars() const;
54  Q_REQUIRED_RESULT bool isSingleSpaces() const;
55  Q_REQUIRED_RESULT bool isAutoFractions() const;
56  Q_REQUIRED_RESULT bool isCapitalizeWeekDays() const;
57  Q_REQUIRED_RESULT bool isReplaceDoubleQuotes() const;
58  Q_REQUIRED_RESULT bool isReplaceSingleQuotes() const;
59  Q_REQUIRED_RESULT bool isAdvancedAutocorrect() const;
60  Q_REQUIRED_RESULT bool isAutoFormatUrl() const;
61  Q_REQUIRED_RESULT bool isAutoBoldUnderline() const;
62  Q_REQUIRED_RESULT bool isSuperScript() const;
63 
64  Q_REQUIRED_RESULT bool isAddNonBreakingSpace() const;
65 
66  Q_REQUIRED_RESULT QString language() const;
67  Q_REQUIRED_RESULT TypographicQuotes typographicSingleQuotes() const;
68  Q_REQUIRED_RESULT TypographicQuotes typographicDoubleQuotes() const;
69  Q_REQUIRED_RESULT TypographicQuotes typographicDefaultSingleQuotes() const;
70  Q_REQUIRED_RESULT TypographicQuotes typographicDefaultDoubleQuotes() const;
71  Q_REQUIRED_RESULT QSet<QString> upperCaseExceptions() const;
72  Q_REQUIRED_RESULT QSet<QString> twoUpperLetterExceptions() const;
73  Q_REQUIRED_RESULT QHash<QString, QString> autocorrectEntries() const;
74 
75  bool autocorrect(bool htmlMode, QTextDocument &document, int &position);
76  void writeConfig();
77 
78  Q_REQUIRED_RESULT bool addAutoCorrect(const QString &currentWord, const QString &replaceWord);
79 
80  void writeAutoCorrectionXmlFile(const QString &filename = QString());
81 
82  void setNonBreakingSpace(QChar nonBreakingSpace);
83 
84  void loadGlobalFileName(const QString &fname, bool forceGlobal);
85  void loadLocalFileName(const QString &localFileName, const QString &fname);
86 private:
87  bool isFrenchLanguage() const;
88  void readConfig();
89 
90  void fixTwoUppercaseChars();
91  bool singleSpaces();
92  void capitalizeWeekDays();
93  bool autoFractions();
94  void uppercaseFirstCharOfSentence();
95  int advancedAutocorrect();
96  void replaceTypographicQuotes();
97  void superscriptAppendix();
98  void addNonBreakingSpace();
99 
100  void selectPreviousWord(QTextCursor &cursor, int cursorPosition);
101  void selectStringOnMaximumSearchString(QTextCursor &cursor, int cursorPosition);
102 
103  bool autoFormatURLs();
104  bool autoBoldUnderline();
105 
106  QString autoDetectURL(const QString &_word) const;
107  void readAutoCorrectionXmlFile(bool forceGlobal = false);
108  bool excludeToUppercase(const QString &word) const;
109  QColor linkColor();
110 
111  bool mSingleSpaces = true; // suppress double spaces.
112  bool mUppercaseFirstCharOfSentence = false; // convert first letter of a sentence automaticall to uppercase
113  bool mFixTwoUppercaseChars = false; // convert two uppercase characters to one upper and one lowercase.
114  bool mAutoFractions = true; // replace 1/2 with ½
115  bool mCapitalizeWeekDays = false;
116  bool mAdvancedAutocorrect = false; // autocorrection from a list of entries
117 
118  bool mReplaceDoubleQuotes = false; // replace double quotes with typographical quotes
119  bool mReplaceSingleQuotes = false; // replace single quotes with typographical quotes
120 
121  bool mAutoFormatUrl = false;
122  bool mAutoBoldUnderline = false;
123  bool mEnabled = false;
124  bool mSuperScriptAppendix = false;
125 
126  bool mAddNonBreakingSpace = false;
127  int mMaxFindStringLenght = 0;
128  int mMinFindStringLenght = 0;
129  QString mWord;
130  QTextCursor mCursor;
131  QChar mNonBreakingSpace;
132 
133  QString mAutoCorrectLang;
134  QStringList mCacheNameOfDays;
135  QSet<QString> mUpperCaseExceptions;
136  QSet<QString> mTwoUpperLetterExceptions;
137  QHash<QString, QString> mAutocorrectEntries;
138  QHash<QString, QString> mSuperScriptEntries;
139  TypographicQuotes mTypographicSingleQuotes;
140  TypographicQuotes mTypographicDoubleQuotes;
141  QColor mLinkColor;
142 };
143 }
144 
145 #endif // AutoCorrection_H
folderdialogacltab.h
The AutoCorrection class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 23:17:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.