File indexing completed on 2024-12-22 04:28:08

0001 /*
0002   SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "autocorrectionsettings.h"
0010 #include "textautocorrectioncore_export.h"
0011 #include <QTextCursor>
0012 
0013 namespace TextAutoCorrectionCore
0014 {
0015 class AutoCorrectionPrivate;
0016 /**
0017  * @brief The AutoCorrection class
0018  * @author Laurent Montel <montel@kde.org>
0019  */
0020 class TEXTAUTOCORRECTIONCORE_EXPORT AutoCorrection
0021 {
0022 public:
0023     AutoCorrection();
0024     ~AutoCorrection();
0025 
0026     void writeConfig();
0027     void readConfig();
0028 
0029     bool autocorrect(bool htmlMode, QTextDocument &document, int &position);
0030 
0031     void loadGlobalFileName(const QString &fname);
0032 
0033     [[nodiscard]] AutoCorrectionSettings *autoCorrectionSettings() const;
0034     void setAutoCorrectionSettings(AutoCorrectionSettings *newAutoCorrectionSettings);
0035 
0036     void writeAutoCorrectionXmlFile(const QString &filename);
0037 
0038 private:
0039     TEXTAUTOCORRECTIONCORE_NO_EXPORT void fixTwoUppercaseChars();
0040     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT bool singleSpaces() const;
0041     TEXTAUTOCORRECTIONCORE_NO_EXPORT void capitalizeWeekDays();
0042     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT bool autoFractions() const;
0043     TEXTAUTOCORRECTIONCORE_NO_EXPORT void uppercaseFirstCharOfSentence();
0044     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT int advancedAutocorrect();
0045     TEXTAUTOCORRECTIONCORE_NO_EXPORT void replaceTypographicQuotes();
0046     TEXTAUTOCORRECTIONCORE_NO_EXPORT void superscriptAppendix();
0047     TEXTAUTOCORRECTIONCORE_NO_EXPORT void addNonBreakingSpace();
0048 
0049     TEXTAUTOCORRECTIONCORE_NO_EXPORT void selectPreviousWord(QTextCursor &cursor, int cursorPosition);
0050     TEXTAUTOCORRECTIONCORE_NO_EXPORT void selectStringOnMaximumSearchString(QTextCursor &cursor, int cursorPosition);
0051 
0052     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT bool autoFormatURLs();
0053     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT bool autoBoldUnderline();
0054 
0055     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT QString autoDetectURL(const QString &_word) const;
0056     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT bool excludeToUppercase(const QString &word) const;
0057     [[nodiscard]] TEXTAUTOCORRECTIONCORE_NO_EXPORT QColor linkColor();
0058     friend class AutoCorrectionPrivate;
0059     std::unique_ptr<AutoCorrectionPrivate> const d;
0060 };
0061 }