2 * \file QSearchDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QSearchDialog.h"
15 #include "qt_helpers.h"
17 #include <QCloseEvent>
19 #include "controllers/ControlSearch.h"
21 #include <qcheckbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
31 void uniqueInsert(QComboBox * box, QString const & text)
33 for (int i = 0; i < box->count(); ++i) {
34 if (box->itemText(i) == text)
44 QSearchDialog::QSearchDialog(QSearch * form)
49 connect(closePB, SIGNAL(clicked()),
50 form_, SLOT(slotClose()));
52 connect( findPB, SIGNAL( clicked() ), this, SLOT( findClicked() ) );
53 connect( replacePB, SIGNAL( clicked() ), this, SLOT( replaceClicked() ) );
54 connect( replaceallPB, SIGNAL( clicked() ), this, SLOT( replaceallClicked() ) );
55 connect( findCO, SIGNAL( editTextChanged(const QString&) ), this, SLOT( findChanged() ) );
57 setFocusProxy(findCO);
61 void QSearchDialog::show()
65 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
69 void QSearchDialog::closeEvent(QCloseEvent * e)
76 void QSearchDialog::findChanged()
78 if (findCO->currentText().isEmpty()) {
79 findPB->setEnabled(false);
80 replacePB->setEnabled(false);
81 replaceallPB->setEnabled(false);
83 findPB->setEnabled(true);
84 replacePB->setEnabled(!form_->readOnly());
85 replaceallPB->setEnabled(!form_->readOnly());
90 void QSearchDialog::findClicked()
92 docstring const find(qstring_to_ucs4(findCO->currentText()));
96 backwardsCB->isChecked());
97 uniqueInsert(findCO, findCO->currentText());
101 void QSearchDialog::replaceClicked()
103 docstring const find(qstring_to_ucs4(findCO->currentText()));
104 docstring const replace(qstring_to_ucs4(replaceCO->currentText()));
105 form_->replace(find, replace,
107 wordsCB->isChecked(),
108 backwardsCB->isChecked(), false);
109 uniqueInsert(findCO, findCO->currentText());
110 uniqueInsert(replaceCO, replaceCO->currentText());
114 void QSearchDialog::replaceallClicked()
116 form_->replace(qstring_to_ucs4(findCO->currentText()),
117 qstring_to_ucs4(replaceCO->currentText()),
119 wordsCB->isChecked(),
121 uniqueInsert(findCO, findCO->currentText());
122 uniqueInsert(replaceCO, replaceCO->currentText());
125 } // namespace frontend
128 #include "QSearchDialog_moc.cpp"