22 #include "tdespell2ui.h"
24 #include "backgroundchecker.h"
27 #include "dictionary.h"
30 #include <tdeconfig.h>
31 #include <tdelocale.h>
34 #include <tqlistview.h>
35 #include <tqpushbutton.h>
36 #include <tqcombobox.h>
37 #include <tqlineedit.h>
46 #define NONSORTINGCOLUMN 2
52 TQString originalBuffer;
53 BackgroundChecker *checker;
56 TQMap<TQString, TQString> replaceAllMap;
59 Dialog::Dialog( BackgroundChecker *checker,
60 TQWidget *parent,
const char *name )
61 : KDialogBase( parent, name, true,
62 i18n(
"Check Spelling" ),
63 Help|Cancel|User1, Cancel, true,
72 setMainWidget(
static_cast<TQWidget*
>(d->ui) );
80 void Dialog::initConnections()
82 connect( d->ui->m_addBtn, TQ_SIGNAL(clicked()),
83 TQ_SLOT(slotAddWord()) );
84 connect( d->ui->m_replaceBtn, TQ_SIGNAL(clicked()),
85 TQ_SLOT(slotReplaceWord()) );
86 connect( d->ui->m_replaceAllBtn, TQ_SIGNAL(clicked()),
87 TQ_SLOT(slotReplaceAll()) );
88 connect( d->ui->m_skipBtn, TQ_SIGNAL(clicked()),
89 TQ_SLOT(slotSkip()) );
90 connect( d->ui->m_skipAllBtn, TQ_SIGNAL(clicked()),
91 TQ_SLOT(slotSkipAll()) );
92 connect( d->ui->m_suggestBtn, TQ_SIGNAL(clicked()),
93 TQ_SLOT(slotSuggest()) );
94 connect( d->ui->m_language, TQ_SIGNAL(activated(
const TQString&)),
95 TQ_SLOT(slotChangeLanguage(
const TQString&)) );
96 connect( d->ui->m_suggestions, TQ_SIGNAL(selectionChanged(TQListViewItem*)),
97 TQ_SLOT(slotSelectionChanged(TQListViewItem*)) );
98 connect( d->checker, TQ_SIGNAL(misspelling(
const TQString&,
int)),
99 TQ_SIGNAL(misspelling(
const TQString&,
int)) );
100 connect( d->checker, TQ_SIGNAL(misspelling(
const TQString&,
int)),
101 TQ_SLOT(slotMisspelling(
const TQString&,
int)) );
102 connect( d->checker, TQ_SIGNAL(done()),
103 TQ_SLOT(slotDone()) );
104 connect( d->ui->m_suggestions, TQ_SIGNAL(doubleClicked(TQListViewItem*,
const TQPoint&,
int)),
105 TQ_SLOT( slotReplaceWord() ) );
106 connect(
this, TQ_SIGNAL(user1Clicked()),
this, TQ_SLOT(slotFinished()) );
107 connect(
this, TQ_SIGNAL(cancelClicked()),
this, TQ_SLOT(slotCancel()) );
108 connect( d->ui->m_replacement, TQ_SIGNAL(returnPressed()),
this, TQ_SLOT(slotReplaceWord()) );
109 connect( d->ui->m_autoCorrect, TQ_SIGNAL(clicked()),
110 TQ_SLOT(slotAutocorrect()) );
113 d->ui->m_autoCorrect->hide();
116 void Dialog::initGui()
118 d->ui =
new KSpell2UI(
this );
119 d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
120 d->ui->m_language->clear();
121 d->ui->m_language->insertStringList( d->checker->broker()->languages() );
122 for (
int i = 0; !d->ui->m_language->text( i ).isNull(); ++i ) {
123 TQString ct = d->ui->m_language->text( i );
124 if ( ct == d->checker->broker()->settings()->defaultLanguage() ) {
125 d->ui->m_language->setCurrentItem( i );
131 void Dialog::activeAutoCorrect(
bool _active )
134 d->ui->m_autoCorrect->show();
136 d->ui->m_autoCorrect->hide();
139 void Dialog::slotAutocorrect()
141 kdDebug()<<
"void Dialog::slotAutocorrect()\n";
142 emit autoCorrect(d->currentWord.word, d->ui->m_replacement->text() );
146 void Dialog::slotFinished()
148 kdDebug()<<
"void Dialog::slotFinished() \n";
151 emit done( d->checker->filter()->buffer() );
155 void Dialog::slotCancel()
157 kdDebug()<<
"void Dialog::slotCancel() \n";
162 TQString Dialog::originalBuffer()
const
164 return d->originalBuffer;
167 TQString Dialog::buffer()
const
169 return d->checker->filter()->buffer();
172 void Dialog::setBuffer(
const TQString& buf )
174 d->originalBuffer = buf;
177 void Dialog::setFilter( Filter *filter )
179 filter->setBuffer( d->checker->filter()->buffer() );
180 d->checker->setFilter( filter );
183 void Dialog::updateDialog(
const TQString& word )
185 d->ui->m_unknownWord->setText( word );
186 d->ui->m_contextLabel->setText( d->checker->filter()->context() );
187 TQStringList suggs = d->checker->suggest( word );
188 d->ui->m_replacement->setText( suggs.first() );
189 fillSuggestions( suggs );
194 kdDebug()<<
"Showing dialog"<<endl;
195 if ( d->originalBuffer.isEmpty() )
198 d->checker->checkText( d->originalBuffer );
201 void Dialog::slotAddWord()
203 d->checker->addWord( d->currentWord.word );
204 d->checker->continueChecking();
207 void Dialog::slotReplaceWord()
209 emit replace( d->currentWord.word, d->currentWord.start,
210 d->ui->m_replacement->text() );
211 d->checker->filter()->replace( d->currentWord, d->ui->m_replacement->text() );
212 d->checker->continueChecking();
215 void Dialog::slotReplaceAll()
217 d->replaceAllMap.insert( d->currentWord.word,
218 d->ui->m_replacement->text() );
222 void Dialog::slotSkip()
224 d->checker->continueChecking();
227 void Dialog::slotSkipAll()
230 d->checker->broker()->settings()->addWordToIgnore( d->ui->m_replacement->text() );
231 d->checker->continueChecking();
234 void Dialog::slotSuggest()
236 TQStringList suggs = d->checker->suggest( d->ui->m_replacement->text() );
237 fillSuggestions( suggs );
240 void Dialog::slotChangeLanguage(
const TQString& lang )
242 d->checker->changeLanguage( lang );
246 void Dialog::slotSelectionChanged( TQListViewItem *item )
248 d->ui->m_replacement->setText( item->text( 0 ) );
251 void Dialog::fillSuggestions(
const TQStringList& suggs )
253 d->ui->m_suggestions->clear();
254 for ( TQStringList::ConstIterator it = suggs.begin(); it != suggs.end(); ++it ) {
255 new TQListViewItem( d->ui->m_suggestions, d->ui->m_suggestions->firstChild(),
260 void Dialog::slotMisspelling(
const TQString& word,
int start )
262 kdDebug()<<
"Dialog misspelling!!"<<endl;
263 d->currentWord = Word( word, start );
264 if ( d->replaceAllMap.contains( word ) ) {
265 d->ui->m_replacement->setText( d->replaceAllMap[ word ] );
268 updateDialog( word );
273 void Dialog::slotDone()
275 kdDebug()<<
"Dialog done!"<<endl;
276 emit done( d->checker->filter()->buffer() );
282 #include "dialog.moc"