00001
00002
#include "applicationspelltest.h"
00003
#include "applicationspelltest.moc"
00004
00005
#include <qtoolbar.h>
00006
#include <qtoolbutton.h>
00007
#include <qpopupmenu.h>
00008
#include <qmenubar.h>
00009
#include <qstatusbar.h>
00010
#include <qmessagebox.h>
00011
#include <qapplication.h>
00012
#include <qaccel.h>
00013
#include <qtextstream.h>
00014
#include <qpainter.h>
00015
#include <qmultilineedit.h>
00016
#include "koSpell.h"
00017
#include <kdebug.h>
00018
#include <qlayout.h>
00019
00020 ApplicationWindowSpell::ApplicationWindowSpell()
00021 :
QMainWindow( 0, "Spell test", WDestructiveClose )
00022 {
00023
QToolBar * fileTools =
new QToolBar(
this,
"file operations" );
00024 fileTools->setLabel(
"File Operations" );
00025
00026 file =
new QPopupMenu(
this );
00027 menuBar()->insertItem(
"&File", file );
00028
00029
00030 file->insertItem(
"Spell text",
this, SLOT(slotSpellText()));
00031 m_modalSpellCheckMenuIndex = file->insertItem(
"Modal Spell text",
this, SLOT(slotModalSpellText()));
00032
00033 file->insertItem(
"Config",
this, SLOT(slotConfigSpellText()));
00034
00035 file->insertItem(
"Quit",
this, SLOT(close()));
00036
00037 multi =
new QMultiLineEdit(
this,
"editor" );
00038 connect( multi, SIGNAL( selectionChanged ()),
this, SLOT( slotSelectionChanged()));
00039 multi->setFocus();
00040 setCentralWidget( multi );
00041 resize( 450, 600 );
00042 m_spell = 0L;
00043 m_spellConfig=
new KOSpellConfig();
00044 file->setItemEnabled( m_modalSpellCheckMenuIndex,
false );
00045 }
00046
00047
00048 ApplicationWindowSpell::~ApplicationWindowSpell()
00049 {
00050
delete m_spell;
00051
delete m_spellConfig;
00052 }
00053
00054
void ApplicationWindowSpell::slotSelectionChanged()
00055 {
00056 file->setItemEnabled( m_modalSpellCheckMenuIndex, multi->hasSelectedText () );
00057 }
00058
00059
void ApplicationWindowSpell::slotModalSpellText()
00060 {
00061
QString text = multi->selectedText();
00062
if ( !text.isEmpty() )
00063 {
00064 kdDebug(30006)<<
" text :"<<text<<endl;
00065 KOSpell::modalCheck( text, 0L );
00066 kdDebug(30006)<<
" after : text :"<<text<<endl;
00067 }
00068 }
00069
00070
void ApplicationWindowSpell::slotSpellText()
00071 {
00072
if ( m_spell )
00073
return;
00074 m_spell =KOSpell::createKoSpell(
this,
"test" ,0L,0L,m_spellConfig,
true,
true );
00075
00076
00077 QObject::connect( m_spell, SIGNAL( death() ),
00078
this, SLOT( spellCheckerFinished() ) );
00079 QObject::connect( m_spell, SIGNAL( misspelling(
const QString &,
const QStringList &,
unsigned int ) ),
00080
this, SLOT( spellCheckerMisspelling(
const QString &,
const QStringList &,
unsigned int ) ) );
00081 QObject::connect( m_spell, SIGNAL( corrected(
const QString &,
const QString &,
unsigned int ) ),
00082
this, SLOT( spellCheckerCorrected(
const QString &,
const QString &,
unsigned int ) ) );
00083 QObject::connect( m_spell, SIGNAL( done(
const QString & ) ),
00084
this, SLOT( spellCheckerDone(
const QString & ) ) );
00085 QObject::connect( m_spell, SIGNAL( ignoreall (
const QString & ) ),
00086
this, SLOT( spellCheckerIgnoreAll(
const QString & ) ) );
00087
00088 QObject::connect( m_spell, SIGNAL( replaceall(
const QString &,
const QString & )),
00089
this, SLOT( spellCheckerReplaceAll(
const QString &,
const QString & )));
00090
bool result = m_spell->check( multi->text());
00091
if ( !result)
00092 {
00093
delete m_spell;
00094 m_spell=0L;
00095 }
00096 }
00097
00098
void ApplicationWindowSpell::slotConfigSpellText()
00099 {
00100 spellConfig *conf =
new spellConfig(
this,
this );
00101 conf->exec();
00102
delete conf;
00103 }
00104
00105
00106
void ApplicationWindowSpell::spellCheckerFinished()
00107 {
00108 kdDebug(30006)<<
" void ApplicationWindowSpell::spellCheckerFinished() \n";
00109
delete m_spell;
00110 m_spell= 0L;
00111 }
00112
00113
void ApplicationWindowSpell::spellCheckerMisspelling(
const QString &text,
const QStringList &,
unsigned int pos)
00114 {
00115 kdDebug(30006)<<
" void ApplicationWindowSpell::spellCheckerMisspelling( const QString &text, const QStringList &, unsigned int ) :"<<text<<
" pos :"<<pos<<endl;
00116
00117 kdDebug(30006)<<
" pos :"<<pos<<
" text :"<<text<<
" text.length() :"<<text.length()<<endl;
00118
unsigned int l = 0;
00119
unsigned int cnt = 0;
00120 posToRowCol (pos, l, cnt);
00121 multi->setSelection(l, cnt, l, cnt+text.length());
00122 }
00123
00124
void ApplicationWindowSpell::spellCheckerCorrected(
const QString &orig ,
const QString & newWord ,
unsigned int pos )
00125 {
00126
if( orig != newWord )
00127 {
00128
unsigned int l = 0;
00129
unsigned int cnt = 0;
00130 kdDebug(30006)<<
"void ApplicationWindowSpell::spellCheckerCorrected( const QString &, const QString &, unsigned int ) :"<<orig<<
" new :"<<newWord<<
" pos :"<<pos <<endl;
00131 posToRowCol (pos, l, cnt);
00132 multi->setSelection(l, cnt, l, cnt+orig.length());
00133 multi->removeSelectedText();
00134 multi->insert(newWord);
00135 }
00136 }
00137
00138
void ApplicationWindowSpell::posToRowCol(
unsigned int pos,
unsigned int &line,
unsigned int &col)
00139 {
00140
for (line = 0; line < static_cast<uint>(multi->lines()) && col <= pos; line++)
00141 {
00142 col += multi->paragraphLength(line)+1;
00143 }
00144 line--;
00145 col = pos - col + multi->paragraphLength(line) + 1;
00146 }
00147
00148
00149
void ApplicationWindowSpell::spellCheckerDone(
const QString & text)
00150 {
00151 kdDebug(30006)<<
"void ApplicationWindowSpell::spellCheckerDone( const QString & ) :"<<text<<endl;
00152 }
00153
00154
void ApplicationWindowSpell::spellCheckerIgnoreAll(
const QString &text )
00155 {
00156 kdDebug(30006)<<
"void ApplicationWindowSpell::spellCheckerIgnoreAll( const QString & ) :"<<text<<endl;
00157 }
00158
00159
void ApplicationWindowSpell::spellCheckerReplaceAll(
const QString & text,
const QString & replace)
00160 {
00161 kdDebug(30006)<<
" void ApplicationWindowSpell::spellCheckerReplaceAll( const QString & , const QString & ) :"<<text<<
" replace:"<<replace<< endl;
00162 }
00163
00164
void ApplicationWindowSpell::closeEvent(
QCloseEvent* ce )
00165 {
00166 ce->accept();
00167 }
00168
00169
void ApplicationWindowSpell::changeConfig(
KOSpellConfig _kspell)
00170 {
00171
if(m_spellConfig==0)
00172 m_spellConfig=
new KOSpellConfig();
00173 m_spellConfig->setNoRootAffix(_kspell.
noRootAffix ());
00174 m_spellConfig->setRunTogether(_kspell.
runTogether ());
00175 m_spellConfig->setDictionary(_kspell.
dictionary ());
00176 m_spellConfig->setDictFromList(_kspell.
dictFromList());
00177 m_spellConfig->setEncoding(_kspell.
encoding());
00178 }
00179
00180
00181 spellConfig::spellConfig(
QWidget* parent,ApplicationWindowSpell *_spell )
00182 : KDialogBase( parent, "urldialog", true, "config",
00183 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true )
00184 {
00185 m_spell = _spell;
00186
QWidget *page =
new QWidget(
this );
00187 setMainWidget(page);
00188
QVBoxLayout *topLayout =
new QVBoxLayout( page, 0, spacingHint() );
00189
00190 config =
new KOSpellConfig( page );
00191 topLayout->addWidget( config );
00192 connect(
this, SIGNAL(okClicked()),
this,SLOT(slotApply()));
00193 }
00194
00195
void spellConfig::slotApply()
00196 {
00197 m_spell->changeConfig(*config);
00198 }
00199