diff options
Diffstat (limited to 'kspell2/ui')
-rw-r--r-- | kspell2/ui/Makefile.am | 21 | ||||
-rw-r--r-- | kspell2/ui/configdialog.cpp | 69 | ||||
-rw-r--r-- | kspell2/ui/configdialog.h | 49 | ||||
-rw-r--r-- | kspell2/ui/configui.ui | 114 | ||||
-rw-r--r-- | kspell2/ui/configwidget.cpp | 131 | ||||
-rw-r--r-- | kspell2/ui/configwidget.h | 57 | ||||
-rw-r--r-- | kspell2/ui/dialog.cpp | 282 | ||||
-rw-r--r-- | kspell2/ui/dialog.h | 88 | ||||
-rw-r--r-- | kspell2/ui/highlighter.cpp | 150 | ||||
-rw-r--r-- | kspell2/ui/highlighter.h | 59 | ||||
-rw-r--r-- | kspell2/ui/kspell2ui.ui | 324 |
11 files changed, 1344 insertions, 0 deletions
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 <zack@kde.org> + * + * 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 <klocale.h> + +#include <qvbox.h> + +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 <zack@kde.org> + * + * 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 <kdialogbase.h> + +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 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KSpell2ConfigUI</class> +<comment>Licensed under GNU LGPL</comment> +<author>Zack Rusin <zack@kde.org></author> +<widget class="QWidget"> + <property name="name"> + <cstring>KSpell2ConfigUI</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>577</width> + <height>441</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KComboBox" row="0" column="1"> + <property name="name"> + <cstring>m_langCombo</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string>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.</string> + </property> + </widget> + <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>groupBox1</cstring> + </property> + <property name="title"> + <string>Options</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox" row="0" column="0"> + <property name="name"> + <cstring>m_bgSpellCB</cstring> + </property> + <property name="text"> + <string>Enable &background spellchecking</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If checked, the "spell as you type" mode is active and all misspelled words are immediately highlighted.</string> + </property> + </widget> + <widget class="QCheckBox" row="1" column="0"> + <property name="name"> + <cstring>m_skipUpperCB</cstring> + </property> + <property name="text"> + <string>Skip all &uppercase words</string> + </property> + <property name="whatsThis" stdset="0"> + <string>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.</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="0"> + <property name="name"> + <cstring>m_skipRunTogetherCB</cstring> + </property> + <property name="text"> + <string>S&kip run-together words</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If checked, concatenated words made of existing words are not spell checked. This is useful in some languages.</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Default language:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kComboBox1</cstring> + </property> + </widget> + <widget class="KEditListBox" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_ignoreListBox</cstring> + </property> + <property name="title"> + <string>Ignore These Words</string> + </property> + <property name="buttons"> + <set>Remove|Add</set> + </property> + <property name="whatsThis" stdset="0"> + <string>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.</string> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<includes> + <include location="global" impldecl="in implementation">keditlistbox.h</include> + <include location="global" impldecl="in implementation">kcombobox.h</include> +</includes> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kcombobox.h</includehint> + <includehint>keditlistbox.h</includehint> + <includehint>klineedit.h</includehint> +</includehints> +</UI> 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 <zack@kde.org> + * + * 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 <keditlistbox.h> +#include <kcombobox.h> +#include <klocale.h> + +#include <qcheckbox.h> +#include <qlayout.h> + +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 <zack@kde.org> + * + * 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 <qwidget.h> +#include <kdelibs_export.h> + +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 <zack@kde.org> + * + * 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 <kconfig.h> +#include <klocale.h> +#include <kdebug.h> + +#include <qlistview.h> +#include <qpushbutton.h> +#include <qcombobox.h> +#include <qlineedit.h> +#include <qlabel.h> +#include <qtimer.h> +#include <qdict.h> + +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<QString, QString> 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"<<endl; + if ( d->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!!"<<endl; + d->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!"<<endl; + emit done( d->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 <zack@kde.org> + * + * 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 <kdialogbase.h> + +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 <zack@kde.org> + * + * 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 <kconfig.h> +#include <kdebug.h> + +#include <qtextedit.h> +#include <qtimer.h> +#include <qcolor.h> +#include <qdict.h> + +namespace KSpell2 { + +class Highlighter::Private +{ +public: + Filter *filter; + Broker::Ptr broker; + Dictionary *dict; + QDict<Dictionary> 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 \"" + <<lang + <<"\" staying with the current language." + <<endl; + return; + } + } + d->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 <zack@kde.org> + * + * 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 <qsyntaxhighlighter.h> + +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 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>KSpell2UI</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KSpell2UI</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>481</width> + <height>311</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>430</width> + <height>300</height> + </size> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Unknown word:</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QLabel" row="1" column="2"> + <property name="name"> + <cstring>m_unknownWord</cstring> + </property> + <property name="text"> + <string><b>misspelled</b></string> + </property> + <property name="toolTip" stdset="0"> + <string>Unknown word</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>textLabel5</cstring> + </property> + <property name="text"> + <string>&Language:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_language</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><qt> +<p>Select the language of the document you are proofing here.</p> +</qt></string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="6"> + <property name="name"> + <cstring>m_contextLabel</cstring> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="text"> + <string>... the <b>misspelled</b> word shown in context ...</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignCenter</set> + </property> + <property name="toolTip" stdset="0"> + <string>Text excerpt showing the unknown word in its context.</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QPushButton" row="1" column="4" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_addBtn</cstring> + </property> + <property name="text"> + <string><< Add to Dictionary</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <spacer row="1" column="3"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>74</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QListView" row="3" column="0" rowspan="1" colspan="5"> + <column> + <property name="text"> + <string>Suggested Words</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>m_suggestions</cstring> + </property> + <property name="resizeMode"> + <enum>AllColumns</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Suggestion List</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QLabel" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="text"> + <string>Replace &with:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_replacement</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QLineEdit" row="2" column="2" rowspan="1" colspan="3"> + <property name="name"> + <cstring>m_replacement</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QComboBox" row="4" column="1" rowspan="1" colspan="4"> + <item> + <property name="text"> + <string>English</string> + </property> + </item> + <property name="name"> + <cstring>m_language</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Language Selection</string> + </property> + <property name="whatsThis" stdset="0"> + <string><qt> +<p>Select the language of the document you are proofing here.</p> +</qt></string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="5" rowspan="3" colspan="1"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_suggestBtn</cstring> + </property> + <property name="text"> + <string>S&uggest</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_replaceBtn</cstring> + </property> + <property name="text"> + <string>&Replace</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_replaceAllBtn</cstring> + </property> + <property name="text"> + <string>R&eplace All</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_skipBtn</cstring> + </property> + <property name="text"> + <string>&Ignore</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_skipAllBtn</cstring> + </property> + <property name="text"> + <string>I&gnore All</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_autoCorrect</cstring> + </property> + <property name="text"> + <string>Autocorrect</string> + </property> + <property name="whatsThis" stdset="0"> + <string><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></string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>m_addBtn</tabstop> + <tabstop>m_replacement</tabstop> + <tabstop>m_suggestBtn</tabstop> + <tabstop>m_replaceBtn</tabstop> + <tabstop>m_replaceAllBtn</tabstop> + <tabstop>m_skipBtn</tabstop> + <tabstop>m_skipAllBtn</tabstop> + <tabstop>m_suggestions</tabstop> + <tabstop>m_language</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> |