From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kspell2/ui/Makefile.am | 21 +++ kspell2/ui/configdialog.cpp | 69 ++++++++++ kspell2/ui/configdialog.h | 49 +++++++ kspell2/ui/configui.ui | 114 ++++++++++++++++ kspell2/ui/configwidget.cpp | 131 ++++++++++++++++++ kspell2/ui/configwidget.h | 57 ++++++++ kspell2/ui/dialog.cpp | 282 ++++++++++++++++++++++++++++++++++++++ kspell2/ui/dialog.h | 88 ++++++++++++ kspell2/ui/highlighter.cpp | 150 ++++++++++++++++++++ kspell2/ui/highlighter.h | 59 ++++++++ kspell2/ui/kspell2ui.ui | 324 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1344 insertions(+) create mode 100644 kspell2/ui/Makefile.am create mode 100644 kspell2/ui/configdialog.cpp create mode 100644 kspell2/ui/configdialog.h create mode 100644 kspell2/ui/configui.ui create mode 100644 kspell2/ui/configwidget.cpp create mode 100644 kspell2/ui/configwidget.h create mode 100644 kspell2/ui/dialog.cpp create mode 100644 kspell2/ui/dialog.h create mode 100644 kspell2/ui/highlighter.cpp create mode 100644 kspell2/ui/highlighter.h create mode 100644 kspell2/ui/kspell2ui.ui (limited to 'kspell2/ui') diff --git a/kspell2/ui/Makefile.am b/kspell2/ui/Makefile.am new file mode 100644 index 000000000..e5995a0aa --- /dev/null +++ b/kspell2/ui/Makefile.am @@ -0,0 +1,21 @@ +METASOURCES = AUTO + +lib_LTLIBRARIES = libkspell2.la +# Put most of the code in a noinst lib, for the unit tests to be able to use internal classes. +noinst_LTLIBRARIES = libkspell2_noinst.la + +KDE_CXXFLAGS = -DKDE_NO_COMPAT -DQT_NO_COMPAT +INCLUDES = -I$(top_srcdir)/kspell2 $(all_includes) + +kspell2includedir = $(includedir)/kspell2 +kspell2include_HEADERS = dialog.h highlighter.h configdialog.h \ + configwidget.h + +libkspell2_noinst_la_SOURCES = kspell2ui.ui configwidget.cpp \ + highlighter.cpp configui.ui configdialog.cpp + +dialog.lo: kspell2ui.h + +libkspell2_la_SOURCES = dialog.cpp +libkspell2_la_LDFLAGS = -no-undefined -version-info 1:0:0 $(all_libraries) +libkspell2_la_LIBADD = libkspell2_noinst.la ../libkspell2base.la diff --git a/kspell2/ui/configdialog.cpp b/kspell2/ui/configdialog.cpp new file mode 100644 index 000000000..09a0af923 --- /dev/null +++ b/kspell2/ui/configdialog.cpp @@ -0,0 +1,69 @@ +/* + * configdialog.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "configdialog.h" +#include "configwidget.h" + +#include + +#include + +using namespace KSpell2; + +class ConfigDialog::Private +{ +public: + ConfigWidget *ui; +}; + +ConfigDialog::ConfigDialog( Broker *broker, QWidget *parent ) + : KDialogBase( parent, "KSpell2ConfigDialog", true, + i18n( "KSpell2 Configuration" ), + KDialogBase::Ok|KDialogBase::Apply|KDialogBase::Cancel, + KDialogBase::Ok, true ) +{ + init( broker ); +} + +ConfigDialog::~ConfigDialog() +{ + delete d; d = 0; +} + +void ConfigDialog::init( Broker *broker ) +{ + d = new Private; + QVBox *page = makeVBoxMainWidget(); + d->ui = new ConfigWidget( broker, page ); +} + +void ConfigDialog::slotOk() +{ + d->ui->save(); + accept(); +} + +void ConfigDialog::slotApply() +{ + d->ui->save(); +} + + +#include "configdialog.moc" diff --git a/kspell2/ui/configdialog.h b/kspell2/ui/configdialog.h new file mode 100644 index 000000000..5a2ee53c8 --- /dev/null +++ b/kspell2/ui/configdialog.h @@ -0,0 +1,49 @@ +/* + * configdialog.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_CONFIGDIALOG_H +#define KSPELL_CONFIGDIALOG_H + +#include + +namespace KSpell2 +{ + class Broker; + class ConfigDialog : public KDialogBase + { + Q_OBJECT + public: + ConfigDialog( Broker *broker, + QWidget *parent ); + ~ConfigDialog(); + + protected slots: + virtual void slotOk(); + virtual void slotApply(); + + private: + void init( Broker *broker ); + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/kspell2/ui/configui.ui b/kspell2/ui/configui.ui new file mode 100644 index 000000000..bf645b9c9 --- /dev/null +++ b/kspell2/ui/configui.ui @@ -0,0 +1,114 @@ + +KSpell2ConfigUI +Licensed under GNU LGPL +Zack Rusin <zack@kde.org> + + + KSpell2ConfigUI + + + + 0 + 0 + 577 + 441 + + + + + unnamed + + + + m_langCombo + + + This is the default language that the spell checker will use. The drop down box will list all of the dictionaries of your existing languages. + + + + + groupBox1 + + + Options + + + + unnamed + + + + m_bgSpellCB + + + Enable &background spellchecking + + + If checked, the "spell as you type" mode is active and all misspelled words are immediately highlighted. + + + + + m_skipUpperCB + + + Skip all &uppercase words + + + If checked, words that consist of only uppercase letters are not spell checked. This is useful if you have a lot of acronyms, such as KDE for example. + + + + + m_skipRunTogetherCB + + + S&kip run-together words + + + If checked, concatenated words made of existing words are not spell checked. This is useful in some languages. + + + + + + + textLabel1 + + + Default language: + + + kComboBox1 + + + + + m_ignoreListBox + + + Ignore These Words + + + Remove|Add + + + To add a word you want to ignore, type it in the top edit field and click Add. To remove a word, highlight it in the list and click Remove. + + + + + + + + keditlistbox.h + kcombobox.h + + + + kcombobox.h + keditlistbox.h + klineedit.h + + diff --git a/kspell2/ui/configwidget.cpp b/kspell2/ui/configwidget.cpp new file mode 100644 index 000000000..09811e56a --- /dev/null +++ b/kspell2/ui/configwidget.cpp @@ -0,0 +1,131 @@ +/* + * configwidget.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "configwidget.h" +#include "configui.h" + +#include "broker.h" +#include "settings.h" + +#include +#include +#include + +#include +#include + +using namespace KSpell2; + +class ConfigWidget::Private +{ +public: + Broker::Ptr broker; + KSpell2ConfigUI *ui; +}; + +ConfigWidget::ConfigWidget( Broker *broker, QWidget *parent, const char *name ) + : QWidget( parent, name ) +{ + init( broker ); +} + +ConfigWidget::~ConfigWidget() +{ + delete d; d = 0; +} + +void ConfigWidget::init( Broker *broker ) +{ + d = new Private; + d->broker = broker; + + QVBoxLayout *layout = new QVBoxLayout( this, 0, 0, "KSpell2ConfigUILayout"); + d->ui = new KSpell2ConfigUI( this ); + + QStringList langs = d->broker->languages(); + //QStringList clients = d->broker->clients(); + d->ui->m_langCombo->insertStringList( langs ); + setCorrectLanguage( langs ); + //d->ui->m_clientCombo->insertStringList( clients ); + d->ui->m_skipUpperCB->setChecked( !d->broker->settings()->checkUppercase() ); + d->ui->m_skipRunTogetherCB->setChecked( d->broker->settings()->skipRunTogether() ); + QStringList ignoreList = d->broker->settings()->currentIgnoreList(); + ignoreList.sort(); + d->ui->m_ignoreListBox->insertStringList( ignoreList ); + d->ui->m_bgSpellCB->setChecked( d->broker->settings()->backgroundCheckerEnabled() ); + d->ui->m_bgSpellCB->hide();//hidden by default + connect( d->ui->m_ignoreListBox, SIGNAL(changed()), SLOT(slotChanged()) ); + + layout->addWidget( d->ui ); +} + +void KSpell2::ConfigWidget::save() +{ + setFromGUI(); + d->broker->settings()->save(); +} + +void ConfigWidget::setFromGUI() +{ + d->broker->settings()->setDefaultLanguage( + d->ui->m_langCombo->currentText() ); + d->broker->settings()->setCheckUppercase( + !d->ui->m_skipUpperCB->isChecked() ); + d->broker->settings()->setSkipRunTogether( + d->ui->m_skipRunTogetherCB->isChecked() ); + d->broker->settings()->setBackgroundCheckerEnabled( + d->ui->m_bgSpellCB->isChecked() ); +} + +void ConfigWidget::slotChanged() +{ + d->broker->settings()->setCurrentIgnoreList( + d->ui->m_ignoreListBox->items() ); +} + +void ConfigWidget::setCorrectLanguage( const QStringList& langs) +{ + int idx = 0; + for ( QStringList::const_iterator itr = langs.begin(); + itr != langs.end(); ++itr, ++idx ) { + if ( *itr == d->broker->settings()->defaultLanguage() ) + d->ui->m_langCombo->setCurrentItem( idx ); + } +} + +void ConfigWidget::setBackgroundCheckingButtonShown( bool b ) +{ + d->ui->m_bgSpellCB->setShown( b ); +} + +bool ConfigWidget::backgroundCheckingButtonShown() const +{ + return d->ui->m_bgSpellCB->isShown(); +} + +void ConfigWidget::slotDefault() +{ + d->ui->m_skipUpperCB->setChecked( false ); + d->ui->m_skipRunTogetherCB->setChecked( false ); + d->ui->m_bgSpellCB->setChecked( true ); + d->ui->m_ignoreListBox->clear(); +} + +#include "configwidget.moc" diff --git a/kspell2/ui/configwidget.h b/kspell2/ui/configwidget.h new file mode 100644 index 000000000..18eb8e74f --- /dev/null +++ b/kspell2/ui/configwidget.h @@ -0,0 +1,57 @@ +/* + * configwidget.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_CONFIGWIDGET_H +#define KSPELL_CONFIGWIDGET_H + +#include +#include + +namespace KSpell2 +{ + class Broker; + class KDE_EXPORT ConfigWidget : public QWidget + { + Q_OBJECT + public: + ConfigWidget( Broker *broker, QWidget *parent, const char *name =0 ); + ~ConfigWidget(); + + bool backgroundCheckingButtonShown() const; + + public slots: + void save(); + void setBackgroundCheckingButtonShown( bool ); + void slotDefault(); + protected slots: + void slotChanged(); + + private: + void init( Broker *broker ); + void setFromGUI(); + void setCorrectLanguage( const QStringList& langs ); + + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/kspell2/ui/dialog.cpp b/kspell2/ui/dialog.cpp new file mode 100644 index 000000000..c7f6aa51e --- /dev/null +++ b/kspell2/ui/dialog.cpp @@ -0,0 +1,282 @@ +/* + * dialog.cpp + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "dialog.h" +#include "kspell2ui.h" + +#include "backgroundchecker.h" +#include "broker.h" +#include "filter.h" +#include "dictionary.h" +#include "settings.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace KSpell2 +{ + +//to initially disable sorting in the suggestions listview +#define NONSORTINGCOLUMN 2 + +class Dialog::Private +{ +public: + KSpell2UI *ui; + QString originalBuffer; + BackgroundChecker *checker; + + Word currentWord; + QMap replaceAllMap; +}; + +Dialog::Dialog( BackgroundChecker *checker, + QWidget *parent, const char *name ) + : KDialogBase( parent, name, true, + i18n( "Check Spelling" ), + Help|Cancel|User1, Cancel, true, + i18n( "&Finished" ) ) +{ + d = new Private; + + d->checker = checker; + + initGui(); + initConnections(); + setMainWidget( d->ui ); +} + +Dialog::~Dialog() +{ + delete d; +} + +void Dialog::initConnections() +{ + connect( d->ui->m_addBtn, SIGNAL(clicked()), + SLOT(slotAddWord()) ); + connect( d->ui->m_replaceBtn, SIGNAL(clicked()), + SLOT(slotReplaceWord()) ); + connect( d->ui->m_replaceAllBtn, SIGNAL(clicked()), + SLOT(slotReplaceAll()) ); + connect( d->ui->m_skipBtn, SIGNAL(clicked()), + SLOT(slotSkip()) ); + connect( d->ui->m_skipAllBtn, SIGNAL(clicked()), + SLOT(slotSkipAll()) ); + connect( d->ui->m_suggestBtn, SIGNAL(clicked()), + SLOT(slotSuggest()) ); + connect( d->ui->m_language, SIGNAL(activated(const QString&)), + SLOT(slotChangeLanguage(const QString&)) ); + connect( d->ui->m_suggestions, SIGNAL(selectionChanged(QListViewItem*)), + SLOT(slotSelectionChanged(QListViewItem*)) ); + connect( d->checker, SIGNAL(misspelling(const QString&, int)), + SIGNAL(misspelling(const QString&, int)) ); + connect( d->checker, SIGNAL(misspelling(const QString&, int)), + SLOT(slotMisspelling(const QString&, int)) ); + connect( d->checker, SIGNAL(done()), + SLOT(slotDone()) ); + connect( d->ui->m_suggestions, SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), + SLOT( slotReplaceWord() ) ); + connect( this, SIGNAL(user1Clicked()), this, SLOT(slotFinished()) ); + connect( this, SIGNAL(cancelClicked()),this, SLOT(slotCancel()) ); + connect( d->ui->m_replacement, SIGNAL(returnPressed()), this, SLOT(slotReplaceWord()) ); + connect( d->ui->m_autoCorrect, SIGNAL(clicked()), + SLOT(slotAutocorrect()) ); + // button use by kword/kpresenter + // hide by default + d->ui->m_autoCorrect->hide(); +} + +void Dialog::initGui() +{ + d->ui = new KSpell2UI( this ); + d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN ); + d->ui->m_language->clear(); + d->ui->m_language->insertStringList( d->checker->broker()->languages() ); + for ( int i = 0; !d->ui->m_language->text( i ).isNull(); ++i ) { + QString ct = d->ui->m_language->text( i ); + if ( ct == d->checker->broker()->settings()->defaultLanguage() ) { + d->ui->m_language->setCurrentItem( i ); + break; + } + } +} + +void Dialog::activeAutoCorrect( bool _active ) +{ + if ( _active ) + d->ui->m_autoCorrect->show(); + else + d->ui->m_autoCorrect->hide(); +} + +void Dialog::slotAutocorrect() +{ + kdDebug()<<"void Dialog::slotAutocorrect()\n"; + emit autoCorrect(d->currentWord.word, d->ui->m_replacement->text() ); + slotReplaceWord(); +} + +void Dialog::slotFinished() +{ + kdDebug()<<"void Dialog::slotFinished() \n"; + emit stop(); + //FIXME: should we emit done here? + emit done( d->checker->filter()->buffer() ); + accept(); +} + +void Dialog::slotCancel() +{ + kdDebug()<<"void Dialog::slotCancel() \n"; + emit cancel(); + reject(); +} + +QString Dialog::originalBuffer() const +{ + return d->originalBuffer; +} + +QString Dialog::buffer() const +{ + return d->checker->filter()->buffer(); +} + +void Dialog::setBuffer( const QString& buf ) +{ + d->originalBuffer = buf; +} + +void Dialog::setFilter( Filter *filter ) +{ + filter->setBuffer( d->checker->filter()->buffer() ); + d->checker->setFilter( filter ); +} + +void Dialog::updateDialog( const QString& word ) +{ + d->ui->m_unknownWord->setText( word ); + d->ui->m_contextLabel->setText( d->checker->filter()->context() ); + QStringList suggs = d->checker->suggest( word ); + d->ui->m_replacement->setText( suggs.first() ); + fillSuggestions( suggs ); +} + +void Dialog::show() +{ + kdDebug()<<"Showing dialog"<originalBuffer.isEmpty() ) + d->checker->start(); + else + d->checker->checkText( d->originalBuffer ); +} + +void Dialog::slotAddWord() +{ + d->checker->addWord( d->currentWord.word ); + d->checker->continueChecking(); +} + +void Dialog::slotReplaceWord() +{ + emit replace( d->currentWord.word, d->currentWord.start, + d->ui->m_replacement->text() ); + d->checker->filter()->replace( d->currentWord, d->ui->m_replacement->text() ); + d->checker->continueChecking(); +} + +void Dialog::slotReplaceAll() +{ + d->replaceAllMap.insert( d->currentWord.word, + d->ui->m_replacement->text() ); + slotReplaceWord(); +} + +void Dialog::slotSkip() +{ + d->checker->continueChecking(); +} + +void Dialog::slotSkipAll() +{ + //### do we want that or should we have a d->ignoreAll list? + d->checker->broker()->settings()->addWordToIgnore( d->ui->m_replacement->text() ); + d->checker->continueChecking(); +} + +void Dialog::slotSuggest() +{ + QStringList suggs = d->checker->suggest( d->ui->m_replacement->text() ); + fillSuggestions( suggs ); +} + +void Dialog::slotChangeLanguage( const QString& lang ) +{ + d->checker->changeLanguage( lang ); + slotSuggest(); +} + +void Dialog::slotSelectionChanged( QListViewItem *item ) +{ + d->ui->m_replacement->setText( item->text( 0 ) ); +} + +void Dialog::fillSuggestions( const QStringList& suggs ) +{ + d->ui->m_suggestions->clear(); + for ( QStringList::ConstIterator it = suggs.begin(); it != suggs.end(); ++it ) { + new QListViewItem( d->ui->m_suggestions, d->ui->m_suggestions->firstChild(), + *it ); + } +} + +void Dialog::slotMisspelling(const QString& word, int start ) +{ + kdDebug()<<"Dialog misspelling!!"<currentWord = Word( word, start ); + if ( d->replaceAllMap.contains( word ) ) { + d->ui->m_replacement->setText( d->replaceAllMap[ word ] ); + slotReplaceWord(); + } else { + updateDialog( word ); + } + KDialogBase::show(); +} + +void Dialog::slotDone() +{ + kdDebug()<<"Dialog done!"<checker->filter()->buffer() ); + accept(); +} + +} + +#include "dialog.moc" diff --git a/kspell2/ui/dialog.h b/kspell2/ui/dialog.h new file mode 100644 index 000000000..20d295c96 --- /dev/null +++ b/kspell2/ui/dialog.h @@ -0,0 +1,88 @@ +// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- +/* + * dialog.h + * + * Copyright (C) 2003 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_DIALOG_H +#define KSPELL_DIALOG_H + +#include + +namespace KSpell2 +{ + class Filter; + class BackgroundChecker; + class KDE_EXPORT Dialog : public KDialogBase + { + Q_OBJECT + public: + Dialog( BackgroundChecker *checker, + QWidget *parent, const char *name=0 ); + ~Dialog(); + + QString originalBuffer() const; + QString buffer() const; + + void show(); + void activeAutoCorrect( bool _active ); + + public slots: + void setBuffer( const QString& ); + void setFilter( Filter* filter ); + + signals: + void done( const QString& newBuffer ); + void misspelling( const QString& word, int start ); + void replace( const QString& oldWord, int start, + const QString& newWord ); + + void stop(); + void cancel(); + void autoCorrect( const QString & currentWord, const QString & replaceWord ); + private slots: + void slotMisspelling(const QString& word, int start ); + void slotDone(); + + void slotFinished(); + void slotCancel(); + + void slotAddWord(); + void slotReplaceWord(); + void slotReplaceAll(); + void slotSkip(); + void slotSkipAll(); + void slotSuggest(); + void slotChangeLanguage( const QString& ); + void slotSelectionChanged( QListViewItem * ); + void slotAutocorrect(); + + private: + void updateDialog( const QString& word ); + void fillSuggestions( const QStringList& suggs ); + void initConnections(); + void initGui(); + void continueChecking(); + + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/kspell2/ui/highlighter.cpp b/kspell2/ui/highlighter.cpp new file mode 100644 index 000000000..0ecbb9802 --- /dev/null +++ b/kspell2/ui/highlighter.cpp @@ -0,0 +1,150 @@ +/* + * highlighter.cpp + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "highlighter.h" +#include "broker.h" +#include "dictionary.h" +#include "settings.h" + +#include +#include + +#include +#include +#include +#include + +namespace KSpell2 { + +class Highlighter::Private +{ +public: + Filter *filter; + Broker::Ptr broker; + Dictionary *dict; + QDict dictCache; +}; + +Highlighter::Highlighter( QTextEdit *textEdit, + const QString& configFile, + Filter *filter) + : QSyntaxHighlighter( textEdit ) +{ + d = new Private; + d->filter = filter; + if ( !configFile.isEmpty() ) + d->broker = Broker::openBroker( KSharedConfig::openConfig( configFile ) ); + else + d->broker = Broker::openBroker(); + + d->filter->setSettings( d->broker->settings() ); + d->dict = d->broker->dictionary(); + Q_ASSERT( d->dict ); + d->dictCache.insert( d->broker->settings()->defaultLanguage(), + d->dict ); +} + +Highlighter::~Highlighter() +{ + delete d; d = 0; +} + +int Highlighter::highlightParagraph( const QString& text, + int endStateOfLastPara ) +{ + Q_UNUSED( endStateOfLastPara ); + int para, index; + textEdit()->getCursorPosition( ¶, &index ); + const int lengthPosition = text.length() - 1; + + if ( index != lengthPosition || + ( lengthPosition > 0 && !text[lengthPosition-1].isLetter() ) ) { + d->filter->setBuffer( text ); + Word w = d->filter->nextWord(); + while ( !w.end ) { + if ( !d->dict->check( w.word ) ) { + setMisspelled( w.start, w.word.length() ); + } else + unsetMisspelled( w.start, w.word.length() ); + w = d->filter->nextWord(); + } + } + //QTimer::singleShot( 0, this, SLOT(checkWords()) ); + + return 0; +} + +Filter *Highlighter::currentFilter() const +{ + return d->filter; +} + +void Highlighter::setCurrentFilter( Filter *filter ) +{ + d->filter = filter; + d->filter->setSettings( d->broker->settings() ); +} + +QString Highlighter::currentLanguage() const +{ + return d->dict->language(); +} + +void Highlighter::setCurrentLanguage( const QString& lang ) +{ + if ( !d->dictCache.find( lang ) ) { + Dictionary *dict = d->broker->dictionary( lang ); + if ( dict ) { + d->dictCache.insert( lang, dict ); + } else { + kdDebug()<<"No dictionary for \"" + <dict = d->dictCache[lang]; +} + +void Highlighter::setMisspelled( int start, int count ) +{ + setFormat( start , count, Qt::red ); +} + +void Highlighter::unsetMisspelled( int start, int count ) +{ + setFormat( start, count, Qt::black ); +} + +/* +void Highlighter::checkWords() +{ + Word w = d->filter->nextWord(); + if ( !w.end ) { + if ( !d->dict->check( w.word ) ) { + setFormat( w.start, w.word.length(), + Qt::red ); + } + } +}*/ + +} diff --git a/kspell2/ui/highlighter.h b/kspell2/ui/highlighter.h new file mode 100644 index 000000000..86140f054 --- /dev/null +++ b/kspell2/ui/highlighter.h @@ -0,0 +1,59 @@ +/* + * highlighter.h + * + * Copyright (C) 2004 Zack Rusin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KSPELL_HIGHLIGHTER_H +#define KSPELL_HIGHLIGHTER_H + +#include "filter.h" + +#include + +class QTextEdit; + +namespace KSpell2 +{ + class Highlighter : public QSyntaxHighlighter + { + public: + Highlighter( QTextEdit *textEdit, + const QString& configFile = QString::null, + Filter *filter = Filter::defaultFilter() ); + ~Highlighter(); + + virtual int highlightParagraph( const QString& text, + int endStateOfLastPara ); + + Filter *currentFilter() const; + void setCurrentFilter( Filter *filter ); + + QString currentLanguage() const; + void setCurrentLanguage( const QString& lang ); + + protected: + virtual void setMisspelled( int start, int count ); + virtual void unsetMisspelled( int start, int count ); + private: + class Private; + Private *d; + }; + +} + +#endif diff --git a/kspell2/ui/kspell2ui.ui b/kspell2/ui/kspell2ui.ui new file mode 100644 index 000000000..b8870f2f5 --- /dev/null +++ b/kspell2/ui/kspell2ui.ui @@ -0,0 +1,324 @@ + +KSpell2UI + + + KSpell2UI + + + + 0 + 0 + 481 + 311 + + + + + 5 + 5 + 0 + 0 + + + + + 430 + 300 + + + + + unnamed + + + + textLabel2 + + + Unknown word: + + + <qt><p>This word was considered to be an "unknown word" because it does not match any entry in the dictionary currently in use. It may also be a word in a foreign language.</p> +<p>If the word is not misspelled, you may add it to the dictionary by clicking <b>Add to Dictionary</b>. If you don't want to add the unknown word to the dictionary, but you want to leave it unchanged, click <b>Ignore</b> or <b>Ignore All</b>.</p> +<p>However, if the word is misspelled, you can try to find the correct replacement in the list below. If you cannot find a replacement there, you may type it in the text box below, and click <b>Replace</b> or <b>Replace All</b>.</p> +</qt> + + + + + m_unknownWord + + + <b>misspelled</b> + + + Unknown word + + + <qt><p>This word was considered to be an "unknown word" because it does not match any entry in the dictionary currently in use. It may also be a word in a foreign language.</p> +<p>If the word is not misspelled, you may add it to the dictionary by clicking <b>Add to Dictionary</b>. If you don't want to add the unknown word to the dictionary, but you want to leave it unchanged, click <b>Ignore</b> or <b>Ignore All</b>.</p> +<p>However, if the word is misspelled, you can try to find the correct replacement in the list below. If you cannot find a replacement there, you may type it in the text box below, and click <b>Replace</b> or <b>Replace All</b>.</p> +</qt> + + + + + textLabel5 + + + &Language: + + + m_language + + + <qt> +<p>Select the language of the document you are proofing here.</p> +</qt> + + + + + m_contextLabel + + + Box + + + ... the <b>misspelled</b> word shown in context ... + + + WordBreak|AlignCenter + + + Text excerpt showing the unknown word in its context. + + + <qt> +<p>Here you can see a text excerpt showing the unknown word in its context. If this information is not sufficient to choose the best replacement for the unknown word, you can click on the document you are proofing, read a larger part of the text and then return here to continue proofing.</p> +</qt> + + + + + m_addBtn + + + << Add to Dictionary + + + <qt> +<p>The unknown word was detected and considered unknown because it is not included in the dictionary.<br> +Click here if you consider that the unknown word is not misspelled and you want to avoid wrongly detecting it again in the future. If you want to let it remain as is, but not add it to the dictionary, then click <b>Ignore</b> or <b>Ignore All</b> instead.</p> +</qt> + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 74 + 20 + + + + + + + Suggested Words + + + true + + + true + + + + m_suggestions + + + AllColumns + + + Suggestion List + + + <qt> +<p>If the unknown word is misspelled, you should check if the correction for it is available and if it is, click on it. If none of the words in this list is a good replacement you may type the correct word in the edit box above.</p> +<p>To correct this word click <b>Replace</b> if you want to correct only this occurrence or <b>Replace All</b> if you want to correct all occurrences.</p> +</qt> + + + + + textLabel4 + + + Replace &with: + + + m_replacement + + + <qt> +<p>If the unknown word is misspelled, you should type the correction for your misspelled word here or select it from the list below.</p> +<p>You can then click <b>Replace</b> if you want to correct only this occurrence of the word or <b>Replace All</b> if you want to correct all occurrences.</p> +</qt> + + + + + m_replacement + + + <qt> +<p>If the unknown word is misspelled, you should type the correction for your misspelled word here or select it from the list below.</p> +<p>You can then click <b>Replace</b> if you want to correct only this occurrence of the word or <b>Replace All</b> if you want to correct all occurrences.</p> +</qt> + + + + + + English + + + + m_language + + + Language Selection + + + <qt> +<p>Select the language of the document you are proofing here.</p> +</qt> + + + + + layout1 + + + + unnamed + + + + m_suggestBtn + + + S&uggest + + + + + m_replaceBtn + + + &Replace + + + <qt> +<p>Click here to replace this occurrence of the unknown text with the text in the edit box above (to the left).</p> +</qt> + + + + + m_replaceAllBtn + + + R&eplace All + + + <qt> +<p>Click here to replace all occurrences of the unknown text with the text in the edit box above (to the left).</p> +</qt> + + + + + m_skipBtn + + + &Ignore + + + <qt> +<p>Click here to let this occurrence of the unknown word remain as is.</p> +<p>This action is useful when the word is a name, an acronym, a foreign word or any other unknown word that you want to use but not add to the dictionary.</p> +</qt> + + + + + m_skipAllBtn + + + I&gnore All + + + <qt> +<p>Click here to let all occurrences of the unknown word remain as they are.</p> +<p>This action is useful when the word is a name, an acronym, a foreign word or any other unknown word that you want to use but not add to the dictionary.</p> +</qt> + + + + + m_autoCorrect + + + Autocorrect + + + <qt> +<p>Click here to let all occurrences of the unknown word remain as they are.</p> +<p>This action is useful when the word is a name, an acronym, a foreign word or any other unknown word that you want to use but not add to the dictionary.</p> +</qt> + + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + m_addBtn + m_replacement + m_suggestBtn + m_replaceBtn + m_replaceAllBtn + m_skipBtn + m_skipAllBtn + m_suggestions + m_language + + + -- cgit v1.2.1