diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-26 13:17:21 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-26 13:17:21 -0600 |
commit | dfe289850f068f19ba4a83ab4e7e22a7e09c13c9 (patch) | |
tree | c297348a55df66c571de4525646e0b9762427353 /tdespell2/ui | |
parent | b7658a0d5eca24a9d37c6e04f88298ef02389db0 (diff) | |
download | tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.tar.gz tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tdespell2/ui')
-rw-r--r-- | tdespell2/ui/CMakeLists.txt | 67 | ||||
-rw-r--r-- | tdespell2/ui/Makefile.am | 21 | ||||
-rw-r--r-- | tdespell2/ui/configdialog.cpp | 69 | ||||
-rw-r--r-- | tdespell2/ui/configdialog.h | 49 | ||||
-rw-r--r-- | tdespell2/ui/configui.ui | 114 | ||||
-rw-r--r-- | tdespell2/ui/configwidget.cpp | 131 | ||||
-rw-r--r-- | tdespell2/ui/configwidget.h | 57 | ||||
-rw-r--r-- | tdespell2/ui/dialog.cpp | 282 | ||||
-rw-r--r-- | tdespell2/ui/dialog.h | 88 | ||||
-rw-r--r-- | tdespell2/ui/highlighter.cpp | 150 | ||||
-rw-r--r-- | tdespell2/ui/highlighter.h | 59 | ||||
-rw-r--r-- | tdespell2/ui/tdespell2ui.ui | 324 |
12 files changed, 1411 insertions, 0 deletions
diff --git a/tdespell2/ui/CMakeLists.txt b/tdespell2/ui/CMakeLists.txt new file mode 100644 index 000000000..8d0521c76 --- /dev/null +++ b/tdespell2/ui/CMakeLists.txt @@ -0,0 +1,67 @@ +################################################# +# +# (C) 2010 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +add_definitions( + -DKDE_NO_COMPAT +) + +include_directories( + ${TQT_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdespell2 + ${CMAKE_SOURCE_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdeui +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### headers ################################### + +install( FILES + dialog.h highlighter.h configdialog.h configwidget.h + DESTINATION ${INCLUDE_INSTALL_DIR}/tdespell2 ) + + +#### tdespell2 (static) ########################### + +set( target tdespell2 ) + +set( ${target}_SRCS + configwidget.cpp highlighter.cpp configdialog.cpp + tdespell2ui.ui configui.ui +) + +tde_add_library( ${target} STATIC_PIC AUTOMOC + SOURCES ${${target}_SRCS} +) + + +#### tdespell2 #################################### + +set( target tdespell2 ) + +set( ${target}_SRCS + configwidget.cpp highlighter.cpp configdialog.cpp + tdespell2ui.ui configui.ui + dialog.cpp +) + +tde_add_library( ${target} SHARED AUTOMOC + SOURCES ${${target}_SRCS} + VERSION 1.0.0 + LINK tdespell2base-static tdeutils-shared + DESTINATION ${LIB_INSTALL_DIR} +) diff --git a/tdespell2/ui/Makefile.am b/tdespell2/ui/Makefile.am new file mode 100644 index 000000000..713270c9d --- /dev/null +++ b/tdespell2/ui/Makefile.am @@ -0,0 +1,21 @@ +METASOURCES = AUTO + +lib_LTLIBRARIES = libtdespell2.la +# Put most of the code in a noinst lib, for the unit tests to be able to use internal classes. +noinst_LTLIBRARIES = libtdespell2_noinst.la + +KDE_CXXFLAGS = -DKDE_NO_COMPAT -DQT_NO_COMPAT +INCLUDES = -I$(top_srcdir)/tdespell2 $(all_includes) + +tdespell2includedir = $(includedir)/tdespell2 +tdespell2include_HEADERS = dialog.h highlighter.h configdialog.h \ + configwidget.h + +libtdespell2_noinst_la_SOURCES = tdespell2ui.ui configwidget.cpp \ + highlighter.cpp configui.ui configdialog.cpp + +dialog.lo: tdespell2ui.h + +libtdespell2_la_SOURCES = dialog.cpp +libtdespell2_la_LDFLAGS = -no-undefined -version-info 1:0:0 $(all_libraries) +libtdespell2_la_LIBADD = libtdespell2_noinst.la ../libtdespell2base.la ../../tdeutils/libtdeutils.la $(LIB_QT) $(LIB_TDEUI) $(LIB_TDECORE) $(LIB_KFILE) diff --git a/tdespell2/ui/configdialog.cpp b/tdespell2/ui/configdialog.cpp new file mode 100644 index 000000000..56e39ca2b --- /dev/null +++ b/tdespell2/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 <tqvbox.h> + +using namespace KSpell2; + +class ConfigDialog::Private +{ +public: + ConfigWidget *ui; +}; + +ConfigDialog::ConfigDialog( Broker *broker, TQWidget *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; + TQVBox *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/tdespell2/ui/configdialog.h b/tdespell2/ui/configdialog.h new file mode 100644 index 000000000..ead508d34 --- /dev/null +++ b/tdespell2/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, + TQWidget *parent ); + ~ConfigDialog(); + + protected slots: + virtual void slotOk(); + virtual void slotApply(); + + private: + void init( Broker *broker ); + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/tdespell2/ui/configui.ui b/tdespell2/ui/configui.ui new file mode 100644 index 000000000..d6f6e596b --- /dev/null +++ b/tdespell2/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="TQWidget"> + <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="TQGroupBox" 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="TQCheckBox" 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="TQCheckBox" 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="TQCheckBox" 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="TQLabel" 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/tdespell2/ui/configwidget.cpp b/tdespell2/ui/configwidget.cpp new file mode 100644 index 000000000..6d98955ae --- /dev/null +++ b/tdespell2/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 <tqcheckbox.h> +#include <tqlayout.h> + +using namespace KSpell2; + +class ConfigWidget::Private +{ +public: + Broker::Ptr broker; + KSpell2ConfigUI *ui; +}; + +ConfigWidget::ConfigWidget( Broker *broker, TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + init( broker ); +} + +ConfigWidget::~ConfigWidget() +{ + delete d; d = 0; +} + +void ConfigWidget::init( Broker *broker ) +{ + d = new Private; + d->broker = broker; + + TQVBoxLayout *layout = new TQVBoxLayout( this, 0, 0, "KSpell2ConfigUILayout"); + d->ui = new KSpell2ConfigUI( this ); + + TQStringList langs = d->broker->languages(); + //TQStringList 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() ); + TQStringList 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, TQT_SIGNAL(changed()), TQT_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 TQStringList& langs) +{ + int idx = 0; + for ( TQStringList::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/tdespell2/ui/configwidget.h b/tdespell2/ui/configwidget.h new file mode 100644 index 000000000..e3fd1542b --- /dev/null +++ b/tdespell2/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 <tqwidget.h> +#include <tdelibs_export.h> + +namespace KSpell2 +{ + class Broker; + class KDE_EXPORT ConfigWidget : public TQWidget + { + Q_OBJECT + public: + ConfigWidget( Broker *broker, TQWidget *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 TQStringList& langs ); + + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/tdespell2/ui/dialog.cpp b/tdespell2/ui/dialog.cpp new file mode 100644 index 000000000..82548a406 --- /dev/null +++ b/tdespell2/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 "tdespell2ui.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 <tqlistview.h> +#include <tqpushbutton.h> +#include <tqcombobox.h> +#include <tqlineedit.h> +#include <tqlabel.h> +#include <tqtimer.h> +#include <tqdict.h> + +namespace KSpell2 +{ + +//to initially disable sorting in the suggestions listview +#define NONSORTINGCOLUMN 2 + +class Dialog::Private +{ +public: + KSpell2UI *ui; + TQString originalBuffer; + BackgroundChecker *checker; + + Word currentWord; + TQMap<TQString, TQString> replaceAllMap; +}; + +Dialog::Dialog( BackgroundChecker *checker, + TQWidget *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( TQT_TQWIDGET(d->ui) ); +} + +Dialog::~Dialog() +{ + delete d; +} + +void Dialog::initConnections() +{ + connect( TQT_TQOBJECT(d->ui->m_addBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotAddWord()) ); + connect( TQT_TQOBJECT(d->ui->m_replaceBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotReplaceWord()) ); + connect( TQT_TQOBJECT(d->ui->m_replaceAllBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotReplaceAll()) ); + connect( TQT_TQOBJECT(d->ui->m_skipBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotSkip()) ); + connect( TQT_TQOBJECT(d->ui->m_skipAllBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotSkipAll()) ); + connect( TQT_TQOBJECT(d->ui->m_suggestBtn), TQT_SIGNAL(clicked()), + TQT_SLOT(slotSuggest()) ); + connect( TQT_TQOBJECT(d->ui->m_language), TQT_SIGNAL(activated(const TQString&)), + TQT_SLOT(slotChangeLanguage(const TQString&)) ); + connect( TQT_TQOBJECT(d->ui->m_suggestions), TQT_SIGNAL(selectionChanged(TQListViewItem*)), + TQT_SLOT(slotSelectionChanged(TQListViewItem*)) ); + connect( TQT_TQOBJECT(d->checker), TQT_SIGNAL(misspelling(const TQString&, int)), + TQT_SIGNAL(misspelling(const TQString&, int)) ); + connect( TQT_TQOBJECT(d->checker), TQT_SIGNAL(misspelling(const TQString&, int)), + TQT_SLOT(slotMisspelling(const TQString&, int)) ); + connect( TQT_TQOBJECT(d->checker), TQT_SIGNAL(done()), + TQT_SLOT(slotDone()) ); + connect( d->ui->m_suggestions, TQT_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), + TQT_SLOT( slotReplaceWord() ) ); + connect( this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(slotFinished()) ); + connect( this, TQT_SIGNAL(cancelClicked()),this, TQT_SLOT(slotCancel()) ); + connect( d->ui->m_replacement, TQT_SIGNAL(returnPressed()), this, TQT_SLOT(slotReplaceWord()) ); + connect( d->ui->m_autoCorrect, TQT_SIGNAL(clicked()), + TQT_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 ) { + TQString 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(); +} + +TQString Dialog::originalBuffer() const +{ + return d->originalBuffer; +} + +TQString Dialog::buffer() const +{ + return d->checker->filter()->buffer(); +} + +void Dialog::setBuffer( const TQString& buf ) +{ + d->originalBuffer = buf; +} + +void Dialog::setFilter( Filter *filter ) +{ + filter->setBuffer( d->checker->filter()->buffer() ); + d->checker->setFilter( filter ); +} + +void Dialog::updateDialog( const TQString& word ) +{ + d->ui->m_unknownWord->setText( word ); + d->ui->m_contextLabel->setText( d->checker->filter()->context() ); + TQStringList 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() +{ + TQStringList suggs = d->checker->suggest( d->ui->m_replacement->text() ); + fillSuggestions( suggs ); +} + +void Dialog::slotChangeLanguage( const TQString& lang ) +{ + d->checker->changeLanguage( lang ); + slotSuggest(); +} + +void Dialog::slotSelectionChanged( TQListViewItem *item ) +{ + d->ui->m_replacement->setText( item->text( 0 ) ); +} + +void Dialog::fillSuggestions( const TQStringList& suggs ) +{ + d->ui->m_suggestions->clear(); + for ( TQStringList::ConstIterator it = suggs.begin(); it != suggs.end(); ++it ) { + new TQListViewItem( d->ui->m_suggestions, d->ui->m_suggestions->firstChild(), + *it ); + } +} + +void Dialog::slotMisspelling(const TQString& 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/tdespell2/ui/dialog.h b/tdespell2/ui/dialog.h new file mode 100644 index 000000000..1da714c7c --- /dev/null +++ b/tdespell2/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, + TQWidget *parent, const char *name=0 ); + ~Dialog(); + + TQString originalBuffer() const; + TQString buffer() const; + + void show(); + void activeAutoCorrect( bool _active ); + + public slots: + void setBuffer( const TQString& ); + void setFilter( Filter* filter ); + + signals: + void done( const TQString& newBuffer ); + void misspelling( const TQString& word, int start ); + void replace( const TQString& oldWord, int start, + const TQString& newWord ); + + void stop(); + void cancel(); + void autoCorrect( const TQString & currentWord, const TQString & replaceWord ); + private slots: + void slotMisspelling(const TQString& word, int start ); + void slotDone(); + + void slotFinished(); + void slotCancel(); + + void slotAddWord(); + void slotReplaceWord(); + void slotReplaceAll(); + void slotSkip(); + void slotSkipAll(); + void slotSuggest(); + void slotChangeLanguage( const TQString& ); + void slotSelectionChanged( TQListViewItem * ); + void slotAutocorrect(); + + private: + void updateDialog( const TQString& word ); + void fillSuggestions( const TQStringList& suggs ); + void initConnections(); + void initGui(); + void continueChecking(); + + private: + class Private; + Private *d; + }; +} + +#endif diff --git a/tdespell2/ui/highlighter.cpp b/tdespell2/ui/highlighter.cpp new file mode 100644 index 000000000..2d185462d --- /dev/null +++ b/tdespell2/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 <tqtextedit.h> +#include <tqtimer.h> +#include <tqcolor.h> +#include <tqdict.h> + +namespace KSpell2 { + +class Highlighter::Private +{ +public: + Filter *filter; + Broker::Ptr broker; + Dictionary *dict; + TQDict<Dictionary> dictCache; +}; + +Highlighter::Highlighter( TQTextEdit *textEdit, + const TQString& configFile, + Filter *filter) + : TQSyntaxHighlighter( 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 TQString& 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(); + } + } + //TQTimer::singleShot( 0, this, TQT_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() ); +} + +TQString Highlighter::currentLanguage() const +{ + return d->dict->language(); +} + +void Highlighter::setCurrentLanguage( const TQString& 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/tdespell2/ui/highlighter.h b/tdespell2/ui/highlighter.h new file mode 100644 index 000000000..2309c3a64 --- /dev/null +++ b/tdespell2/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 <tqsyntaxhighlighter.h> + +class TQTextEdit; + +namespace KSpell2 +{ + class Highlighter : public TQSyntaxHighlighter + { + public: + Highlighter( TQTextEdit *textEdit, + const TQString& configFile = TQString::null, + Filter *filter = Filter::defaultFilter() ); + ~Highlighter(); + + virtual int highlightParagraph( const TQString& text, + int endStateOfLastPara ); + + Filter *currentFilter() const; + void setCurrentFilter( Filter *filter ); + + TQString currentLanguage() const; + void setCurrentLanguage( const TQString& 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/tdespell2/ui/tdespell2ui.ui b/tdespell2/ui/tdespell2ui.ui new file mode 100644 index 000000000..e221c69ba --- /dev/null +++ b/tdespell2/ui/tdespell2ui.ui @@ -0,0 +1,324 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>KSpell2UI</class> +<widget class="TQWidget"> + <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="TQLabel" 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="TQLabel" 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="TQLabel" 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="TQLabel" 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="TQPushButton" 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="TQListView" 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="TQLabel" 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="TQLineEdit" 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="TQComboBox" 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="TQLayoutWidget" 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="TQPushButton"> + <property name="name"> + <cstring>m_suggestBtn</cstring> + </property> + <property name="text"> + <string>S&uggest</string> + </property> + </widget> + <widget class="TQPushButton"> + <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="TQPushButton"> + <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="TQPushButton"> + <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="TQPushButton"> + <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="TQPushButton"> + <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> |