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"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
#include "ControlThesaurus.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-04-24 14:35:15 +00:00
|
|
|
#include "debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QCloseEvent>
|
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
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv)
|
|
|
|
: GuiDialog(lv, "thesaurus")
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setViewTitle(_("Thesaurus"));
|
|
|
|
setController(new ControlThesaurus(*this));
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
meaningsTV->setColumnCount(1);
|
|
|
|
meaningsTV->header()->hide();
|
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(slotClose()));
|
2007-04-24 14:35:15 +00:00
|
|
|
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-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
bc().setApply(replacePB);
|
|
|
|
bc().addReadOnly(replaceED);
|
|
|
|
bc().addReadOnly(replacePB);
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 18:33:42 +00:00
|
|
|
ControlThesaurus & GuiThesaurusDialog::controller()
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
return static_cast<ControlThesaurus &>(GuiDialog::controller());
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::change_adaptor()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiThesaurusDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2007-04-24 14:35:15 +00:00
|
|
|
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::selectionChanged()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
int const col = meaningsTV->currentColumn();
|
2007-09-11 18:33:42 +00:00
|
|
|
if (col < 0 || controller().isBufferReadonly())
|
2007-04-24 14:35:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
replaceED->setText(meaningsTV->currentItem()->text(col));
|
|
|
|
replacePB->setEnabled(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
Thesaurus::Meanings meanings = controller().getMeanings(qstring_to_ucs4(entryED->text()));
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
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-09-11 18:33:42 +00:00
|
|
|
void GuiThesaurusDialog::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
entryED->setText(toqstr(controller().text()));
|
|
|
|
replaceED->setText("");
|
|
|
|
updateLists();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
void GuiThesaurusDialog::replaceClicked()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().replace(qstring_to_ucs4(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"
|