• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

ontheflycheck.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2008-2009 by Michel Ludwig (michel.ludwig@kdemail.net)
00003  * Copyright (C) 2009 by Joseph Wenninger (jowenn@kde.org)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal