]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QSearchDialog.C
fix bug 2483:
[features.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->setFocus();
65         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
66 }
67
68
69 void QSearchDialog::closeEvent(QCloseEvent * e)
70 {
71         form_->slotWMHide();
72         e->accept();
73 }
74
75
76 void QSearchDialog::findChanged()
77 {
78         if (findCO->currentText().isEmpty()) {
79                 findPB->setEnabled(false);
80                 replacePB->setEnabled(false);
81                 replaceallPB->setEnabled(false);
82         } else {
83                 findPB->setEnabled(true);
84                 replacePB->setEnabled(!form_->readOnly());
85                 replaceallPB->setEnabled(!form_->readOnly());
86         }
87 }
88
89
90 void QSearchDialog::findClicked()
91 {
92         docstring const find(qstring_to_ucs4(findCO->currentText()));
93         form_->find(find,
94                 caseCB->isChecked(),
95                 wordsCB->isChecked(),
96                 backwardsCB->isChecked());
97         uniqueInsert(findCO, findCO->currentText());
98 }
99
100
101 void QSearchDialog::replaceClicked()
102 {
103         docstring const find(qstring_to_ucs4(findCO->currentText()));
104         docstring const replace(qstring_to_ucs4(replaceCO->currentText()));
105         form_->replace(find, replace,
106                 caseCB->isChecked(),
107                 wordsCB->isChecked(),
108                 backwardsCB->isChecked(), false);
109         uniqueInsert(findCO, findCO->currentText());
110         uniqueInsert(replaceCO, replaceCO->currentText());
111 }
112
113
114 void QSearchDialog::replaceallClicked()
115 {
116         form_->replace(qstring_to_ucs4(findCO->currentText()),
117                 qstring_to_ucs4(replaceCO->currentText()),
118                 caseCB->isChecked(),
119                 wordsCB->isChecked(),
120                 false, true);
121         uniqueInsert(findCO, findCO->currentText());
122         uniqueInsert(replaceCO, replaceCO->currentText());
123 }
124
125 } // namespace frontend
126 } // namespace lyx
127
128 #include "QSearchDialog_moc.cpp"