lib Library API Documentation

koSpelldlg.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1997 David Sweet <dsweet@kde.org> 00003 Copyright (C) 2000 Rik Hemsley <rik@kde.org> 00004 Copyright (C) 2000-2001 Wolfram Diestel <wolfram@steloj.de> 00005 Copyright (C) 2002-2003 Laurent Montel <lmontel@mandrakesoft.com> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 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 <klineedit.h> 00031 #include <kbuttonbox.h> 00032 #include <kdebug.h> 00033 #include <qcombobox.h> 00034 #include <koSconfig.h> 00035 #include "koSpelldlg.h" 00036 #include <qcheckbox.h> 00037 00038 KOSpellDlg::KOSpellDlg( 00039 QWidget * parent, 00040 KOSpellConfig *_ksc, 00041 const char * name, 00042 int indexOfLanguage, 00043 bool _modal, 00044 bool _autocorrect 00045 ) 00046 : KDialogBase(parent, name, _modal, i18n("Check Spelling"), Help|Cancel|User1, Cancel, true, i18n("&Stop")) 00047 { 00048 QWidget * w = new QWidget(this); 00049 setMainWidget(w); 00050 m_indexLanguage=0; 00051 m_previous = 0L; 00052 00053 wordlabel = new QLabel(w, "wordlabel"); 00054 wordlabel->setFrameStyle(QFrame::WinPanel | QFrame::Sunken); 00055 00056 editbox = new KLineEdit(w, "editbox"); 00057 00058 listbox = new KListBox(w, "listbox"); 00059 00060 00061 QLabel * l_language = new QLabel(i18n("Language:"), w, "l_language"); 00062 00063 language = new QComboBox( w, "language"); 00064 00065 language->insertStringList( KOSpellConfig::listOfAspellLanguages()); 00066 language->setCurrentItem( indexOfLanguage); 00067 if ( _autocorrect ) 00068 { 00069 m_previous = new QCheckBox( i18n("Previous word"), w); 00070 } 00071 00072 if( _ksc->client() == KOS_CLIENT_ISPELL) 00073 { 00074 language->hide(); 00075 l_language->hide(); 00076 if( m_previous ) 00077 m_previous->hide(); 00078 } 00079 00080 QLabel * l_misspelled = new QLabel(i18n("Misspelled word:"), w, "l_misspelled"); 00081 00082 QLabel * l_replacement = new QLabel(i18n("Replacement:"), w, "l_replacement"); 00083 00084 QLabel * l_suggestions = new QLabel(i18n("Suggestions:"), w, "l_suggestions"); 00085 l_suggestions->setAlignment(Qt::AlignLeft | Qt::AlignTop ); 00086 00087 KButtonBox * buttonBox = new KButtonBox(w, Vertical); 00088 00089 QPushButton * b = 0L; 00090 00091 b = buttonBox->addButton(i18n("&Replace"), this, SLOT(replace())); 00092 connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool))); 00093 qpbrep = b; 00094 00095 b = buttonBox->addButton(i18n("Replace &All"), this, SLOT(replaceAll())); 00096 connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool))); 00097 qpbrepa = b; 00098 00099 b = buttonBox->addButton(i18n("&Ignore"), this, SLOT(ignore())); 00100 connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool))); 00101 00102 b = buttonBox->addButton(i18n("I&gnore All"), this, SLOT(ignoreAll())); 00103 connect(this, SIGNAL(ready(bool)), this, SLOT(setEnabled(bool))); 00104 00105 b = buttonBox->addButton(i18n("A&dd"), this, SLOT(add())); 00106 connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool))); 00107 00108 if ( _autocorrect ) 00109 { 00110 b = buttonBox->addButton( i18n("AutoCorrection"), this, SLOT(addToAutoCorrect())); 00111 connect( this, SIGNAL( ready(bool)), b, SLOT(setEnabled(bool))); 00112 } 00113 00114 connect(this, SIGNAL(user1Clicked()), this, SLOT(stop())); 00115 00116 connect( language, SIGNAL( activated ( int )), this, SLOT( changeLanguage( int))); 00117 00118 buttonBox->layout(); 00119 00120 QHBoxLayout * layout = new QHBoxLayout(w, KDialog::marginHint(), KDialog::spacingHint()); 00121 QGridLayout * leftGrid = new QGridLayout(layout); 00122 00123 leftGrid->addWidget(l_misspelled, 0, 0); 00124 leftGrid->addWidget(l_replacement, 1, 0); 00125 00126 leftGrid->addWidget(l_suggestions, 2, 0); 00127 leftGrid->addMultiCellWidget(wordlabel, 0,0, 1, 2); 00128 leftGrid->addMultiCellWidget(editbox, 1, 1, 1, 2); 00129 leftGrid->addMultiCellWidget(listbox, 2, 2, 1, 2); 00130 00131 leftGrid->addWidget(l_language, 3, 0); 00132 leftGrid->addMultiCellWidget(language, 3, 3, 1, 2); 00133 00134 if( m_previous ) 00135 leftGrid->addMultiCellWidget( m_previous, 4, 4, 0, 2); 00136 00137 layout->addWidget(buttonBox); 00138 00139 connect( editbox, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &))); 00140 00141 connect(editbox, SIGNAL(returnPressed()), SLOT(replace())); 00142 connect(listbox, SIGNAL(selected(int)), SLOT(selected(int))); 00143 connect(listbox, SIGNAL(highlighted(int)), SLOT(highlighted (int))); 00144 00145 QSize bs = sizeHint(); 00146 if (bs.width() < bs.height()) { 00147 resize(9 * bs.height() / 6, bs.height()); 00148 } 00149 00150 setHelp("spelldlg", "kspell"); 00151 00152 emit(ready(false)); 00153 } 00154 00155 void KOSpellDlg::addToAutoCorrect() 00156 { 00157 newword = editbox->text(); 00158 done (KOS_ADDAUTOCORRECT); 00159 } 00160 00161 void KOSpellDlg::spellCheckAgain() 00162 { 00163 newword = editbox->text(); 00164 done (KOS_CHECKAGAIN); 00165 } 00166 00167 void KOSpellDlg::changeLanguage( int index) 00168 { 00169 newword = word; 00170 m_indexLanguage = index; 00171 done (KOS_CHECKAGAINWITHNEWLANGUAGE); 00172 } 00173 00174 void KOSpellDlg::changeSuggList( QStringList *_lst ) 00175 { 00176 sugg = _lst; 00177 00178 listbox->clear(); 00179 emit(ready(true)); 00180 listbox->insertStringList(*_lst); 00181 changeButtonState( _lst ); 00182 } 00183 00184 void KOSpellDlg::init(const QString & _word, QStringList * _sugg) 00185 { 00186 sugg = _sugg; 00187 word = _word; 00188 00189 listbox->clear(); 00190 listbox->insertStringList(*sugg); 00191 00192 kdDebug(30006) << "KOSpellDlg::init [" << word << "]" << endl; 00193 00194 emit(ready(true)); 00195 00196 wordlabel->setText(_word); 00197 00198 if (sugg->count() == 0) { 00199 editbox->setText(_word); 00200 } 00201 changeButtonState( _sugg ); 00202 00203 } 00204 00205 void KOSpellDlg::changeButtonState( QStringList * _sugg ) 00206 { 00207 if (_sugg->count() == 0) { 00208 qpbrep->setEnabled(false); 00209 qpbrepa->setEnabled(false); 00210 00211 } else { 00212 00213 editbox->setText((*_sugg)[0]); 00214 qpbrep->setEnabled(true); 00215 qpbrepa->setEnabled(true); 00216 listbox->setCurrentItem (0); 00217 } 00218 } 00219 00220 00221 void KOSpellDlg::textChanged (const QString &) 00222 { 00223 qpbrep->setEnabled(true); 00224 qpbrepa->setEnabled(true); 00225 } 00226 00227 void KOSpellDlg::selected (int i) 00228 { 00229 highlighted (i); 00230 replace(); 00231 } 00232 00233 void KOSpellDlg::highlighted (int i) 00234 { 00235 if (listbox->text (i)!=0) 00236 editbox->setText (listbox->text (i)); 00237 } 00238 00239 /* 00240 exit functions 00241 */ 00242 00243 void KOSpellDlg::closeEvent( QCloseEvent * ) 00244 { 00245 cancel(); 00246 } 00247 00248 void KOSpellDlg::done (int result) 00249 { 00250 emit command (result); 00251 } 00252 void KOSpellDlg::ignore() 00253 { 00254 newword = word; 00255 done (KOS_IGNORE); 00256 } 00257 00258 void KOSpellDlg::ignoreAll() 00259 { 00260 newword = word; 00261 done (KOS_IGNOREALL); 00262 } 00263 00264 void KOSpellDlg::add() 00265 { 00266 newword = word; 00267 done (KOS_ADD); 00268 } 00269 00270 00271 void KOSpellDlg::cancel() 00272 { 00273 newword=word; 00274 done (KOS_CANCEL); 00275 } 00276 00277 void KOSpellDlg::replace() 00278 { 00279 newword = editbox->text(); 00280 done (KOS_REPLACE); 00281 } 00282 00283 void KOSpellDlg::stop() 00284 { 00285 newword = word; 00286 done (KOS_STOP); 00287 } 00288 00289 void KOSpellDlg::replaceAll() 00290 { 00291 newword = editbox->text(); 00292 done (KOS_REPLACEALL); 00293 } 00294 00295 bool KOSpellDlg::previousWord() const 00296 { 00297 return m_previous ? m_previous->isChecked(): false; 00298 } 00299 00300 #include "koSpelldlg.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003