• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal