From 822fbb710c4ae51c866f409bb2914a717f0616e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 24 Apr 2007 13:27:23 +0000 Subject: [PATCH] merge QSearch and QSearchDialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17945 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Makefile.dialogs | 2 +- src/frontends/qt4/QSearch.C | 120 ++++++++++++++++++++++++++- src/frontends/qt4/QSearch.h | 30 ++++++- src/frontends/qt4/QSearchDialog.C | 127 ----------------------------- src/frontends/qt4/QSearchDialog.h | 53 ------------ 5 files changed, 145 insertions(+), 187 deletions(-) delete mode 100644 src/frontends/qt4/QSearchDialog.C delete mode 100644 src/frontends/qt4/QSearchDialog.h diff --git a/src/frontends/qt4/Makefile.dialogs b/src/frontends/qt4/Makefile.dialogs index 33f32d3228..aeccea2826 100644 --- a/src/frontends/qt4/Makefile.dialogs +++ b/src/frontends/qt4/Makefile.dialogs @@ -119,7 +119,7 @@ MOCFILES = \ QParagraphDialog.C QParagraphDialog.h \ QPrefsDialog.C QPrefsDialog.h \ QRefDialog.C QRefDialog.h \ - QSearchDialog.C QSearchDialog.h \ + QSearch.C QSearch.h \ QSendtoDialog.C QSendtoDialog.h \ qsetborder.C qsetborder.h \ QShowFileDialog.C QShowFileDialog.h \ diff --git a/src/frontends/qt4/QSearch.C b/src/frontends/qt4/QSearch.C index 11107b5e00..1a0c72efe1 100644 --- a/src/frontends/qt4/QSearch.C +++ b/src/frontends/qt4/QSearch.C @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Edwin Leuven * * Full author contact details are available in file CREDITS. */ @@ -11,23 +12,130 @@ #include #include "QSearch.h" -#include "QSearchDialog.h" +#include "qt_helpers.h" #include "Qt2BC.h" #include "controllers/ControlSearch.h" -#include +#include +#include using std::string; namespace lyx { namespace frontend { -typedef QController > search_base_class; + +///////////////////////////////////////////////////////////////////// +// +// QSearchDialog +// +///////////////////////////////////////////////////////////////////// + + +static void uniqueInsert(QComboBox * box, QString const & text) +{ + for (int i = 0; i < box->count(); ++i) { + if (box->itemText(i) == text) + return; + } + + box->addItem(text); +} + + +QSearchDialog::QSearchDialog(QSearch * form) + : form_(form) +{ + setupUi(this); + + connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked())); + connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked())); + connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked())); + connect(findCO, SIGNAL(editTextChanged(const QString &)), + this, SLOT(findChanged())); + + setFocusProxy(findCO); +} + + +void QSearchDialog::show() +{ + QDialog::show(); + findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length()); +} + + +void QSearchDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} + + +void QSearchDialog::findChanged() +{ + if (findCO->currentText().isEmpty()) { + findPB->setEnabled(false); + replacePB->setEnabled(false); + replaceallPB->setEnabled(false); + } else { + findPB->setEnabled(true); + replacePB->setEnabled(!form_->readOnly()); + replaceallPB->setEnabled(!form_->readOnly()); + } +} + + +void QSearchDialog::findClicked() +{ + docstring const find = qstring_to_ucs4(findCO->currentText()); + form_->find(find, + caseCB->isChecked(), + wordsCB->isChecked(), + backwardsCB->isChecked()); + uniqueInsert(findCO, findCO->currentText()); +} + + +void QSearchDialog::replaceClicked() +{ + docstring const find = qstring_to_ucs4(findCO->currentText()); + docstring const replace = qstring_to_ucs4(replaceCO->currentText()); + form_->replace(find, replace, + caseCB->isChecked(), + wordsCB->isChecked(), + backwardsCB->isChecked(), false); + uniqueInsert(findCO, findCO->currentText()); + uniqueInsert(replaceCO, replaceCO->currentText()); +} + + +void QSearchDialog::replaceallClicked() +{ + form_->replace(qstring_to_ucs4(findCO->currentText()), + qstring_to_ucs4(replaceCO->currentText()), + caseCB->isChecked(), + wordsCB->isChecked(), + false, true); + uniqueInsert(findCO, findCO->currentText()); + uniqueInsert(replaceCO, replaceCO->currentText()); +} + + +///////////////////////////////////////////////////////////////////// +// +// QSearch +// +///////////////////////////////////////////////////////////////////// + + +typedef QController > SearchBase; QSearch::QSearch(Dialog & parent) - : search_base_class(parent, _("Find and Replace")) + : SearchBase(parent, _("Find and Replace")) { } @@ -62,3 +170,7 @@ void QSearch::replace(docstring const & findstr, docstring const & replacestr, } // namespace frontend } // namespace lyx + + +#include "QSearch_moc.cpp" + diff --git a/src/frontends/qt4/QSearch.h b/src/frontends/qt4/QSearch.h index c7a316b7c2..0c279c3750 100644 --- a/src/frontends/qt4/QSearch.h +++ b/src/frontends/qt4/QSearch.h @@ -13,14 +13,40 @@ #define QSEARCH_H #include "QDialogView.h" -#include "QSearchDialog.h" +#include "ui/SearchUi.h" +#include + +#include namespace lyx { namespace frontend { class ControlSearch; -/// +class QSearch; + +class QSearchDialog : public QDialog, public Ui::QSearchUi { + Q_OBJECT +public: + QSearchDialog(QSearch * form); + + virtual void show(); +protected Q_SLOTS: + void findChanged(); + void findClicked(); + void replaceClicked(); + void replaceallClicked(); +protected: + virtual void closeEvent(QCloseEvent * e); + +private: + // add a string to the combo if needed + void remember(std::string const & find, QComboBox & combo); + + QSearch * form_; +}; + + class QSearch : public QController > { diff --git a/src/frontends/qt4/QSearchDialog.C b/src/frontends/qt4/QSearchDialog.C deleted file mode 100644 index 819d82585b..0000000000 --- a/src/frontends/qt4/QSearchDialog.C +++ /dev/null @@ -1,127 +0,0 @@ -/** - * \file QSearchDialog.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "QSearchDialog.h" -#include "QSearch.h" -#include "qt_helpers.h" -//Added by qt3to4: -#include - -#include "controllers/ControlSearch.h" - -#include -#include -#include - - -namespace lyx { -namespace frontend { - -namespace { - -void uniqueInsert(QComboBox * box, QString const & text) -{ - for (int i = 0; i < box->count(); ++i) { - if (box->itemText(i) == text) - return; - } - - box->addItem(text); -} - -}; - - -QSearchDialog::QSearchDialog(QSearch * form) - : form_(form) -{ - setupUi(this); - - connect(closePB, SIGNAL(clicked()), - form_, SLOT(slotClose())); - - connect( findPB, SIGNAL( clicked() ), this, SLOT( findClicked() ) ); - connect( replacePB, SIGNAL( clicked() ), this, SLOT( replaceClicked() ) ); - connect( replaceallPB, SIGNAL( clicked() ), this, SLOT( replaceallClicked() ) ); - connect( findCO, SIGNAL( editTextChanged(const QString&) ), this, SLOT( findChanged() ) ); - - setFocusProxy(findCO); -} - - -void QSearchDialog::show() -{ - QDialog::show(); - findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length()); -} - - -void QSearchDialog::closeEvent(QCloseEvent * e) -{ - form_->slotWMHide(); - e->accept(); -} - - -void QSearchDialog::findChanged() -{ - if (findCO->currentText().isEmpty()) { - findPB->setEnabled(false); - replacePB->setEnabled(false); - replaceallPB->setEnabled(false); - } else { - findPB->setEnabled(true); - replacePB->setEnabled(!form_->readOnly()); - replaceallPB->setEnabled(!form_->readOnly()); - } -} - - -void QSearchDialog::findClicked() -{ - docstring const find(qstring_to_ucs4(findCO->currentText())); - form_->find(find, - caseCB->isChecked(), - wordsCB->isChecked(), - backwardsCB->isChecked()); - uniqueInsert(findCO, findCO->currentText()); -} - - -void QSearchDialog::replaceClicked() -{ - docstring const find(qstring_to_ucs4(findCO->currentText())); - docstring const replace(qstring_to_ucs4(replaceCO->currentText())); - form_->replace(find, replace, - caseCB->isChecked(), - wordsCB->isChecked(), - backwardsCB->isChecked(), false); - uniqueInsert(findCO, findCO->currentText()); - uniqueInsert(replaceCO, replaceCO->currentText()); -} - - -void QSearchDialog::replaceallClicked() -{ - form_->replace(qstring_to_ucs4(findCO->currentText()), - qstring_to_ucs4(replaceCO->currentText()), - caseCB->isChecked(), - wordsCB->isChecked(), - false, true); - uniqueInsert(findCO, findCO->currentText()); - uniqueInsert(replaceCO, replaceCO->currentText()); -} - -} // namespace frontend -} // namespace lyx - -#include "QSearchDialog_moc.cpp" diff --git a/src/frontends/qt4/QSearchDialog.h b/src/frontends/qt4/QSearchDialog.h deleted file mode 100644 index cf997e33fa..0000000000 --- a/src/frontends/qt4/QSearchDialog.h +++ /dev/null @@ -1,53 +0,0 @@ -// -*- C++ -*- -/** - * \file QSearchDialog.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Edwin Leuven - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef QSEARCHDIALOG_H -#define QSEARCHDIALOG_H - -#include "ui/SearchUi.h" -#include - -#include -#include - -class QCloseEvent; -class QComboBox; - -namespace lyx { -namespace frontend { - -class QSearch; - -class QSearchDialog : public QDialog, public Ui::QSearchUi { - Q_OBJECT -public: - QSearchDialog(QSearch * form); - - virtual void show(); -protected Q_SLOTS: - void findChanged(); - void findClicked(); - void replaceClicked(); - void replaceallClicked(); -protected: - virtual void closeEvent(QCloseEvent * e); - -private: - // add a string to the combo if needed - void remember(std::string const & find, QComboBox & combo); - - QSearch * form_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // QSEARCHDIALOG_H