2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiSpellchecker.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* 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>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSpellchecker.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.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
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiSpellCheckerDialog
|
2007-04-24 15:32:14 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiSpellcheckerDialog::GuiSpellcheckerDialog(GuiSpellchecker * form)
|
2007-04-24 15:32:14 +00:00
|
|
|
: 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*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::acceptClicked()
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->accept();
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::addClicked()
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->add();
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::replaceClicked()
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->replace();
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::ignoreClicked()
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->ignore();
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
if (replaceCO->count() != 0)
|
|
|
|
replaceCO->setItemText(0, item->text());
|
|
|
|
else
|
|
|
|
replaceCO->addItem(item->text());
|
|
|
|
|
|
|
|
replaceCO->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::replaceChanged(const QString & str)
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
if (suggestionsLW->currentItem()->text() == str)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < suggestionsLW->count(); ++i) {
|
|
|
|
if (suggestionsLW->item(i)->text() == str) {
|
|
|
|
suggestionsLW->setCurrentRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellcheckerDialog::reject()
|
2007-04-24 15:32:14 +00:00
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiSpellChecker
|
2007-04-24 15:32:14 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiSpellchecker::GuiSpellchecker(Dialog & parent)
|
2007-08-31 22:16:11 +00:00
|
|
|
: GuiView<GuiSpellcheckerDialog>(parent, _("Spellchecker"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
dialog_.reset(new GuiSpellcheckerDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
dialog_->wordED->setReadOnly(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-12-10 19:00:57 +00:00
|
|
|
if (isVisible() || controller().exitEarly())
|
|
|
|
controller().check();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::accept()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
controller().ignoreAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::add()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
controller().insert();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::ignore()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
controller().check();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::replace()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-12-08 19:46:16 +00:00
|
|
|
controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSpellchecker::partialUpdate(int s)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSpellchecker_moc.cpp"
|