2001-09-01 03:52:21 +00:00
|
|
|
/**
|
|
|
|
* \file QSpellchecker.C
|
2002-09-24 13:57:09 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-09-01 03:52:21 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author John Levon
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-09-01 03:52:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
#include "ControlSpellchecker.h"
|
|
|
|
#include "QSpellcheckerDialog.h"
|
|
|
|
#include "QSpellchecker.h"
|
|
|
|
#include "Qt2BC.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2002-11-28 16:16:58 +00:00
|
|
|
#include "debug.h"
|
2001-09-01 03:52:21 +00:00
|
|
|
|
|
|
|
#include <qprogressbar.h>
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <qmessagebox.h>
|
2001-09-01 03:52:21 +00:00
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
|
|
|
|
typedef Qt2CB<ControlSpellchecker, Qt2DB<QSpellcheckerDialog> > base_class;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
QSpellchecker::QSpellchecker()
|
2002-12-17 20:37:13 +00:00
|
|
|
: base_class(qt_("Spellchecker"))
|
2001-09-01 03:52:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QSpellcheckerDialog(this));
|
|
|
|
|
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
dialog_->wordED->setReadOnly(true);
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
void QSpellchecker::update_contents()
|
|
|
|
{
|
|
|
|
dialog_->wordED->setText("");
|
|
|
|
dialog_->replaceCO->clear();
|
|
|
|
dialog_->suggestionsLB->clear();
|
2002-12-12 21:07:20 +00:00
|
|
|
dialog_->spellcheckPR->setProgress(0);
|
2003-01-13 09:17:12 +00:00
|
|
|
dialog_->spellcheckPB->setEnabled(true);
|
|
|
|
dialog_->wordED->setEnabled(false);
|
|
|
|
dialog_->replaceCO->setEnabled(false);
|
|
|
|
dialog_->replacePB->setEnabled(false);
|
|
|
|
dialog_->ignorePB->setEnabled(false);
|
|
|
|
dialog_->replacePB_3->setEnabled(false);
|
|
|
|
dialog_->addPB->setEnabled(false);
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
void QSpellchecker::accept()
|
|
|
|
{
|
|
|
|
controller().ignoreAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::add()
|
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
controller().insert();
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::ignore()
|
|
|
|
{
|
|
|
|
controller().check();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::replace()
|
|
|
|
{
|
2002-12-17 20:37:13 +00:00
|
|
|
controller().replace(fromqstr(dialog_->replaceCO->currentText()));
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::spellcheck()
|
|
|
|
{
|
|
|
|
dialog_->spellcheckPB->setEnabled(false);
|
2003-01-13 09:17:12 +00:00
|
|
|
dialog_->wordED->setEnabled(true);
|
|
|
|
dialog_->replaceCO->setEnabled(true);
|
|
|
|
dialog_->replacePB->setEnabled(true);
|
|
|
|
dialog_->ignorePB->setEnabled(true);
|
|
|
|
dialog_->replacePB_3->setEnabled(true);
|
|
|
|
dialog_->addPB->setEnabled(true);
|
|
|
|
controller().check();
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::stop()
|
|
|
|
{
|
|
|
|
controller().stop();
|
|
|
|
dialog_->spellcheckPB->setEnabled(true);
|
2002-03-21 21:21:28 +00:00
|
|
|
hide();
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
void QSpellchecker::partialUpdate(int id)
|
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
case 0:
|
|
|
|
dialog_->spellcheckPR->setProgress(controller().getProgress());
|
|
|
|
break;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-28 15:41:48 +00:00
|
|
|
case 1: {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->wordED->setText(toqstr(controller().getWord()));
|
2001-09-01 03:52:21 +00:00
|
|
|
dialog_->suggestionsLB->clear();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
string w;
|
|
|
|
while (!(w = controller().getSuggestion()).empty()) {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->suggestionsLB->insertItem(toqstr(w));
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
2002-12-12 21:07:20 +00:00
|
|
|
|
2003-02-15 22:26:27 +00:00
|
|
|
if (dialog_->suggestionsLB->count() == 0) {
|
|
|
|
dialog_->suggestionChanged(dialog_->wordED->text());
|
|
|
|
} else {
|
|
|
|
dialog_->suggestionChanged(dialog_->suggestionsLB->text(0));
|
|
|
|
}
|
2001-09-01 03:52:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2001-09-01 03:52:21 +00:00
|
|
|
case 2:
|
|
|
|
dialog_->spellcheckPB->setEnabled(true);
|
|
|
|
hide();
|
2002-12-17 20:37:13 +00:00
|
|
|
QMessageBox::information(0, qt_("Spellcheck complete"),
|
|
|
|
toqstr(controller().getMessage()),
|
|
|
|
qt_("OK"));
|
2001-09-01 03:52:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|