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

KDEUI

dialog.cpp

Go to the documentation of this file.
00001 
00021 #include "dialog.h"
00022 #include "ui_sonnetui.h"
00023 
00024 #include "backgroundchecker.h"
00025 #include "speller.h"
00026 #include "filter_p.h"
00027 #include "settings_p.h"
00028 
00029 #include <kconfig.h>
00030 #include <kguiitem.h>
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033 
00034 #include <QtGui/QListView>
00035 #include <QtGui/QPushButton>
00036 #include <QtGui/QComboBox>
00037 #include <QtGui/QLineEdit>
00038 #include <QtGui/QLabel>
00039 #include <QtCore/QTimer>
00040 
00041 namespace Sonnet
00042 {
00043 
00044 //to initially disable sorting in the suggestions listview
00045 #define NONSORTINGCOLUMN 2
00046 
00047 class Dialog::Private
00048 {
00049 public:
00050     Ui_SonnetUi ui;
00051     QWidget *wdg;
00052     QString   originalBuffer;
00053     BackgroundChecker *checker;
00054 
00055     Word   currentWord;
00056     QMap<QString, QString> replaceAllMap;
00057     bool restart;//used when text is distributed across several qtextedits, eg in KAider
00058 };
00059 
00060 Dialog::Dialog(BackgroundChecker *checker,
00061                QWidget *parent)
00062     : KDialog(parent),
00063       d(new Private)
00064 {
00065     setModal(true);
00066     setCaption(i18nc("@title:window", "Check Spelling"));
00067     setButtons(Help | Cancel | User1);
00068     setButtonGuiItem(User1, KGuiItem(i18nc("@action:button", "&Finished")));
00069     setDefaultButton(Cancel);
00070     showButtonSeparator(true);
00071 
00072     setDefaultButton(Cancel);
00073     d->checker = checker;
00074 
00075     initGui();
00076     initConnections();
00077     setMainWidget(d->wdg);
00078     setHelp(QString(),"sonnet");
00079 }
00080 
00081 Dialog::~Dialog()
00082 {
00083     delete d;
00084 }
00085 
00086 void Dialog::initConnections()
00087 {
00088     connect( d->ui.m_addBtn, SIGNAL(clicked()),
00089              SLOT(slotAddWord()) );
00090     connect( d->ui.m_replaceBtn, SIGNAL(clicked()),
00091              SLOT(slotReplaceWord()) );
00092     connect( d->ui.m_replaceAllBtn, SIGNAL(clicked()),
00093              SLOT(slotReplaceAll()) );
00094     connect( d->ui.m_skipBtn, SIGNAL(clicked()),
00095              SLOT(slotSkip()) );
00096     connect( d->ui.m_skipAllBtn, SIGNAL(clicked()),
00097              SLOT(slotSkipAll()) );
00098     connect( d->ui.m_suggestBtn, SIGNAL(clicked()),
00099              SLOT(slotSuggest()) );
00100     connect( d->ui.m_language, SIGNAL(activated(const QString&)),
00101              SLOT(slotChangeLanguage(const QString&)) );
00102     connect( d->ui.m_suggestions, SIGNAL(itemClicked(QListWidgetItem*)),
00103          SLOT(slotSelectionChanged(QListWidgetItem*)) );
00104     connect( d->checker, SIGNAL(misspelling(const QString&, int)),
00105              SIGNAL(misspelling(const QString&, int)) );
00106     connect( d->checker, SIGNAL(misspelling(const QString&, int)),
00107              SLOT(slotMisspelling(const QString&, int)) );
00108     connect( d->checker, SIGNAL(done()),
00109              SLOT(slotDone()) );
00110     connect( d->ui.m_suggestions, SIGNAL(itemDoubleClicked (QListWidgetItem *)),
00111              SLOT( slotReplaceWord() ) );
00112     connect( this, SIGNAL(user1Clicked()), this, SLOT(slotFinished()) );
00113     connect( this, SIGNAL(cancelClicked()),this, SLOT(slotCancel()) );
00114     connect( d->ui.m_replacement, SIGNAL(returnPressed()), this, SLOT(slotReplaceWord()) );
00115     connect( d->ui.m_autoCorrect, SIGNAL(clicked()),
00116              SLOT(slotAutocorrect()) );
00117     // button use by kword/kpresenter
00118     // hide by default
00119     d->ui.m_autoCorrect->hide();
00120 }
00121 
00122 void Dialog::initGui()
00123 {
00124     d->wdg = new QWidget(this);
00125     d->ui.setupUi(d->wdg);
00126 
00127     //d->ui.m_suggestions->setSorting( NONSORTINGCOLUMN );
00128     d->ui.m_language->clear();
00129     Speller speller = d->checker->speller();
00130     d->ui.m_language->insertItems(0, speller.availableLanguageNames());
00131     d->ui.m_language->setCurrentIndex(speller.availableLanguages().indexOf(
00132                                           speller.language()));
00133     d->restart = false;
00134 }
00135 
00136 void Dialog::activeAutoCorrect( bool _active )
00137 {
00138     if ( _active )
00139         d->ui.m_autoCorrect->show();
00140     else
00141         d->ui.m_autoCorrect->hide();
00142 }
00143 
00144 void Dialog::slotAutocorrect()
00145 {
00146     kDebug();
00147     emit autoCorrect(d->currentWord.word, d->ui.m_replacement->text() );
00148     slotReplaceWord();
00149 }
00150 
00151 void Dialog::slotFinished()
00152 {
00153     kDebug();
00154     emit stop();
00155     //FIXME: should we emit done here?
00156     emit done(d->checker->text());
00157     emit spellCheckStatus(i18n("Spell check stopped."));
00158     accept();
00159 }
00160 
00161 void Dialog::slotCancel()
00162 {
00163     kDebug();
00164     emit cancel();
00165     emit spellCheckStatus(i18n("Spell check canceled."));
00166     reject();
00167 }
00168 
00169 QString Dialog::originalBuffer() const
00170 {
00171     return d->originalBuffer;
00172 }
00173 
00174 QString Dialog::buffer() const
00175 {
00176     return d->checker->text();
00177 }
00178 
00179 void Dialog::setBuffer(const QString &buf)
00180 {
00181     d->originalBuffer = buf;
00182     //it is possible to change buffer inside slot connected to done() signal
00183     d->restart = true;
00184 }
00185 
00186 
00187 void Dialog::updateDialog( const QString& word )
00188 {
00189     d->ui.m_unknownWord->setText( word );
00190     d->ui.m_contextLabel->setText( d->checker->currentContext() );
00191     const QStringList suggs = d->checker->suggest( word );
00192 
00193     if (suggs.isEmpty())
00194         d->ui.m_replacement->clear();
00195     else
00196         d->ui.m_replacement->setText( suggs.first() );
00197     fillSuggestions( suggs );
00198 }
00199 
00200 void Dialog::show()
00201 {
00202     kDebug()<<"Showing dialog";
00203     if (d->originalBuffer.isEmpty())
00204         d->checker->start();
00205     else
00206         d->checker->setText(d->originalBuffer);
00207 }
00208 
00209 void Dialog::slotAddWord()
00210 {
00211    d->checker->addWordToPersonal(d->currentWord.word);
00212    d->checker->continueChecking();
00213 }
00214 
00215 void Dialog::slotReplaceWord()
00216 {
00217     emit replace( d->currentWord.word, d->currentWord.start,
00218                   d->ui.m_replacement->text() );
00219     d->checker->replace(d->currentWord.start,
00220                         d->currentWord.word,
00221                         d->ui.m_replacement->text());
00222     d->checker->continueChecking();
00223 }
00224 
00225 void Dialog::slotReplaceAll()
00226 {
00227     d->replaceAllMap.insert( d->currentWord.word,
00228                              d->ui.m_replacement->text() );
00229     slotReplaceWord();
00230 }
00231 
00232 void Dialog::slotSkip()
00233 {
00234     d->checker->continueChecking();
00235 }
00236 
00237 void Dialog::slotSkipAll()
00238 {
00239     //### do we want that or should we have a d->ignoreAll list?
00240     Speller speller = d->checker->speller();
00241     speller.addToPersonal(d->currentWord.word);
00242     d->checker->setSpeller(speller);
00243     d->checker->continueChecking();
00244 }
00245 
00246 void Dialog::slotSuggest()
00247 {
00248     QStringList suggs = d->checker->suggest( d->ui.m_replacement->text() );
00249     fillSuggestions( suggs );
00250 }
00251 
00252 void Dialog::slotChangeLanguage( const QString& lang )
00253 {
00254     Speller speller = d->checker->speller();
00255     QString languageCode = speller.availableLanguages().at(
00256         speller.availableLanguageNames().indexOf(lang));
00257     d->checker->changeLanguage( languageCode );
00258     slotSuggest();
00259     emit languageChanged( languageCode );
00260 }
00261 
00262 void Dialog::slotSelectionChanged( QListWidgetItem *item )
00263 {
00264     d->ui.m_replacement->setText( item->text() );
00265 }
00266 
00267 void Dialog::fillSuggestions( const QStringList& suggs )
00268 {
00269     d->ui.m_suggestions->clear();
00270     for ( QStringList::ConstIterator it = suggs.begin(); it != suggs.end(); ++it ) {
00271         d->ui.m_suggestions->addItem(*it );
00272     }
00273 }
00274 
00275 void Dialog::slotMisspelling(const QString& word, int start)
00276 {
00277     kDebug()<<"Dialog misspelling!!";
00278     d->currentWord = Word( word, start );
00279     if ( d->replaceAllMap.contains( word ) ) {
00280         d->ui.m_replacement->setText( d->replaceAllMap[ word ] );
00281         slotReplaceWord();
00282     } else {
00283         updateDialog( word );
00284     }
00285     KDialog::show();
00286 }
00287 
00288 void Dialog::slotDone()
00289 {
00290     kDebug()<<"Dialog done!";
00291     d->restart=false;
00292     emit done(d->checker->text());
00293     if (d->restart)
00294     {
00295         d->checker->setText(d->originalBuffer);
00296         d->restart=false;
00297     }
00298     else
00299     {
00300         emit spellCheckStatus(i18n("Spell check complete."));        
00301         accept();
00302     }
00303 }
00304 
00305 }
00306 
00307 #include "dialog.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • 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