2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QSpellchecker.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QSpellchecker.h"
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "controllers/ControlSpellchecker.h"
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QProgressBar>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QListWidgetItem>
|
2007-04-24 15:32:14 +00:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-24 15:32:14 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QSpellCheckerDialog
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
QSpellcheckerDialog::QSpellcheckerDialog(QSpellchecker * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
|
|
|
|
|
|
|
|
connect(replaceCO, SIGNAL(highlighted(const QString &)),
|
|
|
|
this, SLOT(replaceChanged(const QString &)));
|
|
|
|
connect(replacePB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(replaceClicked()));
|
|
|
|
connect(ignorePB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(ignoreClicked()));
|
|
|
|
connect(replacePB_3, SIGNAL(clicked()),
|
|
|
|
this, SLOT(acceptClicked()));
|
|
|
|
connect(addPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(addClicked()));
|
|
|
|
connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
|
|
|
this, SLOT(replaceClicked() ) );
|
|
|
|
connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
|
|
|
|
this, SLOT(suggestionChanged(QListWidgetItem*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::acceptClicked()
|
|
|
|
{
|
|
|
|
form_->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::addClicked()
|
|
|
|
{
|
|
|
|
form_->add();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::replaceClicked()
|
|
|
|
{
|
|
|
|
form_->replace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::ignoreClicked()
|
|
|
|
{
|
|
|
|
form_->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
|
|
|
|
{
|
|
|
|
if (replaceCO->count() != 0)
|
|
|
|
replaceCO->setItemText(0, item->text());
|
|
|
|
else
|
|
|
|
replaceCO->addItem(item->text());
|
|
|
|
|
|
|
|
replaceCO->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::replaceChanged(const QString & str)
|
|
|
|
{
|
|
|
|
if (suggestionsLW->currentItem()->text() == str)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < suggestionsLW->count(); ++i) {
|
|
|
|
if (suggestionsLW->item(i)->text() == str) {
|
|
|
|
suggestionsLW->setCurrentRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellcheckerDialog::reject()
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QSpellChecker
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> >
|
|
|
|
SpellcheckerBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
QSpellchecker::QSpellchecker(Dialog & parent)
|
2007-04-24 15:32:14 +00:00
|
|
|
: SpellcheckerBase(parent, _("Spellchecker"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QSpellcheckerDialog(this));
|
|
|
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
dialog_->wordED->setReadOnly(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::update_contents()
|
|
|
|
{
|
2006-12-10 19:00:57 +00:00
|
|
|
if (isVisible() || controller().exitEarly())
|
|
|
|
controller().check();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::accept()
|
|
|
|
{
|
|
|
|
controller().ignoreAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::add()
|
|
|
|
{
|
|
|
|
controller().insert();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::ignore()
|
|
|
|
{
|
|
|
|
controller().check();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::replace()
|
|
|
|
{
|
2006-12-08 19:46:16 +00:00
|
|
|
controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QSpellchecker::partialUpdate(int s)
|
|
|
|
{
|
|
|
|
ControlSpellchecker::State const state =
|
|
|
|
static_cast<ControlSpellchecker::State>(s);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
|
|
|
case ControlSpellchecker::SPELL_PROGRESSED:
|
2006-05-03 19:51:15 +00:00
|
|
|
dialog_->spellcheckPR->setValue(controller().getProgress());
|
2006-03-05 17:24:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ControlSpellchecker::SPELL_FOUND_WORD: {
|
|
|
|
dialog_->wordED->setText(toqstr(controller().getWord()));
|
2006-05-03 19:51:15 +00:00
|
|
|
dialog_->suggestionsLW->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-12-08 19:46:16 +00:00
|
|
|
docstring w;
|
2006-03-05 17:24:44 +00:00
|
|
|
while (!(w = controller().getSuggestion()).empty()) {
|
2006-05-03 19:51:15 +00:00
|
|
|
dialog_->suggestionsLW->addItem(toqstr(w));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
if (dialog_->suggestionsLW->count() == 0) {
|
|
|
|
dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
2006-05-03 19:51:15 +00:00
|
|
|
dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2006-05-03 19:51:15 +00:00
|
|
|
|
|
|
|
dialog_->suggestionsLW->setCurrentRow(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 15:32:14 +00:00
|
|
|
|
|
|
|
#include "QSpellchecker_moc.cpp"
|