• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • spellcheck
ontheflycheck.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2008-2010 by Michel Ludwig <michel.ludwig@kdemail.net>
4  * Copyright (C) 2009 by Joseph Wenninger <jowenn@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef ONTHEFLYCHECK_H
23 #define ONTHEFLYCHECK_H
24 
25 #include <QList>
26 #include <QMap>
27 #include <QObject>
28 #include <QPair>
29 #include <QString>
30 #include <QSet>
31 
32 #include <sonnet/speller.h>
33 
34 #include "katedocument.h"
35 
36 namespace Sonnet {
37  class BackgroundChecker;
38 }
39 
40 class KateOnTheFlyChecker : public QObject, private KTextEditor::MovingRangeFeedback {
41  Q_OBJECT
42 
43  enum ModificationType {TEXT_INSERTED = 0, TEXT_REMOVED};
44 
45  typedef QPair<KTextEditor::MovingRange*, QString> SpellCheckItem;
46  typedef QList<KTextEditor::MovingRange*> MovingRangeList;
47  typedef QPair<KTextEditor::MovingRange*, QString> MisspelledItem;
48  typedef QList<MisspelledItem> MisspelledList;
49 
50  typedef QPair<ModificationType, KTextEditor::MovingRange*> ModificationItem;
51  typedef QList<ModificationItem> ModificationList;
52 
53  public:
54  KateOnTheFlyChecker(KateDocument *document);
55  ~KateOnTheFlyChecker();
56 
57  static int debugArea();
58 
59  QPair<KTextEditor::Range, QString> getMisspelledItem(const KTextEditor::Cursor &cursor) const;
60  QString dictionaryForMisspelledRange(const KTextEditor::Range& range) const;
61 
62  void clearMisspellingForWord(const QString& word);
63 
64  public Q_SLOTS:
65  void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range);
66  void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range);
67 
68  void updateConfig();
69  void refreshSpellCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid());
70 
71  void updateInstalledMovingRanges(KateView *view);
72 
73  protected:
74  KateDocument *const m_document;
75  Sonnet::Speller m_speller;
76  QList<SpellCheckItem> m_spellCheckQueue;
77  Sonnet::BackgroundChecker *m_backgroundChecker;
78  SpellCheckItem m_currentlyCheckedItem;
79  static const SpellCheckItem invalidSpellCheckQueueItem;
80  MisspelledList m_misspelledList;
81  ModificationList m_modificationList;
82  KateDocument::OffsetList m_currentDecToEncOffsetList;
83  QMap<KTextEditor::View*, KTextEditor::Range> m_displayRangeMap;
84 
85  void freeDocument();
86 
87  MovingRangeList installedMovingRanges(const KTextEditor::Range& range);
88 
89  void queueLineSpellCheck(KateDocument *document, int line);
93  void queueLineSpellCheck(const KTextEditor::Range& range, const QString& dictionary);
94  void queueSpellCheckVisibleRange(const KTextEditor::Range& range);
95  void queueSpellCheckVisibleRange(KateView *view, const KTextEditor::Range& range);
96 
97  void addToSpellCheckQueue(const KTextEditor::Range& range, const QString& dictionary);
98  void addToSpellCheckQueue(KTextEditor::MovingRange *range, const QString& dictionary);
99 
100  QTimer *m_viewRefreshTimer;
101  QPointer<KateView> m_refreshView;
102 
103  virtual void removeRangeFromEverything(KTextEditor::MovingRange *range);
104  bool removeRangeFromCurrentSpellCheck(KTextEditor::MovingRange *range);
105  bool removeRangeFromSpellCheckQueue(KTextEditor::MovingRange *range);
106  virtual void rangeEmpty(KTextEditor::MovingRange *range);
107  virtual void rangeInvalid (KTextEditor::MovingRange* range);
108  virtual void mouseEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view);
109  virtual void mouseExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view);
110  virtual void caretEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view);
111  virtual void caretExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view);
112 
113  KTextEditor::Range findWordBoundaries(const KTextEditor::Cursor& begin,
114  const KTextEditor::Cursor& end);
115 
116  void deleteMovingRange(KTextEditor::MovingRange *range);
117  void deleteMovingRanges(const QList<KTextEditor::MovingRange*>& list);
118  void deleteMovingRangeQuickly(KTextEditor::MovingRange *range);
119  void stopCurrentSpellCheck();
120 
121  protected Q_SLOTS:
122  void performSpellCheck();
123  void misspelling(const QString &word, int start);
124  void spellCheckDone();
125 
126  void viewDestroyed(QObject* obj);
127  void addView(KTextEditor::Document *document, KTextEditor::View *view);
128  void removeView(KTextEditor::View *view);
129 
130  void restartViewRefreshTimer(KateView *view);
131  void viewRefreshTimeout();
132 
133  void handleModifiedRanges();
134  void handleInsertedText(const KTextEditor::Range &range);
135  void handleRemovedText(const KTextEditor::Range &range);
136  void handleRespellCheckBlock(int start, int end);
137  bool removeRangeFromModificationList(KTextEditor::MovingRange *range);
138  void clearModificationList();
139 };
140 
141 #endif
142 
143 // kate: space-indent on; indent-width 2; replace-tabs on;
KateOnTheFlyChecker::m_speller
Sonnet::Speller m_speller
Definition: ontheflycheck.h:75
KateOnTheFlyChecker::dictionaryForMisspelledRange
QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const
Definition: ontheflycheck.cpp:95
KateOnTheFlyChecker::getMisspelledItem
QPair< KTextEditor::Range, QString > getMisspelledItem(const KTextEditor::Cursor &cursor) const
Definition: ontheflycheck.cpp:84
KateOnTheFlyChecker::textInserted
void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:135
KateOnTheFlyChecker::removeRangeFromEverything
virtual void removeRangeFromEverything(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:418
KateOnTheFlyChecker::viewDestroyed
void viewDestroyed(QObject *obj)
Definition: ontheflycheck.cpp:698
KateOnTheFlyChecker::m_refreshView
QPointer< KateView > m_refreshView
Definition: ontheflycheck.h:101
KateOnTheFlyChecker::misspelling
void misspelling(const QString &word, int start)
Definition: ontheflycheck.cpp:597
KateOnTheFlyChecker::m_viewRefreshTimer
QTimer * m_viewRefreshTimer
Definition: ontheflycheck.h:100
KateOnTheFlyChecker::m_currentlyCheckedItem
SpellCheckItem m_currentlyCheckedItem
Definition: ontheflycheck.h:78
KateOnTheFlyChecker::m_misspelledList
MisspelledList m_misspelledList
Definition: ontheflycheck.h:80
QMap< KTextEditor::View *, KTextEditor::Range >
KateOnTheFlyChecker::m_currentDecToEncOffsetList
KateDocument::OffsetList m_currentDecToEncOffsetList
Definition: ontheflycheck.h:82
KateOnTheFlyChecker::handleInsertedText
void handleInsertedText(const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:168
QPointer< KateView >
katedocument.h
KateOnTheFlyChecker::removeView
void removeView(KTextEditor::View *view)
Definition: ontheflycheck.cpp:705
KateOnTheFlyChecker::stopCurrentSpellCheck
void stopCurrentSpellCheck()
Definition: ontheflycheck.cpp:453
KateOnTheFlyChecker::queueSpellCheckVisibleRange
void queueSpellCheckVisibleRange(const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:762
KateOnTheFlyChecker::m_backgroundChecker
Sonnet::BackgroundChecker * m_backgroundChecker
Definition: ontheflycheck.h:77
KateOnTheFlyChecker::findWordBoundaries
KTextEditor::Range findWordBoundaries(const KTextEditor::Cursor &begin, const KTextEditor::Cursor &end)
Definition: ontheflycheck.cpp:543
KateOnTheFlyChecker::handleModifiedRanges
void handleModifiedRanges()
Definition: ontheflycheck.cpp:888
QTimer
KateOnTheFlyChecker::updateInstalledMovingRanges
void updateInstalledMovingRanges(KateView *view)
Definition: ontheflycheck.cpp:711
QObject
KateOnTheFlyChecker::m_modificationList
ModificationList m_modificationList
Definition: ontheflycheck.h:81
KateOnTheFlyChecker::addView
void addView(KTextEditor::Document *document, KTextEditor::View *view)
Definition: ontheflycheck.cpp:688
KateOnTheFlyChecker::installedMovingRanges
MovingRangeList installedMovingRanges(const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:652
KateOnTheFlyChecker::handleRemovedText
void handleRemovedText(const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:268
KateOnTheFlyChecker::deleteMovingRanges
void deleteMovingRanges(const QList< KTextEditor::MovingRange * > &list)
Definition: ontheflycheck.cpp:536
KateOnTheFlyChecker::deleteMovingRangeQuickly
void deleteMovingRangeQuickly(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:879
KateOnTheFlyChecker::mouseExitedRange
virtual void mouseExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view)
Definition: ontheflycheck.cpp:502
QString
QList< KTextEditor::MovingRange * >
KateOnTheFlyChecker::m_spellCheckQueue
QList< SpellCheckItem > m_spellCheckQueue
Definition: ontheflycheck.h:76
QPair< KTextEditor::MovingRange *, QString >
KateView
Definition: kateview.h:77
KateOnTheFlyChecker::m_displayRangeMap
QMap< KTextEditor::View *, KTextEditor::Range > m_displayRangeMap
Definition: ontheflycheck.h:83
KateOnTheFlyChecker::textRemoved
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range)
Definition: ontheflycheck.cpp:230
KateOnTheFlyChecker::refreshSpellCheck
void refreshSpellCheck(const KTextEditor::Range &range=KTextEditor::Range::invalid())
Definition: ontheflycheck.cpp:677
KateDocument
Definition: katedocument.h:74
KateOnTheFlyChecker::restartViewRefreshTimer
void restartViewRefreshTimer(KateView *view)
Definition: ontheflycheck.cpp:870
KateOnTheFlyChecker::~KateOnTheFlyChecker
~KateOnTheFlyChecker()
Definition: ontheflycheck.cpp:73
KateOnTheFlyChecker::performSpellCheck
void performSpellCheck()
Definition: ontheflycheck.cpp:371
KateOnTheFlyChecker::invalidSpellCheckQueueItem
static const SpellCheckItem invalidSpellCheckQueueItem
Definition: ontheflycheck.h:79
KateOnTheFlyChecker::caretExitedRange
virtual void caretExitedRange(KTextEditor::MovingRange *range, KTextEditor::View *view)
Definition: ontheflycheck.cpp:518
KateOnTheFlyChecker::handleRespellCheckBlock
void handleRespellCheckBlock(int start, int end)
Definition: ontheflycheck.cpp:120
KateOnTheFlyChecker::spellCheckDone
void spellCheckDone()
Definition: ontheflycheck.cpp:637
KateOnTheFlyChecker::freeDocument
void freeDocument()
Definition: ontheflycheck.cpp:345
KateOnTheFlyChecker::clearMisspellingForWord
void clearMisspellingForWord(const QString &word)
Definition: ontheflycheck.cpp:106
KateOnTheFlyChecker::KateOnTheFlyChecker
KateOnTheFlyChecker(KateDocument *document)
Definition: ontheflycheck.cpp:40
KateOnTheFlyChecker::m_document
KateDocument *const m_document
Definition: ontheflycheck.h:74
KateOnTheFlyChecker::rangeInvalid
virtual void rangeInvalid(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:490
KateOnTheFlyChecker::queueLineSpellCheck
void queueLineSpellCheck(KateDocument *document, int line)
Definition: ontheflycheck.cpp:797
KateOnTheFlyChecker::viewRefreshTimeout
void viewRefreshTimeout()
Definition: ontheflycheck.cpp:862
KateOnTheFlyChecker::removeRangeFromModificationList
bool removeRangeFromModificationList(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:904
KateOnTheFlyChecker::debugArea
static int debugArea()
Definition: ontheflycheck.cpp:78
KateOnTheFlyChecker::clearModificationList
void clearModificationList()
Definition: ontheflycheck.cpp:921
KateOnTheFlyChecker::caretEnteredRange
virtual void caretEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view)
It is not enough to use 'caret/Entered/ExitedRange' only as the cursor doesn't move when some text ha...
Definition: ontheflycheck.cpp:512
KateOnTheFlyChecker::deleteMovingRange
void deleteMovingRange(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:524
KateOnTheFlyChecker::addToSpellCheckQueue
void addToSpellCheckQueue(const KTextEditor::Range &range, const QString &dictionary)
Definition: ontheflycheck.cpp:832
KateOnTheFlyChecker::rangeEmpty
virtual void rangeEmpty(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:484
KateOnTheFlyChecker
Definition: ontheflycheck.h:40
KateOnTheFlyChecker::mouseEnteredRange
virtual void mouseEnteredRange(KTextEditor::MovingRange *range, KTextEditor::View *view)
Definition: ontheflycheck.cpp:496
KateOnTheFlyChecker::removeRangeFromCurrentSpellCheck
bool removeRangeFromCurrentSpellCheck(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:443
KateOnTheFlyChecker::removeRangeFromSpellCheckQueue
bool removeRangeFromSpellCheckQueue(KTextEditor::MovingRange *range)
Definition: ontheflycheck.cpp:462
KateOnTheFlyChecker::updateConfig
void updateConfig()
Definition: ontheflycheck.cpp:667
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal