File indexing completed on 2024-04-21 03:57:42

0001 /*
0002     SPDX-FileCopyrightText: 2009-2010 Michel Ludwig <michel.ludwig@kdemail.net>
0003     SPDX-FileCopyrightText: 2008 Mirko Stocker <me@misto.ch>
0004     SPDX-FileCopyrightText: 2004-2005 Anders Lund <anders@alweb.dk>
0005     SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
0006     SPDX-FileCopyrightText: 2001-2004 Christoph Cullmann <cullmann@kde.org>
0007     SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org>
0008     SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
0009 
0010     SPDX-License-Identifier: LGPL-2.0-or-later
0011 */
0012 
0013 #ifndef KATE_SPELLCHECKDIALOG_H
0014 #define KATE_SPELLCHECKDIALOG_H
0015 
0016 #include <QObject>
0017 
0018 namespace KTextEditor
0019 {
0020 class ViewPrivate;
0021 }
0022 
0023 class QAction;
0024 class KActionCollection;
0025 
0026 namespace Sonnet
0027 {
0028 class BackgroundChecker;
0029 class Speller;
0030 }
0031 
0032 #include "ktexteditor/range.h"
0033 
0034 namespace KTextEditor
0035 {
0036 class MovingRange;
0037 }
0038 
0039 class SpellCheckBar;
0040 
0041 class KateSpellCheckDialog : public QObject
0042 {
0043     Q_OBJECT
0044 public:
0045     explicit KateSpellCheckDialog(KTextEditor::ViewPrivate *);
0046     ~KateSpellCheckDialog() override;
0047 
0048     void createActions(KActionCollection *);
0049 
0050     // spellcheck from cursor, selection
0051 private Q_SLOTS:
0052     void spellcheckFromCursor();
0053 
0054     // defined here in anticipation of per view selections ;)
0055     void spellcheckSelection();
0056 
0057     void spellcheck();
0058 
0059     /**
0060      * Spellcheck a defined portion of the text.
0061      *
0062      * @param from Where to start the check
0063      * @param to Where to end. If this is (0,0), it will be set to the end of the document.
0064      */
0065     void spellcheck(const KTextEditor::Cursor from, const KTextEditor::Cursor to = KTextEditor::Cursor());
0066 
0067     void misspelling(const QString &, int);
0068     void corrected(const QString &, int, const QString &);
0069 
0070     void performSpellCheck(KTextEditor::Range range);
0071     void installNextSpellCheckRange();
0072 
0073     void cancelClicked();
0074 
0075     void objectDestroyed(QObject *object);
0076 
0077     void languageChanged(const QString &language);
0078 
0079 private:
0080     KTextEditor::Cursor locatePosition(int pos);
0081 
0082     KTextEditor::ViewPrivate *m_view;
0083 
0084     Sonnet::Speller *m_speller;
0085     Sonnet::BackgroundChecker *m_backgroundChecker;
0086 
0087     SpellCheckBar *m_sonnetDialog;
0088 
0089     // define the part of the text that is to be checked
0090     KTextEditor::Range m_currentSpellCheckRange;
0091     KTextEditor::MovingRange *m_globalSpellCheckRange;
0092 
0093     QList<QPair<int, int>> m_currentDecToEncOffsetList;
0094 
0095     QList<QPair<KTextEditor::Range, QString>> m_languagesInSpellCheckRange;
0096     QList<QPair<KTextEditor::Range, QString>>::iterator m_currentLanguageRangeIterator;
0097 
0098     // keep track of where we are.
0099     KTextEditor::Cursor m_spellPosCursor;
0100     uint m_spellLastPos;
0101 
0102     bool m_spellCheckCancelledByUser;
0103 
0104     QString m_userSpellCheckLanguage, m_previousGivenSpellCheckLanguage;
0105 
0106     void spellCheckDone();
0107 };
0108 
0109 #endif