merge QThesaurus and QThesaurusDialog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17950 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-04-24 14:35:15 +00:00
parent 8dcd22492d
commit 998a68b13e
5 changed files with 155 additions and 191 deletions

View File

@ -127,7 +127,7 @@ MOCFILES = \
QTabularCreateDialog.C QTabularCreateDialog.h \
QTabularDialog.C QTabularDialog.h \
QTexinfoDialog.C QTexinfoDialog.h \
QThesaurusDialog.C QThesaurusDialog.h \
QThesaurus.C QThesaurus.h \
TocModel.C TocModel.h \
TocWidget.C TocWidget.h \
QToc.C QToc.h \

View File

@ -11,22 +11,141 @@
#include <config.h>
#include "QThesaurus.h"
#include "QThesaurusDialog.h"
#include "Qt2BC.h"
#include "qt_helpers.h"
#include "debug.h"
#include "controllers/ControlThesaurus.h"
#include <QHeaderView>
#include <QLineEdit>
#include <QPushButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
using std::string;
namespace lyx {
namespace frontend {
typedef QController<ControlThesaurus, QView<QThesaurusDialog> > theasaurus_base_class;
/////////////////////////////////////////////////////////////////////
//
// 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;
QThesaurus::QThesaurus(Dialog & parent)
: theasaurus_base_class(parent, _("Thesaurus"))
: ThesaurusBase(parent, _("Thesaurus"))
{
}
@ -57,3 +176,6 @@ void QThesaurus::replace()
} // namespace frontend
} // namespace lyx
#include "QThesaurus_moc.cpp"

View File

@ -13,13 +13,41 @@
#define QTHESAURUS_H
#include "QDialogView.h"
#include "QThesaurusDialog.h"
#include "ui/ThesaurusUi.h"
#include <QDialog>
#include <QCloseEvent>
class QTreeWidgetItem;
namespace lyx {
namespace frontend {
class ControlThesaurus;
class QThesaurus;
class QThesaurusDialog : public QDialog, public Ui::QThesaurusUi {
Q_OBJECT
public:
QThesaurusDialog(QThesaurus * form);
void updateLists();
protected Q_SLOTS:
virtual void change_adaptor();
virtual void entryChanged();
virtual void replaceClicked();
virtual void selectionChanged();
virtual void selectionClicked(QTreeWidgetItem *, int);
virtual void itemClicked(QTreeWidgetItem *, int);
protected:
virtual void closeEvent(QCloseEvent * e);
private:
QThesaurus * form_;
};
///
class QThesaurus
: public QController<ControlThesaurus, QView<QThesaurusDialog> >

View File

@ -1,137 +0,0 @@
/**
* \file QThesaurusDialog.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 "QThesaurusDialog.h"
#include "QThesaurus.h"
#include "qt_helpers.h"
#include "debug.h"
#include "controllers/ControlThesaurus.h"
#include <QCloseEvent>
#include <QPushButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QLineEdit>
#include <QHeaderView>
using std::string;
namespace lyx {
namespace frontend {
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();
}
} // namespace frontend
} // namespace lyx
#include "QThesaurusDialog_moc.cpp"

View File

@ -1,49 +0,0 @@
// -*- C++ -*-
/**
* \file QThesaurusDialog.h
* 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.
*/
#ifndef QTHESAURUSDIALOG_H
#define QTHESAURUSDIALOG_H
#include "ui/ThesaurusUi.h"
#include <QDialog>
#include <QCloseEvent>
class QTreeWidgetItem;
namespace lyx {
namespace frontend {
class QThesaurus;
class QThesaurusDialog : public QDialog, public Ui::QThesaurusUi {
Q_OBJECT
public:
QThesaurusDialog(QThesaurus * form);
void updateLists();
protected Q_SLOTS:
virtual void change_adaptor();
virtual void entryChanged();
virtual void replaceClicked();
virtual void selectionChanged();
virtual void selectionClicked(QTreeWidgetItem *, int);
virtual void itemClicked(QTreeWidgetItem *, int);
protected:
virtual void closeEvent(QCloseEvent * e);
private:
QThesaurus * form_;
};
} // namespace frontend
} // namespace lyx
#endif // QTHESAURUSDIALOG_H