kspelldlg.cpp Source File (kspell Library)

| # kspell Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kspelldlg.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
    00006    This library is free software; you can redistribute it and/or
    00007    modify it under the terms of the GNU Library General Public
    00008    License version 2 as published by the Free Software Foundation.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <qstringlist.h>
    00022 #include <qpushbutton.h>
    00023 #include <qlabel.h>
    00024 #include <qlayout.h>
    00025
    00026 #include <kapplication.h>
    00027 #include <klocale.h>
    00028 #include <klistbox.h>
    00029 #include <klineedit.h>
    00030 #include <kprogress.h>
    00031 #include <kbuttonbox.h>
    00032 #include <kdebug.h>
    00033
    00034 #include "kspelldlg.h"
    00035
    00036 KSpellDlg::KSpellDlg(
    00037   QWidget * parent,
    00038   const char * name,
    00039   bool _progressbar,
    00040   bool _modal
    00041 )
    00042   : KDialogBase(
    00043       parent, name, _modal, i18n("Check spelling"), Help|Cancel|User1,
    00044       Cancel, true, i18n("&Stop")
    00045     ),
    00046     progressbar(_progressbar)
    00047 {
    00048   QWidget * w = new QWidget(this);
    00049   setMainWidget(w);
    00050
    00051   wordlabel = new QLabel(w, "wordlabel");
    00052   wordlabel->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
    00053
    00054   editbox = new KLineEdit(w, "editbox");
    00055
    00056   listbox = new KListBox(w, "listbox");
    00057
    00058   QLabel * l_misspelled =
    00059     new QLabel(i18n("Misspelled word:"), w, "l_misspelled");
    00060
    00061   QLabel * l_replacement =
    00062     new QLabel(i18n("Replacement:"), w, "l_replacement");
    00063
    00064   QLabel * l_suggestions =
    00065     new QLabel(i18n("Suggestions:"), w, "l_suggestions");
    00066   l_suggestions->setAlignment(Qt::AlignLeft | Qt::AlignTop );
    00067
    00068   KButtonBox * buttonBox = new KButtonBox(w, Vertical);
    00069
    00070   QPushButton * b = 0L;
    00071
    00072   b = buttonBox->addButton(i18n("&Replace"), this, SLOT(replace()));
    00073   connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool)));
    00074   qpbrep = b;
    00075
    00076   b = buttonBox->addButton(i18n("Replace &All"), this, SLOT(replaceAll()));
    00077   connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool)));
    00078   qpbrepa = b;
    00079
    00080   b = buttonBox->addButton(i18n("&Ignore"), this, SLOT(ignore()));
    00081   connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool)));
    00082
    00083   b = buttonBox->addButton(i18n("I&gnore All"), this, SLOT(ignoreAll()));
    00084   connect(this, SIGNAL(ready(bool)), this, SLOT(setEnabled(bool)));
    00085
    00086   b = buttonBox->addButton(i18n("A&dd"), this, SLOT(add()));
    00087   connect(this, SIGNAL(ready(bool)), b, SLOT(setEnabled(bool)));
    00088
    00089   connect(this, SIGNAL(user1Clicked()), this, SLOT(stop()));
    00090
    00091   buttonBox->layout();
    00092
    00093   QHBoxLayout * layout = 0L;
    00094
    00095   if (progressbar) {
    00096
    00097     QVBoxLayout * topLayout =
    00098       new QVBoxLayout(w, KDialog::marginHint(), KDialog::spacingHint());
    00099
    00100     layout = new QHBoxLayout(topLayout);
    00101     progbar = new KProgress (w);
    00102     topLayout->addWidget(progbar);
    00103
    00104   } else {
    00105
    00106     layout =
    00107       new QHBoxLayout(w, KDialog::marginHint(), KDialog::spacingHint());
    00108   }
    00109
    00110   QGridLayout * leftGrid = new QGridLayout(layout);
    00111
    00112   leftGrid->addWidget(l_misspelled,   0, 0);
    00113   leftGrid->addWidget(l_replacement,  1, 0);
    00114   leftGrid->addWidget(l_suggestions,  2, 0);
    00115   leftGrid->addWidget(wordlabel,      0, 1);
    00116   leftGrid->addWidget(editbox,        1, 1);
    00117   leftGrid->addWidget(listbox,        2, 1);
    00118
    00119   layout->addWidget(buttonBox);
    00120
    00121   connect(
    00122     editbox,
    00123     SIGNAL(textChanged(const QString &)),
    00124     SLOT(textChanged(const QString &))
    00125   );
    00126
    00127   connect(editbox, SIGNAL(returnPressed()),   SLOT(replace()));
    00128   connect(listbox, SIGNAL(selected(int)),     SLOT(selected(int)));
    00129   connect(listbox, SIGNAL(highlighted(int)),  SLOT(highlighted (int)));
    00130
    00131   QSize bs = sizeHint();
    00132   if (bs.width() < bs.height()) {
    00133     resize(9 * bs.height() / 6, bs.height());
    00134   }
    00135
    00136   setHelp("spelldlg", "kspell");
    00137
    00138   emit(ready(false));
    00139 }
    00140
    00141 void
    00142 KSpellDlg::init(const QString & _word, QStringList * _sugg)
    00143 {
    00144   sugg = _sugg;
    00145   word = _word;
    00146
    00147   listbox->clear();
    00148   listbox->insertStringList(*sugg);
    00149
    00150   kdDebug(750) << "KSpellDlg::init [" << word << "]" << endl;
    00151
    00152   emit(ready(true));
    00153
    00154   wordlabel->setText(_word);
    00155
    00156   if (sugg->count() == 0) {
    00157
    00158     editbox->setText(_word);
    00159     qpbrep->setEnabled(false);
    00160     qpbrepa->setEnabled(false);
    00161
    00162   } else {
    00163
    00164     editbox->setText((*sugg)[0]);
    00165     qpbrep->setEnabled(true);
    00166     qpbrepa->setEnabled(true);
    00167     listbox->setCurrentItem (0);
    00168   }
    00169 }
    00170
    00171 void
    00172 KSpellDlg::slotProgress (unsigned int p)
    00173 {
    00174   if (!progressbar)
    00175     return;
    00176
    00177   progbar->setValue((int) p);
    00178 }
    00179
    00180 void
    00181 KSpellDlg::textChanged (const QString &)
    00182 {
    00183   qpbrep->setEnabled(true);
    00184   qpbrepa->setEnabled(true);
    00185 }
    00186
    00187 void
    00188 KSpellDlg::selected (int i)
    00189 {
    00190   highlighted (i);
    00191   replace();
    00192 }
    00193
    00194 void
    00195 KSpellDlg::highlighted (int i)
    00196 {
    00197   if (listbox->text (i)!=0)
    00198     editbox->setText (listbox->text (i));
    00199 }
    00200
    00201 /*
    00202   exit functions
    00203   */
    00204
    00205 void
    00206 KSpellDlg::closeEvent( QCloseEvent * )
    00207 {
    00208         cancel();
    00209 }
    00210
    00211 void
    00212 KSpellDlg::done (int result)
    00213 {
    00214   emit command (result);
    00215 }
    00216 void
    00217 KSpellDlg::ignore()
    00218 {
    00219   newword = word;
    00220   done (KS_IGNORE);
    00221 }
    00222
    00223 void
    00224 KSpellDlg::ignoreAll()
    00225 {
    00226   newword = word;
    00227   done (KS_IGNOREALL);
    00228 }
    00229
    00230 void
    00231 KSpellDlg::add()
    00232 {
    00233   newword = word;
    00234   done (KS_ADD);
    00235 }
    00236
    00237
    00238 void
    00239 KSpellDlg::cancel()
    00240 {
    00241   newword=word;
    00242   done (KS_CANCEL);
    00243 }
    00244
    00245 void
    00246 KSpellDlg::replace()
    00247 {
    00248   newword = editbox->text();
    00249   done (KS_REPLACE);
    00250 }
    00251
    00252 void
    00253 KSpellDlg::stop()
    00254 {
    00255   newword = word;
    00256   done (KS_STOP);
    00257 }
    00258
    00259 void
    00260 KSpellDlg::replaceAll()
    00261 {
    00262   newword = editbox->text();
    00263   done (KS_REPLACEALL);
    00264 }
    00265
    00266 #include "kspelldlg.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:27:47 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001