1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/* This file is part of the KDE libraries
Copyright (C) 1997 David Sweet <[email protected]>
Copyright (C) 2000 Rik Hemsley <[email protected]>
Copyright (C) 2000-2001 Wolfram Diestel <[email protected]>
Copyright (C) 2003 Zack Rusin <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqstringlist.h>
#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tdeapplication.h>
#include <tdelocale.h>
#include <tdelistbox.h>
#include <kcombobox.h>
#include <tdelistview.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kprogress.h>
#include <kbuttonbox.h>
#include <kdebug.h>
#include "ksconfig.h"
#include "tdespelldlg.h"
#include "tdespellui.h"
//to initially disable sorting in the suggestions listview
#define NONSORTINGCOLUMN 2
class KSpellDlg::KSpellDlgPrivate {
public:
KSpellUI* ui;
KSpellConfig* spellConfig;
};
KSpellDlg::KSpellDlg( TQWidget * parent, const char * name, bool _progressbar, bool _modal )
: KDialogBase(
parent, name, _modal, i18n("Check Spelling"), Help|Cancel|User1,
Cancel, true, i18n("&Finished")
),
progressbar( false )
{
Q_UNUSED( _progressbar );
d = new KSpellDlgPrivate;
d->ui = new KSpellUI( this );
setMainWidget( d->ui );
connect( d->ui->m_replaceBtn, TQT_SIGNAL(clicked()),
this, TQT_SLOT(replace()));
connect( this, TQT_SIGNAL(ready(bool)),
d->ui->m_replaceBtn, TQT_SLOT(setEnabled(bool)) );
connect( d->ui->m_replaceAllBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(replaceAll()));
connect(this, TQT_SIGNAL(ready(bool)), d->ui->m_replaceAllBtn, TQT_SLOT(setEnabled(bool)));
connect( d->ui->m_skipBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(ignore()));
connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_skipBtn, TQT_SLOT(setEnabled(bool)));
connect( d->ui->m_skipAllBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(ignoreAll()));
connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_skipAllBtn, TQT_SLOT(setEnabled(bool)));
connect( d->ui->m_addBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(add()));
connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_addBtn, TQT_SLOT(setEnabled(bool)));
connect( d->ui->m_suggestBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(suggest()));
connect( this, TQT_SIGNAL(ready(bool)), d->ui->m_suggestBtn, TQT_SLOT(setEnabled(bool)) );
d->ui->m_suggestBtn->hide();
connect(this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(stop()));
connect( d->ui->m_replacement, TQT_SIGNAL(textChanged(const TQString &)),
TQT_SLOT(textChanged(const TQString &)) );
connect( d->ui->m_replacement, TQT_SIGNAL(returnPressed()), TQT_SLOT(replace()) );
connect( d->ui->m_suggestions, TQT_SIGNAL(selectionChanged(TQListViewItem*)),
TQT_SLOT(slotSelectionChanged(TQListViewItem*)) );
connect( d->ui->m_suggestions, TQT_SIGNAL( doubleClicked ( TQListViewItem *, const TQPoint &, int ) ),
TQT_SLOT( replace() ) );
d->spellConfig = new KSpellConfig( 0, 0 ,0, false );
d->spellConfig->fillDicts( d->ui->m_language );
connect( d->ui->m_language, TQT_SIGNAL(activated(int)),
d->spellConfig, TQT_SLOT(sSetDictionary(int)) );
connect( d->spellConfig, TQT_SIGNAL(configChanged()),
TQT_SLOT(slotConfigChanged()) );
setHelp( "spelldlg", "tdespell" );
setMinimumSize( sizeHint() );
emit ready( false );
}
KSpellDlg::~KSpellDlg()
{
delete d->spellConfig;
delete d;
}
void
KSpellDlg::init( const TQString & _word, TQStringList * _sugg )
{
sugg = _sugg;
word = _word;
d->ui->m_suggestions->clear();
d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
for ( TQStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
TQListViewItem *item = new TQListViewItem( d->ui->m_suggestions,
d->ui->m_suggestions->lastItem() );
item->setText( 0, *it );
}
kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl;
emit ready( true );
d->ui->m_unknownWord->setText( _word );
if ( sugg->count() == 0 ) {
d->ui->m_replacement->setText( _word );
d->ui->m_replaceBtn->setEnabled( false );
d->ui->m_replaceAllBtn->setEnabled( false );
d->ui->m_suggestBtn->setEnabled( false );
} else {
d->ui->m_replacement->setText( (*sugg)[0] );
d->ui->m_replaceBtn->setEnabled( true );
d->ui->m_replaceAllBtn->setEnabled( true );
d->ui->m_suggestBtn->setEnabled( false );
d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true );
}
}
void
KSpellDlg::init( const TQString& _word, TQStringList* _sugg,
const TQString& context )
{
sugg = _sugg;
word = _word;
d->ui->m_suggestions->clear();
d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
for ( TQStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
TQListViewItem *item = new TQListViewItem( d->ui->m_suggestions,
d->ui->m_suggestions->lastItem() );
item->setText( 0, *it );
}
kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl;
emit ready( true );
d->ui->m_unknownWord->setText( _word );
d->ui->m_contextLabel->setText( context );
if ( sugg->count() == 0 ) {
d->ui->m_replacement->setText( _word );
d->ui->m_replaceBtn->setEnabled( false );
d->ui->m_replaceAllBtn->setEnabled( false );
d->ui->m_suggestBtn->setEnabled( false );
} else {
d->ui->m_replacement->setText( (*sugg)[0] );
d->ui->m_replaceBtn->setEnabled( true );
d->ui->m_replaceAllBtn->setEnabled( true );
d->ui->m_suggestBtn->setEnabled( false );
d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true );
}
}
void
KSpellDlg::slotProgress( unsigned int p )
{
if (!progressbar)
return;
progbar->setValue( (int) p );
}
void
KSpellDlg::textChanged( const TQString & )
{
d->ui->m_replaceBtn->setEnabled( true );
d->ui->m_replaceAllBtn->setEnabled( true );
d->ui->m_suggestBtn->setEnabled( true );
}
void
KSpellDlg::slotSelectionChanged( TQListViewItem* item )
{
if ( item )
d->ui->m_replacement->setText( item->text( 0 ) );
}
/*
exit functions
*/
void
KSpellDlg::closeEvent( TQCloseEvent * )
{
cancel();
}
void
KSpellDlg::done( int result )
{
emit command( result );
}
void
KSpellDlg::ignore()
{
newword = word;
done( KS_IGNORE );
}
void
KSpellDlg::ignoreAll()
{
newword = word;
done( KS_IGNOREALL );
}
void
KSpellDlg::add()
{
newword = word;
done( KS_ADD );
}
void
KSpellDlg::cancel()
{
newword = word;
done( KS_CANCEL );
}
void
KSpellDlg::replace()
{
newword = d->ui->m_replacement->text();
done( KS_REPLACE );
}
void
KSpellDlg::stop()
{
newword = word;
done( KS_STOP );
}
void
KSpellDlg::replaceAll()
{
newword = d->ui->m_replacement->text();
done( KS_REPLACEALL );
}
void
KSpellDlg::suggest()
{
newword = d->ui->m_replacement->text();
done( KS_SUGGEST );
}
void
KSpellDlg::slotConfigChanged()
{
d->spellConfig->writeGlobalSettings();
done( KS_CONFIG );
}
#include "tdespelldlg.moc"
|