KDE3Support
k3spelldlg.cpp
Go to the documentation of this file.
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) 2003 Zack Rusin <zack@kde.org> 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., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "k3spelldlg.h" 00023 00024 #include <QProgressBar> 00025 00026 #include <kconfig.h> 00027 #include <kglobal.h> 00028 #include <klocale.h> 00029 #include <kdebug.h> 00030 00031 #include "k3sconfig.h" 00032 #include "ui_k3spellui.h" 00033 #include <kconfiggroup.h> 00034 #include <kdebug.h> 00035 00036 //to initially disable sorting in the suggestions listview 00037 #define NONSORTINGCOLUMN 2 00038 00039 class K3SpellDlg::K3SpellDlgPrivate { 00040 public: 00041 Ui_K3SpellUI ui; 00042 K3SpellConfig* spellConfig; 00043 }; 00044 00045 K3SpellDlg::K3SpellDlg( QWidget * parent, bool _progressbar, bool _modal ) 00046 : KDialog(parent) 00047 , d(0),progressbar( false ) 00048 { 00049 setCaption( i18n("Check Spelling") ); 00050 setButtons( Help|Cancel|User1 ); 00051 setModal( _modal ); 00052 setDefaultButton( Cancel ); 00053 setButtonText( Cancel, i18n("&Finished") ); 00054 00055 KConfigGroup cg( KGlobal::config(),"K3Spell" ); 00056 kDebug() << (cg.readEntry("K3Spell_DoSpellChecking")); 00057 kDebug() << "dospellchecking is " << cg.readEntry("K3Spell_DoSpellChecking", false); 00058 if ( (cg.readEntry("K3Spell_DoSpellChecking", false) == true) ) //dospellcheck ? 00059 { 00060 Q_UNUSED( _progressbar ); 00061 d = new K3SpellDlgPrivate; 00062 d->ui.setupUi(this); 00063 00064 connect( d->ui.m_replaceBtn, SIGNAL(clicked()), 00065 this, SLOT(replace())); 00066 connect( this, SIGNAL(ready(bool)), 00067 d->ui.m_replaceBtn, SLOT(setEnabled(bool)) ); 00068 00069 connect( d->ui.m_replaceAllBtn, SIGNAL(clicked()), this, SLOT(replaceAll())); 00070 connect(this, SIGNAL(ready(bool)), d->ui.m_replaceAllBtn, SLOT(setEnabled(bool))); 00071 00072 connect( d->ui.m_skipBtn, SIGNAL(clicked()), this, SLOT(ignore())); 00073 connect( this, SIGNAL(ready(bool)), d->ui.m_skipBtn, SLOT(setEnabled(bool))); 00074 00075 connect( d->ui.m_skipAllBtn, SIGNAL(clicked()), this, SLOT(ignoreAll())); 00076 connect( this, SIGNAL(ready(bool)), d->ui.m_skipAllBtn, SLOT(setEnabled(bool))); 00077 00078 connect( d->ui.m_addBtn, SIGNAL(clicked()), this, SLOT(add())); 00079 connect( this, SIGNAL(ready(bool)), d->ui.m_addBtn, SLOT(setEnabled(bool))); 00080 00081 connect( d->ui.m_suggestBtn, SIGNAL(clicked()), this, SLOT(suggest())); 00082 connect( this, SIGNAL(ready(bool)), d->ui.m_suggestBtn, SLOT(setEnabled(bool)) ); 00083 d->ui.m_suggestBtn->hide(); 00084 00085 connect(this, SIGNAL(user1Clicked()), this, SLOT(stop())); 00086 00087 connect( d->ui.m_replacement, SIGNAL(textChanged(const QString &)), 00088 SLOT(textChanged(const QString &)) ); 00089 00090 connect( d->ui.m_replacement, SIGNAL(returnPressed()), SLOT(replace()) ); 00091 connect( d->ui.m_suggestions, SIGNAL(selectionChanged(Q3ListViewItem*)), 00092 SLOT(slotSelectionChanged(Q3ListViewItem*)) ); 00093 00094 connect( d->ui.m_suggestions, SIGNAL( doubleClicked ( Q3ListViewItem *, const QPoint &, int ) ), 00095 SLOT( replace() ) ); 00096 d->spellConfig = new K3SpellConfig( 0, 0 , false ); 00097 d->spellConfig->fillDicts( d->ui.m_language ); 00098 connect( d->ui.m_language, SIGNAL(activated(int)), 00099 d->spellConfig, SLOT(sSetDictionary(int)) ); 00100 connect( d->spellConfig, SIGNAL(configChanged()), 00101 SLOT(slotConfigChanged()) ); 00102 00103 setHelp( "spelldlg", "k3spell" ); 00104 setMinimumSize( sizeHint() ); 00105 emit ready( false ); 00106 } 00107 } 00108 00109 K3SpellDlg::~K3SpellDlg() 00110 { 00111 delete d; 00112 } 00113 00114 QString K3SpellDlg::replacement() const 00115 { 00116 return newword; 00117 } 00118 00119 void 00120 K3SpellDlg::init( const QString & _word, QStringList * _sugg ) 00121 { 00122 sugg = _sugg; 00123 word = _word; 00124 00125 d->ui.m_suggestions->clear(); 00126 d->ui.m_suggestions->setSorting( NONSORTINGCOLUMN ); 00127 for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) { 00128 Q3ListViewItem *item = new Q3ListViewItem( d->ui.m_suggestions, 00129 d->ui.m_suggestions->lastItem() ); 00130 item->setText( 0, *it ); 00131 } 00132 kDebug(750) << "K3SpellDlg::init [" << word << "]"; 00133 00134 emit ready( true ); 00135 00136 d->ui.m_unknownWord->setText( _word ); 00137 00138 if ( sugg->count() == 0 ) { 00139 d->ui.m_replacement->setText( _word ); 00140 d->ui.m_replaceBtn->setEnabled( false ); 00141 d->ui.m_replaceAllBtn->setEnabled( false ); 00142 d->ui.m_suggestBtn->setEnabled( false ); 00143 } else { 00144 d->ui.m_replacement->setText( (*sugg)[0] ); 00145 d->ui.m_replaceBtn->setEnabled( true ); 00146 d->ui.m_replaceAllBtn->setEnabled( true ); 00147 d->ui.m_suggestBtn->setEnabled( false ); 00148 d->ui.m_suggestions->setSelected( d->ui.m_suggestions->firstChild(), true ); 00149 } 00150 } 00151 00152 void 00153 K3SpellDlg::init( const QString& _word, QStringList* _sugg, 00154 const QString& context ) 00155 { 00156 sugg = _sugg; 00157 word = _word; 00158 00159 d->ui.m_suggestions->clear(); 00160 d->ui.m_suggestions->setSorting( NONSORTINGCOLUMN ); 00161 for ( QStringList::Iterator it = _sugg->begin(); it != _sugg->end(); ++it ) { 00162 Q3ListViewItem *item = new Q3ListViewItem( d->ui.m_suggestions, 00163 d->ui.m_suggestions->lastItem() ); 00164 item->setText( 0, *it ); 00165 } 00166 00167 kDebug(750) << "K3SpellDlg::init [" << word << "]"; 00168 00169 emit ready( true ); 00170 00171 d->ui.m_unknownWord->setText( _word ); 00172 d->ui.m_contextLabel->setText( context ); 00173 00174 if ( sugg->count() == 0 ) { 00175 d->ui.m_replacement->setText( _word ); 00176 d->ui.m_replaceBtn->setEnabled( false ); 00177 d->ui.m_replaceAllBtn->setEnabled( false ); 00178 d->ui.m_suggestBtn->setEnabled( false ); 00179 } else { 00180 d->ui.m_replacement->setText( (*sugg)[0] ); 00181 d->ui.m_replaceBtn->setEnabled( true ); 00182 d->ui.m_replaceAllBtn->setEnabled( true ); 00183 d->ui.m_suggestBtn->setEnabled( false ); 00184 d->ui.m_suggestions->setSelected( d->ui.m_suggestions->firstChild(), true ); 00185 } 00186 } 00187 00188 void K3SpellDlg::standby() 00189 { 00190 ready( false ); 00191 } 00192 00193 void 00194 K3SpellDlg::slotProgress( unsigned int p ) 00195 { 00196 if (!progressbar) 00197 return; 00198 00199 progbar->setValue( (int) p ); 00200 } 00201 00202 void 00203 K3SpellDlg::textChanged( const QString & ) 00204 { 00205 d->ui.m_replaceBtn->setEnabled( true ); 00206 d->ui.m_replaceAllBtn->setEnabled( true ); 00207 d->ui.m_suggestBtn->setEnabled( true ); 00208 } 00209 00210 void 00211 K3SpellDlg::slotSelectionChanged( Q3ListViewItem* item ) 00212 { 00213 if ( item ) 00214 d->ui.m_replacement->setText( item->text( 0 ) ); 00215 } 00216 00217 /* 00218 exit functions 00219 */ 00220 00221 void 00222 K3SpellDlg::closeEvent( QCloseEvent * ) 00223 { 00224 cancel(); 00225 } 00226 00227 void 00228 K3SpellDlg::done( int result ) 00229 { 00230 emit command( result ); 00231 } 00232 void 00233 K3SpellDlg::ignore() 00234 { 00235 newword = word; 00236 done( KS_IGNORE ); 00237 } 00238 00239 void 00240 K3SpellDlg::ignoreAll() 00241 { 00242 newword = word; 00243 done( KS_IGNOREALL ); 00244 } 00245 00246 void 00247 K3SpellDlg::add() 00248 { 00249 newword = word; 00250 done( KS_ADD ); 00251 } 00252 00253 00254 void 00255 K3SpellDlg::cancel() 00256 { 00257 newword = word; 00258 done( KS_CANCEL ); 00259 } 00260 00261 void 00262 K3SpellDlg::replace() 00263 { 00264 newword = d->ui.m_replacement->text(); 00265 done( KS_REPLACE ); 00266 } 00267 00268 void 00269 K3SpellDlg::stop() 00270 { 00271 newword = word; 00272 done( KS_STOP ); 00273 } 00274 00275 void 00276 K3SpellDlg::replaceAll() 00277 { 00278 newword = d->ui.m_replacement->text(); 00279 done( KS_REPLACEALL ); 00280 } 00281 00282 void 00283 K3SpellDlg::suggest() 00284 { 00285 newword = d->ui.m_replacement->text(); 00286 done( KS_SUGGEST ); 00287 } 00288 00289 void 00290 K3SpellDlg::slotConfigChanged() 00291 { 00292 d->spellConfig->writeGlobalSettings(); 00293 done( KS_CONFIG ); 00294 } 00295 00296 #include "k3spelldlg.moc"
KDE 4.6 API Reference