Kate
ontheflycheck.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ONTHEFLYCHECK_H
00022 #define ONTHEFLYCHECK_H
00023
00024 #include <QList>
00025 #include <QMap>
00026 #include <QObject>
00027 #include <QPair>
00028 #include <QString>
00029
00030 #include <ktexteditor/document.h>
00031 #include <ktexteditor/rangefeedback.h>
00032 #include <sonnet/backgroundchecker.h>
00033 #include <sonnet/speller.h>
00034
00035 #include "katedocument.h"
00036 #include "kateview.h"
00037
00038 class KateOnTheFlyChecker : public QObject, private KTextEditor::SmartRangeWatcher {
00039 Q_OBJECT
00040
00041 enum ModificationType {TEXT_INSERTED = 0, TEXT_REMOVED};
00042
00043 typedef QPair<KTextEditor::SmartRange*, QString> SpellCheckItem;
00044 typedef QList<KTextEditor::SmartRange*> SmartRangeList;
00045 typedef QPair<KTextEditor::SmartRange*, QString> MisspelledItem;
00046 typedef QList<MisspelledItem> MisspelledList;
00047
00048 typedef QPair<ModificationType, KTextEditor::SmartRange*> ModificationItem;
00049 typedef QList<ModificationItem> ModificationList;
00050
00051 public:
00052 KateOnTheFlyChecker(KateDocument *document);
00053 ~KateOnTheFlyChecker();
00054
00055 static int debugArea();
00056
00057 QPair<KTextEditor::Range, QString> getMisspelledItem(const KTextEditor::Cursor &cursor) const;
00058 QString dictionaryForMisspelledRange(const KTextEditor::Range& range) const;
00059
00060 void clearMisspellingForWord(const QString& word);
00061
00062 public Q_SLOTS:
00063 void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range);
00064 void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range);
00065
00066 void updateConfig();
00067 void refreshSpellCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid());
00068
00069 void updateInstalledSmartRanges(KateView *view);
00070 void updateInstalledSmartRanges();
00071
00072 protected:
00073 KateDocument *const m_document;
00074 Sonnet::Speller m_speller;
00075 QList<SpellCheckItem> m_spellCheckQueue;
00076 Sonnet::BackgroundChecker *m_backgroundChecker;
00077 SpellCheckItem m_currentlyCheckedItem;
00078 static const SpellCheckItem invalidSpellCheckQueueItem;
00079 MisspelledList m_misspelledList;
00080 SmartRangeList m_installedSmartRangeList;
00081 ModificationList m_modificationList;
00082 KateDocument::OffsetList m_currentDecToEncOffsetList;
00083
00084 void freeDocument();
00085
00086 SmartRangeList installedSmartRanges(const KTextEditor::Range& range);
00087
00088 void installSmartRange(KTextEditor::SmartRange *smartRange);
00089
00090 void queueLineSpellCheck(KateDocument *document, int line);
00094 void queueLineSpellCheck(const KTextEditor::Range& range, const QString& dictionary);
00095 void queueSpellCheckVisibleRange(const KTextEditor::Range& range);
00096 void queueSpellCheckVisibleRange(KateView *view, const KTextEditor::Range& range);
00097
00098 void addToSpellCheckQueue(const KTextEditor::Range& range, const QString& dictionary);
00099 void addToSpellCheckQueue(KTextEditor::SmartRange *range, const QString& dictionary);
00100
00101 QTimer *m_viewRefreshTimer;
00102 QPointer<KateView> m_refreshView;
00103
00104 virtual void rangeDeleted(KTextEditor::SmartRange *range);
00105 bool removeRangeFromCurrentSpellCheck(KTextEditor::SmartRange *range);
00106 bool removeRangeFromSpellCheckQueue(KTextEditor::SmartRange *range);
00107 virtual void rangeEliminated(KTextEditor::SmartRange *range);
00108 virtual void mouseEnteredRange(KTextEditor::SmartRange *range, KTextEditor::View *view);
00109 virtual void mouseExitedRange(KTextEditor::SmartRange *range, KTextEditor::View *view);
00110
00111 QList<KTextEditor::SmartRange*> m_eliminatedRanges;
00112
00113 QMap<KTextEditor::View*, KTextEditor::Range> m_displayRangeMap;
00114 QList<KTextEditor::SmartRange*> m_myranges;
00115 KTextEditor::Range findWordBoundaries(const KTextEditor::Cursor& begin,
00116 const KTextEditor::Cursor& end);
00117
00118 void deleteSmartRangeLater(KTextEditor::SmartRange *range);
00119 void deleteSmartRangesLater(const QList<KTextEditor::SmartRange*>& list);
00120 void stopCurrentSpellCheck();
00121
00122 protected Q_SLOTS:
00123 void performSpellCheck();
00124 void misspelling(const QString &word, int start);
00125 void spellCheckDone();
00126
00127 void viewDestroyed(QObject* obj);
00128 void addView(KTextEditor::Document *document, KTextEditor::View *view);
00129 void removeView(KTextEditor::View *view);
00130
00131 void restartViewRefreshTimer(KateView *view);
00132 void viewRefreshTimeout();
00133
00134 void deleteEliminatedRanges();
00135
00136 void handleModifiedRanges();
00137 void handleInsertedText(const KTextEditor::Range &range);
00138 void handleRemovedText(const KTextEditor::Range &range);
00139 void handleRespellCheckBlock(KateDocument *document, int start, int end);
00140 bool removeRangeFromModificationList(KTextEditor::SmartRange *range);
00141 void clearModificationList();
00142 };
00143
00144 #endif
00145
00146