2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QThesaurus.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 "QThesaurus.h"
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
2007-04-24 14:35:15 +00:00
|
|
|
#include "debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "controllers/ControlThesaurus.h"
|
|
|
|
|
2007-04-24 14:35:15 +00:00
|
|
|
#include <QHeaderView>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2007-04-24 14:35:15 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
|
|
|
using std::string;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-24 14:35:15 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QTheasurusDialog
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
meaningsTV->setColumnCount(1);
|
|
|
|
meaningsTV->header()->hide();
|
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotClose()));
|
|
|
|
connect(replaceED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(replaceClicked()));
|
|
|
|
connect(replaceED, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(change_adaptor() ) );
|
|
|
|
connect(entryED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(entryChanged()));
|
|
|
|
connect(replacePB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(replaceClicked()));
|
|
|
|
connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(itemClicked(QTreeWidgetItem *, int)));
|
|
|
|
connect(meaningsTV, SIGNAL(itemSelectionChanged()),
|
|
|
|
this, SLOT(selectionChanged()));
|
|
|
|
connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::entryChanged()
|
|
|
|
{
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::replaceClicked()
|
|
|
|
{
|
|
|
|
form_->replace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::selectionChanged()
|
|
|
|
{
|
|
|
|
int const col = meaningsTV->currentColumn();
|
|
|
|
if (col<0 || form_->readOnly())
|
|
|
|
return;
|
|
|
|
|
|
|
|
replaceED->setText(meaningsTV->currentItem()->text(col));
|
|
|
|
replacePB->setEnabled(true);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
|
|
|
|
{
|
|
|
|
selectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
|
|
|
|
{
|
|
|
|
entryED->setText(item->text(col));
|
|
|
|
selectionChanged();
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurusDialog::updateLists()
|
|
|
|
{
|
|
|
|
meaningsTV->clear();
|
|
|
|
meaningsTV->setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text()));
|
|
|
|
|
|
|
|
for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
|
|
|
|
cit != meanings.end(); ++cit) {
|
|
|
|
QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
|
|
|
|
i->setText(0, toqstr(cit->first));
|
|
|
|
meaningsTV->expandItem(i);
|
|
|
|
for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
|
|
|
|
cit2 != cit->second.end(); ++cit2) {
|
|
|
|
QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
|
|
|
|
i2->setText(0, toqstr(*cit2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meaningsTV->setUpdatesEnabled(true);
|
|
|
|
meaningsTV->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QThesuarus
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef QController<ControlThesaurus, QView<QThesaurusDialog> > ThesaurusBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
QThesaurus::QThesaurus(Dialog & parent)
|
2007-04-24 14:35:15 +00:00
|
|
|
: ThesaurusBase(parent, _("Thesaurus"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurus::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QThesaurusDialog(this));
|
|
|
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().setApply(dialog_->replacePB);
|
|
|
|
bcview().addReadOnly(dialog_->replaceED);
|
|
|
|
bcview().addReadOnly(dialog_->replacePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurus::update_contents()
|
|
|
|
{
|
|
|
|
dialog_->entryED->setText(toqstr(controller().text()));
|
|
|
|
dialog_->replaceED->setText("");
|
|
|
|
dialog_->updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QThesaurus::replace()
|
|
|
|
{
|
2006-12-10 11:52:46 +00:00
|
|
|
controller().replace(qstring_to_ucs4(dialog_->replaceED->text()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "QThesaurus_moc.cpp"
|