Pimcommon

autocorrection.h
1 /*
2  SPDX-FileCopyrightText: 2012-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "pimcommon_export.h"
10 #include <QHash>
11 #include <QSet>
12 #include <QTextCursor>
13 
14 namespace PimCommon
15 {
16 /**
17  * @brief The AutoCorrection class
18  * @author Laurent Montel <[email protected]>
19  */
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 
87 private:
88  Q_REQUIRED_RESULT bool isFrenchLanguage() const;
89  void readConfig();
90 
91  void fixTwoUppercaseChars();
92  Q_REQUIRED_RESULT bool singleSpaces();
93  void capitalizeWeekDays();
94  Q_REQUIRED_RESULT bool autoFractions();
95  void uppercaseFirstCharOfSentence();
96  Q_REQUIRED_RESULT int advancedAutocorrect();
97  void replaceTypographicQuotes();
98  void superscriptAppendix();
99  void addNonBreakingSpace();
100 
101  void selectPreviousWord(QTextCursor &cursor, int cursorPosition);
102  void selectStringOnMaximumSearchString(QTextCursor &cursor, int cursorPosition);
103 
104  Q_REQUIRED_RESULT bool autoFormatURLs();
105  Q_REQUIRED_RESULT bool autoBoldUnderline();
106 
107  Q_REQUIRED_RESULT QString autoDetectURL(const QString &_word) const;
108  void readAutoCorrectionXmlFile(bool forceGlobal = false);
109  Q_REQUIRED_RESULT bool excludeToUppercase(const QString &word) const;
110  Q_REQUIRED_RESULT QColor linkColor();
111 
112  bool mSingleSpaces = true; // suppress double spaces.
113  bool mUppercaseFirstCharOfSentence = false; // convert first letter of a sentence automatically to uppercase
114  bool mFixTwoUppercaseChars = false; // convert two uppercase characters to one upper and one lowercase.
115  bool mAutoFractions = true; // replace 1/2 with ½
116  bool mCapitalizeWeekDays = false;
117  bool mAdvancedAutocorrect = false; // autocorrection from a list of entries
118 
119  bool mReplaceDoubleQuotes = false; // replace double quotes with typographical quotes
120  bool mReplaceSingleQuotes = false; // replace single quotes with typographical quotes
121 
122  bool mAutoFormatUrl = false;
123  bool mAutoBoldUnderline = false;
124  bool mEnabled = false;
125  bool mSuperScriptAppendix = false;
126 
127  bool mAddNonBreakingSpace = false;
128  int mMaxFindStringLenght = 0;
129  int mMinFindStringLenght = 0;
130  QString mWord;
131  QTextCursor mCursor;
132  QChar mNonBreakingSpace;
133 
134  QString mAutoCorrectLang;
135  QStringList mCacheNameOfDays;
136  QSet<QString> mUpperCaseExceptions;
137  QSet<QString> mTwoUpperLetterExceptions;
138  QHash<QString, QString> mAutocorrectEntries;
139  QHash<QString, QString> mSuperScriptEntries;
140  TypographicQuotes mTypographicSingleQuotes;
141  TypographicQuotes mTypographicDoubleQuotes;
142  QColor mLinkColor;
143 };
144 }
folderdialogacltab.h
The AutoCorrection class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 04:03:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.