merge QSearch and QSearchDialog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17945 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-04-24 13:27:23 +00:00
parent 888ba9e94b
commit 822fbb710c
5 changed files with 145 additions and 187 deletions

View File

@ -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 \

View File

@ -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 <config.h>
#include "QSearch.h"
#include "QSearchDialog.h"
#include "qt_helpers.h"
#include "Qt2BC.h"
#include "controllers/ControlSearch.h"
#include <qpushbutton.h>
#include <QLineEdit>
#include <QCloseEvent>
using std::string;
namespace lyx {
namespace frontend {
typedef QController<ControlSearch, QView<QSearchDialog> > 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<ControlSearch, QView<QSearchDialog> > 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"

View File

@ -13,14 +13,40 @@
#define QSEARCH_H
#include "QDialogView.h"
#include "QSearchDialog.h"
#include "ui/SearchUi.h"
#include <string>
#include <QDialog>
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<ControlSearch, QView<QSearchDialog> >
{

View File

@ -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 <config.h>
#include "QSearchDialog.h"
#include "QSearch.h"
#include "qt_helpers.h"
//Added by qt3to4:
#include <QCloseEvent>
#include "controllers/ControlSearch.h"
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qpushbutton.h>
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"

View File

@ -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 <string>
#include <QDialog>
#include <QCloseEvent>
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