]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSearchDialog.C
renaming in frontends/qt4/ui: s/Q//g
[lyx.git] / src / frontends / qt4 / QSearchDialog.C
1 /**
2  * \file QSearchDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QSearchDialog.h"
14 #include "QSearch.h"
15 #include "qt_helpers.h"
16 //Added by qt3to4:
17 #include <QCloseEvent>
18
19 #include "controllers/ControlSearch.h"
20
21 #include <qcheckbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24
25
26 namespace lyx {
27 namespace frontend {
28
29 namespace {
30
31 void uniqueInsert(QComboBox * box, QString const & text)
32 {
33         for (int i = 0; i < box->count(); ++i) {
34                 if (box->itemText(i) == text)
35                         return;
36         }
37
38         box->addItem(text);
39 }
40
41 };
42
43
44 QSearchDialog::QSearchDialog(QSearch * form)
45         : form_(form)
46 {
47         setupUi(this);
48
49         connect(closePB, SIGNAL(clicked()),
50                 form_, SLOT(slotClose()));
51
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() ) );
56
57         setFocusProxy(findCO);
58 }
59
60
61 void QSearchDialog::show()
62 {
63         QDialog::show();
64         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
65 }
66
67
68 void QSearchDialog::closeEvent(QCloseEvent * e)
69 {
70         form_->slotWMHide();
71         e->accept();
72 }
73
74
75 void QSearchDialog::findChanged()
76 {
77         if (findCO->currentText().isEmpty()) {
78                 findPB->setEnabled(false);
79                 replacePB->setEnabled(false);
80                 replaceallPB->setEnabled(false);
81         } else {
82                 findPB->setEnabled(true);
83                 replacePB->setEnabled(!form_->readOnly());
84                 replaceallPB->setEnabled(!form_->readOnly());
85         }
86 }
87
88
89 void QSearchDialog::findClicked()
90 {
91         docstring const find(qstring_to_ucs4(findCO->currentText()));
92         form_->find(find,
93                 caseCB->isChecked(),
94                 wordsCB->isChecked(),
95                 backwardsCB->isChecked());
96         uniqueInsert(findCO, findCO->currentText());
97 }
98
99
100 void QSearchDialog::replaceClicked()
101 {
102         docstring const find(qstring_to_ucs4(findCO->currentText()));
103         docstring const replace(qstring_to_ucs4(replaceCO->currentText()));
104         form_->replace(find, replace,
105                 caseCB->isChecked(),
106                 wordsCB->isChecked(),
107                 backwardsCB->isChecked(), false);
108         uniqueInsert(findCO, findCO->currentText());
109         uniqueInsert(replaceCO, replaceCO->currentText());
110 }
111
112
113 void QSearchDialog::replaceallClicked()
114 {
115         form_->replace(qstring_to_ucs4(findCO->currentText()),
116                 qstring_to_ucs4(replaceCO->currentText()),
117                 caseCB->isChecked(),
118                 wordsCB->isChecked(),
119                 false, true);
120         uniqueInsert(findCO, findCO->currentText());
121         uniqueInsert(replaceCO, replaceCO->currentText());
122 }
123
124 } // namespace frontend
125 } // namespace lyx
126
127 #include "QSearchDialog_moc.cpp"