00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qstringlist.h>
00023 #include <qpushbutton.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026
00027 #include <kapplication.h>
00028 #include <klocale.h>
00029 #include <klistbox.h>
00030 #include <kcombobox.h>
00031 #include <klistview.h>
00032 #include <klineedit.h>
00033 #include <kpushbutton.h>
00034 #include <kprogress.h>
00035 #include <kbuttonbox.h>
00036 #include <kdebug.h>
00037
00038 #include "ksconfig.h"
00039 #include "kspelldlg.h"
00040 #include "kspellui.h"
00041
00042
00043 #define NONSORTINGCOLUMN 2
00044
00045 class KSpellDlg::KSpellDlgPrivate {
00046 public:
00047 KSpellUI* ui;
00048 KSpellConfig* spellConfig;
00049 };
00050
00051 KSpellDlg::KSpellDlg( QWidget * parent, const char * name, bool _progressbar, bool _modal )
00052 : KDialogBase(
00053 parent, name, _modal, i18n("Check Spelling"), Help|Cancel|User1,
00054 Cancel, true, i18n("&Finished")
00055 ),
00056 progressbar( false )
00057 {
00058 Q_UNUSED( _progressbar );
00059 d = new KSpellDlgPrivate;
00060 d->ui = new KSpellUI( this );
00061 setMainWidget( d->ui );
00062
00063 connect( d->ui->m_replaceBtn, SIGNAL(clicked()),
00064 this, SLOT(replace()));
00065 connect( this, SIGNAL(ready(bool)),
00066 d->ui->m_replaceBtn, SLOT(setEnabled(bool)) );
00067
00068 connect( d->ui->m_replaceAllBtn, SIGNAL(clicked()), this, SLOT(replaceAll()));
00069 connect(this, SIGNAL(ready(bool)), d->ui->m_replaceAllBtn, SLOT(setEnabled(bool)));
00070
00071 connect( d->ui->m_skipBtn, SIGNAL(clicked()), this, SLOT(ignore()));
00072 connect( this, SIGNAL(ready(bool)), d->ui->m_skipBtn, SLOT(setEnabled(bool)));
00073
00074 connect( d->ui->m_skipAllBtn, SIGNAL(clicked()), this, SLOT(ignoreAll()));
00075 connect( this, SIGNAL(ready(bool)), d->ui->m_skipAllBtn, SLOT(setEnabled(bool)));
00076
00077 connect( d->ui->m_addBtn, SIGNAL(clicked()), this, SLOT(add()));
00078 connect( this, SIGNAL(ready(bool)), d->ui->m_addBtn, SLOT(setEnabled(bool)));
00079
00080 connect( d->ui->m_suggestBtn, SIGNAL(clicked()), this, SLOT(suggest()));
00081 connect( this, SIGNAL(ready(bool)), d->ui->m_suggestBtn, SLOT(setEnabled(bool)) );
00082 d->ui->m_suggestBtn->hide();
00083
00084 connect(this, SIGNAL(user1Clicked()), this, SLOT(stop()));
00085
00086 connect( d->ui->m_replacement, SIGNAL(textChanged(const QString &)),
00087 SLOT(textChanged(const QString &)) );
00088
00089 connect( d->ui->m_replacement, SIGNAL(returnPressed()), SLOT(replace()) );
00090 connect( d->ui->m_suggestions, SIGNAL(selectionChanged(QListViewItem*)),
00091 SLOT(slotSelectionChanged(QListViewItem*)) );
00092
00093 connect( d->ui->m_suggestions, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ),
00094 SLOT( replace() ) );
00095 d->spellConfig = new KSpellConfig( 0, 0 ,0, false );
00096 d->spellConfig->fillDicts( d->ui->m_language );
00097 connect( d->ui->m_language, SIGNAL(activated(int)),
00098 d->spellConfig, SLOT(sSetDictionary(int)) );
00099 connect( d->spellConfig, SIGNAL(configChanged()),
00100 SLOT(slotConfigChanged()) );
00101
00102 setHelp( "spelldlg", "kspell" );
00103 setMinimumSize( sizeHint() );
00104 emit ready( false );
00105 }
00106
00107 KSpellDlg::~KSpellDlg()
00108 {
00109 delete d->spellConfig;
00110 delete d;
00111 }
00112
00113 void
00114 KSpellDlg::init( const QString & _word, QStringList * _sugg )
00115 {
00116 sugg = _sugg;
00117 word = _word;
00118
00119 d->ui->m_suggestions->clear();
00120 d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
00121 for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
00122 QListViewItem *item = new QListViewItem( d->ui->m_suggestions,
00123 d->ui->m_suggestions->lastItem() );
00124 item->setText( 0, *it );
00125 }
00126 kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl;
00127
00128 emit ready( true );
00129
00130 d->ui->m_unknownWord->setText( _word );
00131
00132 if ( sugg->count() == 0 ) {
00133 d->ui->m_replacement->setText( _word );
00134 d->ui->m_replaceBtn->setEnabled( false );
00135 d->ui->m_replaceAllBtn->setEnabled( false );
00136 d->ui->m_suggestBtn->setEnabled( false );
00137 } else {
00138 d->ui->m_replacement->setText( (*sugg)[0] );
00139 d->ui->m_replaceBtn->setEnabled( true );
00140 d->ui->m_replaceAllBtn->setEnabled( true );
00141 d->ui->m_suggestBtn->setEnabled( false );
00142 d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true );
00143 }
00144 }
00145
00146 void
00147 KSpellDlg::init( const QString& _word, QStringList* _sugg,
00148 const QString& context )
00149 {
00150 sugg = _sugg;
00151 word = _word;
00152
00153 d->ui->m_suggestions->clear();
00154 d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
00155 for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) {
00156 QListViewItem *item = new QListViewItem( d->ui->m_suggestions,
00157 d->ui->m_suggestions->lastItem() );
00158 item->setText( 0, *it );
00159 }
00160
00161 kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl;
00162
00163 emit ready( true );
00164
00165 d->ui->m_unknownWord->setText( _word );
00166 d->ui->m_contextLabel->setText( context );
00167
00168 if ( sugg->count() == 0 ) {
00169 d->ui->m_replacement->setText( _word );
00170 d->ui->m_replaceBtn->setEnabled( false );
00171 d->ui->m_replaceAllBtn->setEnabled( false );
00172 d->ui->m_suggestBtn->setEnabled( false );
00173 } else {
00174 d->ui->m_replacement->setText( (*sugg)[0] );
00175 d->ui->m_replaceBtn->setEnabled( true );
00176 d->ui->m_replaceAllBtn->setEnabled( true );
00177 d->ui->m_suggestBtn->setEnabled( false );
00178 d->ui->m_suggestions->setSelected( d->ui->m_suggestions->firstChild(), true );
00179 }
00180 }
00181
00182 void
00183 KSpellDlg::slotProgress( unsigned int p )
00184 {
00185 if (!progressbar)
00186 return;
00187
00188 progbar->setValue( (int) p );
00189 }
00190
00191 void
00192 KSpellDlg::textChanged( const QString & )
00193 {
00194 d->ui->m_replaceBtn->setEnabled( true );
00195 d->ui->m_replaceAllBtn->setEnabled( true );
00196 d->ui->m_suggestBtn->setEnabled( true );
00197 }
00198
00199 void
00200 KSpellDlg::slotSelectionChanged( QListViewItem* item )
00201 {
00202 if ( item )
00203 d->ui->m_replacement->setText( item->text( 0 ) );
00204 }
00205
00206
00207
00208
00209
00210 void
00211 KSpellDlg::closeEvent( QCloseEvent * )
00212 {
00213 cancel();
00214 }
00215
00216 void
00217 KSpellDlg::done( int result )
00218 {
00219 emit command( result );
00220 }
00221 void
00222 KSpellDlg::ignore()
00223 {
00224 newword = word;
00225 done( KS_IGNORE );
00226 }
00227
00228 void
00229 KSpellDlg::ignoreAll()
00230 {
00231 newword = word;
00232 done( KS_IGNOREALL );
00233 }
00234
00235 void
00236 KSpellDlg::add()
00237 {
00238 newword = word;
00239 done( KS_ADD );
00240 }
00241
00242
00243 void
00244 KSpellDlg::cancel()
00245 {
00246 newword = word;
00247 done( KS_CANCEL );
00248 }
00249
00250 void
00251 KSpellDlg::replace()
00252 {
00253 newword = d->ui->m_replacement->text();
00254 done( KS_REPLACE );
00255 }
00256
00257 void
00258 KSpellDlg::stop()
00259 {
00260 newword = word;
00261 done( KS_STOP );
00262 }
00263
00264 void
00265 KSpellDlg::replaceAll()
00266 {
00267 newword = d->ui->m_replacement->text();
00268 done( KS_REPLACEALL );
00269 }
00270
00271 void
00272 KSpellDlg::suggest()
00273 {
00274 newword = d->ui->m_replacement->text();
00275 done( KS_SUGGEST );
00276 }
00277
00278 void
00279 KSpellDlg::slotConfigChanged()
00280 {
00281 d->spellConfig->writeGlobalSettings();
00282 done( KS_CONFIG );
00283 }
00284
00285 #include "kspelldlg.moc"