2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiThesaurus.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 "GuiThesaurus.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#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
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiThesaurusDialog::GuiThesaurusDialog(GuiThesaurus * form)
|
2007-04-24 14:35:15 +00:00
|
|
|
: 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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::change_adaptor()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::entryChanged()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::replaceClicked()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
form_->replace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::selectionChanged()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
int const col = meaningsTV->currentColumn();
|
|
|
|
if (col<0 || form_->readOnly())
|
|
|
|
return;
|
|
|
|
|
|
|
|
replaceED->setText(meaningsTV->currentItem()->text(col));
|
|
|
|
replacePB->setEnabled(true);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
selectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
entryED->setText(item->text(col));
|
|
|
|
selectionChanged();
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::updateLists()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiThesuarus
|
2007-04-24 14:35:15 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
typedef QController<ControlThesaurus, GuiView<GuiThesaurusDialog> > ThesaurusBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiThesaurus::GuiThesaurus(Dialog & parent)
|
2007-04-24 14:35:15 +00:00
|
|
|
: ThesaurusBase(parent, _("Thesaurus"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurus::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
dialog_.reset(new GuiThesaurusDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().setApply(dialog_->replacePB);
|
|
|
|
bcview().addReadOnly(dialog_->replaceED);
|
|
|
|
bcview().addReadOnly(dialog_->replacePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurus::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
dialog_->entryED->setText(toqstr(controller().text()));
|
|
|
|
dialog_->replaceED->setText("");
|
|
|
|
dialog_->updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurus::replace()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
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
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiThesaurus_moc.cpp"
|