diff --git a/src/frontends/qt4/Makefile.dialogs b/src/frontends/qt4/Makefile.dialogs index 668e5c2cd7..aa65de0d6e 100644 --- a/src/frontends/qt4/Makefile.dialogs +++ b/src/frontends/qt4/Makefile.dialogs @@ -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 \ diff --git a/src/frontends/qt4/QThesaurus.C b/src/frontends/qt4/QThesaurus.C index 4e92c9ec1d..23de2813b3 100644 --- a/src/frontends/qt4/QThesaurus.C +++ b/src/frontends/qt4/QThesaurus.C @@ -11,22 +11,141 @@ #include #include "QThesaurus.h" -#include "QThesaurusDialog.h" #include "Qt2BC.h" #include "qt_helpers.h" +#include "debug.h" #include "controllers/ControlThesaurus.h" +#include #include #include +#include +#include + +using std::string; namespace lyx { namespace frontend { -typedef QController > 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::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 > 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" diff --git a/src/frontends/qt4/QThesaurus.h b/src/frontends/qt4/QThesaurus.h index b31f16bf27..e4beedf21b 100644 --- a/src/frontends/qt4/QThesaurus.h +++ b/src/frontends/qt4/QThesaurus.h @@ -13,13 +13,41 @@ #define QTHESAURUS_H #include "QDialogView.h" -#include "QThesaurusDialog.h" +#include "ui/ThesaurusUi.h" + +#include +#include + + +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 > diff --git a/src/frontends/qt4/QThesaurusDialog.C b/src/frontends/qt4/QThesaurusDialog.C deleted file mode 100644 index a28e5a029a..0000000000 --- a/src/frontends/qt4/QThesaurusDialog.C +++ /dev/null @@ -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 - -#include "QThesaurusDialog.h" -#include "QThesaurus.h" -#include "qt_helpers.h" -#include "debug.h" - -#include "controllers/ControlThesaurus.h" - -#include -#include -#include -#include -#include -#include - -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::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" diff --git a/src/frontends/qt4/QThesaurusDialog.h b/src/frontends/qt4/QThesaurusDialog.h deleted file mode 100644 index e34f4f6ad9..0000000000 --- a/src/frontends/qt4/QThesaurusDialog.h +++ /dev/null @@ -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 -#include - -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