Kate
ontheflycheck.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2008-2010 by Michel Ludwig <michel.ludwig@kdemail.net> 00004 * Copyright (C) 2009 by Joseph Wenninger <jowenn@kde.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef ONTHEFLYCHECK_H 00023 #define ONTHEFLYCHECK_H 00024 00025 #include <QList> 00026 #include <QMap> 00027 #include <QObject> 00028 #include <QPair> 00029 #include <QString> 00030 #include <QSet> 00031 00032 #include <sonnet/speller.h> 00033 00034 #include "katedocument.h" 00035 00036 namespace Sonnet { 00037 class BackgroundChecker; 00038 } 00039 00040 class KateOnTheFlyChecker : public QObject, private KTextEditor::MovingRangeFeedback { 00041 Q_OBJECT 00042 00043 enum ModificationType {TEXT_INSERTED = 0, TEXT_REMOVED}; 00044 00045 typedef QPair<KTextEditor::MovingRange*, QString> SpellCheckItem; 00046 typedef QList<KTextEditor::MovingRange*> MovingRangeList; 00047 typedef QPair<KTextEditor::MovingRange*, QString> MisspelledItem; 00048 typedef QList<MisspelledItem> MisspelledList; 00049 00050 typedef QPair<ModificationType, KTextEditor::MovingRange*> ModificationItem; 00051 typedef QList<ModificationItem> ModificationList; 00052 00053 public: 00054 KateOnTheFlyChecker(KateDocument *document); 00055 ~KateOnTheFlyChecker(); 00056 00057 static int debugArea(); 00058 00059 QPair<KTextEditor::Range, QString> getMisspelledItem(const KTextEditor::Cursor &cursor) const; 00060 QString dictionaryForMisspelledRange(const KTextEditor::Range& range) const; 00061 00062 void clearMisspellingForWord(const QString& word); 00063 00064 public Q_SLOTS: 00065 void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range); 00066 void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range); 00067 00068 void updateConfig(); 00069 void refreshSpellCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid()); 00070 00071 void updateInstalledMovingRanges(KateView *view); 00072 00073 protected: 00074 KateDocument *const m_document; 00075 Sonnet::Speller m_speller; 00076 QList<SpellCheckItem> m_spellCheckQueue; 00077 Sonnet::BackgroundChecker *m_backgroundChecker; 00078 SpellCheckItem m_currentlyCheckedItem; 00079 static const SpellCheckItem invalidSpellCheckQueueItem; 00080 MisspelledList m_misspelledList; 00081 ModificationList m_modificationList; 00082 KateDocument::OffsetList m_currentDecToEncOffsetList; 00083 QMap<KTextEditor::View*, KTextEditor::Range> m_displayRangeMap; 00084 00085 void freeDocument(); 00086 00087 MovingRangeList installedMovingRanges(const KTextEditor::Range& range); 00088 00089 void queueLineSpellCheck(KateDocument *document, int line); 00093 void queueLineSpellCheck(const KTextEditor::Range& range, const QString& dictionary); 00094 void queueSpellCheckVisibleRange(const KTextEditor::Range& range); 00095 void queueSpellCheckVisibleRange(KateView *view, const KTextEditor::Range& range); 00096 00097 void addToSpellCheckQueue(const KTextEditor::Range& range, const QString& dictionary); 00098 void addToSpellCheckQueue(KTextEditor::MovingRange *range, const QString& dictionary); 00099 00100 QTimer *m_viewRefreshTimer; 00101 QPointer<KateView> m_refreshView; 00102 00103 virtual void removeRangeFromEverything(KTextEditor::MovingRange *range); 00104 bool removeRangeFromCurrentSpellCheck(KTextEditor::MovingRange *range); 00105 bool removeRangeFromSpellCheckQueue(KTextEditor::MovingRange *range); 00106 virtual void rangeEmpty(KTextEditor::MovingRange *range); 00107 virtual void rangeInvalid (KTextEditor::MovingRange* range); 00108 virtual void mouseEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view); 00109 virtual void mouseExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view); 00110 virtual void caretEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view); 00111 virtual void caretExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view); 00112 00113 KTextEditor::Range findWordBoundaries(const KTextEditor::Cursor& begin, 00114 const KTextEditor::Cursor& end); 00115 00116 void deleteMovingRange(KTextEditor::MovingRange *range); 00117 void deleteMovingRanges(const QList<KTextEditor::MovingRange*>& list); 00118 void deleteMovingRangeQuickly(KTextEditor::MovingRange *range); 00119 void stopCurrentSpellCheck(); 00120 00121 protected Q_SLOTS: 00122 void performSpellCheck(); 00123 void misspelling(const QString &word, int start); 00124 void spellCheckDone(); 00125 00126 void viewDestroyed(QObject* obj); 00127 void addView(KTextEditor::Document *document, KTextEditor::View *view); 00128 void removeView(KTextEditor::View *view); 00129 00130 void restartViewRefreshTimer(KateView *view); 00131 void viewRefreshTimeout(); 00132 00133 void handleModifiedRanges(); 00134 void handleInsertedText(const KTextEditor::Range &range); 00135 void handleRemovedText(const KTextEditor::Range &range); 00136 void handleRespellCheckBlock(KateDocument *document, int start, int end); 00137 bool removeRangeFromModificationList(KTextEditor::MovingRange *range); 00138 void clearModificationList(); 00139 }; 00140 00141 #endif 00142 00143 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference