]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSearchDialog.C
enable Font cache only for MacOSX and inline width() for other platform.
[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 using std::string;
26
27 namespace lyx {
28 namespace frontend {
29
30 namespace {
31
32 void uniqueInsert(QComboBox * box, QString const & text)
33 {
34         for (int i = 0; i < box->count(); ++i) {
35                 if (box->itemText(i) == text)
36                         return;
37         }
38
39         box->addItem(text);
40 }
41
42 };
43
44
45 QSearchDialog::QSearchDialog(QSearch * form)
46         : form_(form)
47 {
48         setupUi(this);
49
50         connect(closePB, SIGNAL(clicked()),
51                 form_, SLOT(slotClose()));
52
53     connect( findPB, SIGNAL( clicked() ), this, SLOT( findClicked() ) );
54     connect( replacePB, SIGNAL( clicked() ), this, SLOT( replaceClicked() ) );
55     connect( replaceallPB, SIGNAL( clicked() ), this, SLOT( replaceallClicked() ) );
56     connect( findCO, SIGNAL( textChanged(const QString&) ), this, SLOT( findChanged() ) );
57 }
58
59
60 void QSearchDialog::show()
61 {
62         QDialog::show();
63         findCO->setFocus();
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         string const find(fromqstr(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         string const find(fromqstr(findCO->currentText()));
103         string const replace(fromqstr(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(fromqstr(findCO->currentText()),
116                 fromqstr(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"