• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdespell2
 

tdespell2

  • tdespell2
  • ui
highlighter.cpp
1/*
2 * highlighter.cpp
3 *
4 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 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 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 */
21
22#include "highlighter.h"
23#include "broker.h"
24#include "dictionary.h"
25#include "settings.h"
26
27#include <tdeconfig.h>
28#include <kdebug.h>
29
30#include <tqtextedit.h>
31#include <tqtimer.h>
32#include <tqcolor.h>
33#include <tqdict.h>
34
35namespace KSpell2 {
36
37class Highlighter::Private
38{
39public:
40 Filter *filter;
41 Broker::Ptr broker;
42 Dictionary *dict;
43 TQDict<Dictionary> dictCache;
44};
45
46Highlighter::Highlighter( TQTextEdit *textEdit,
47 const TQString& configFile,
48 Filter *filter)
49 : TQSyntaxHighlighter( textEdit )
50{
51 d = new Private;
52 d->filter = filter;
53 if ( !configFile.isEmpty() )
54 d->broker = Broker::openBroker( TDESharedConfig::openConfig( configFile ) );
55 else
56 d->broker = Broker::openBroker();
57
58 d->filter->setSettings( d->broker->settings() );
59 d->dict = d->broker->dictionary();
60 Q_ASSERT( d->dict );
61 d->dictCache.insert( d->broker->settings()->defaultLanguage(),
62 d->dict );
63}
64
65Highlighter::~Highlighter()
66{
67 delete d; d = 0;
68}
69
70int Highlighter::highlightParagraph( const TQString& text,
71 int endStateOfLastPara )
72{
73 Q_UNUSED( endStateOfLastPara );
74 int para, index;
75 textEdit()->getCursorPosition( &para, &index );
76 const int lengthPosition = text.length() - 1;
77
78 if ( index != lengthPosition ||
79 ( lengthPosition > 0 && !text[lengthPosition-1].isLetter() ) ) {
80 d->filter->setBuffer( text );
81 Word w = d->filter->nextWord();
82 while ( !w.end ) {
83 if ( !d->dict->check( w.word ) ) {
84 setMisspelled( w.start, w.word.length() );
85 } else
86 unsetMisspelled( w.start, w.word.length() );
87 w = d->filter->nextWord();
88 }
89 }
90 //TQTimer::singleShot( 0, this, TQ_SLOT(checkWords()) );
91
92 return 0;
93}
94
95Filter *Highlighter::currentFilter() const
96{
97 return d->filter;
98}
99
100void Highlighter::setCurrentFilter( Filter *filter )
101{
102 d->filter = filter;
103 d->filter->setSettings( d->broker->settings() );
104}
105
106TQString Highlighter::currentLanguage() const
107{
108 return d->dict->language();
109}
110
111void Highlighter::setCurrentLanguage( const TQString& lang )
112{
113 if ( !d->dictCache.find( lang ) ) {
114 Dictionary *dict = d->broker->dictionary( lang );
115 if ( dict ) {
116 d->dictCache.insert( lang, dict );
117 } else {
118 kdDebug()<<"No dictionary for \""
119 <<lang
120 <<"\" staying with the current language."
121 <<endl;
122 return;
123 }
124 }
125 d->dict = d->dictCache[lang];
126}
127
128void Highlighter::setMisspelled( int start, int count )
129{
130 setFormat( start , count, TQt::red );
131}
132
133void Highlighter::unsetMisspelled( int start, int count )
134{
135 setFormat( start, count, TQt::black );
136}
137
138/*
139void Highlighter::checkWords()
140{
141 Word w = d->filter->nextWord();
142 if ( !w.end ) {
143 if ( !d->dict->check( w.word ) ) {
144 setFormat( w.start, w.word.length(),
145 TQt::red );
146 }
147 }
148}*/
149
150}
KSpell2
tdespell_hspellclient.h
Definition: backgroundchecker.h:29

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.9.4
This website is maintained by Timothy Pearson.