25 #include <qcheckbox.h>
26 #include <qlineedit.h>
27 #include <qtabwidget.h>
28 #include <qvgroupbox.h>
29 #include <qpushbutton.h>
30 #include <qmessagebox.h>
34 : QDialog(App_, 0, true)
38 QVBoxLayout *all =
new QVBoxLayout(
this);
41 QVGroupBox *g1 =
new QVGroupBox(tr(
"Text to search for"),
this);
43 SearchEdit =
new QLineEdit(g1);
45 ReplaceGroup =
new QVGroupBox(tr(
"Text to replace with"),
this);
46 all->addWidget(ReplaceGroup);
47 ReplaceEdit =
new QLineEdit(ReplaceGroup);
49 AskBox =
new QCheckBox(tr(
"Ask before replacing"),
this);
50 all->addWidget(AskBox);
52 PositionBox =
new QCheckBox(tr(
"From cursor position"),
this);
53 all->addWidget(PositionBox);
54 CaseBox =
new QCheckBox(tr(
"Case sensitive"),
this);
55 all->addWidget(CaseBox);
56 WordBox =
new QCheckBox(tr(
"Whole words only"),
this);
57 all->addWidget(WordBox);
58 BackwardBox =
new QCheckBox(tr(
"Search backwards"),
this);
59 all->addWidget(BackwardBox);
61 QHBox *Buttons =
new QHBox(
this);
62 all->addWidget(Buttons);
63 QPushButton *ButtonSearch =
new QPushButton(tr(
"Search"), Buttons);
64 connect(ButtonSearch, SIGNAL(clicked()), SLOT(slotSearch()));
65 connect(
new QPushButton(tr(
"Cancel"), Buttons),
66 SIGNAL(clicked()), SLOT(reject()));
68 ButtonSearch->setDefault(
true);
79 setCaption(tr(
"Replace Text"));
80 AskBox->setHidden(
false);
81 ReplaceGroup->setHidden(
false);
84 setCaption(tr(
"Search Text"));
91 SearchEdit->setText(Doc->selectedText());
92 SearchEdit->selectAll();
94 SearchEdit->setFocus();
103 int Line=0, Column=0, count=0,
i;
105 Doc->getCursorPosition(&Line, &Column);
106 else if(BackwardBox->isChecked())
107 Line = Doc->paragraphs();
109 if(!BackwardBox->isChecked())
112 if(SearchEdit->text().isEmpty())
114 while(Doc->find(SearchEdit->text(), CaseBox->isChecked(),
115 WordBox->isChecked(), !BackwardBox->isChecked(), &Line, &Column)) {
118 if(AskBox->isHidden())
121 i = QMessageBox::Yes;
122 if(AskBox->isChecked()) {
123 i = QMessageBox::information(
this,
124 tr(
"Replace..."), tr(
"Replace occurrence ?"),
125 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No,
126 QMessageBox::Cancel | QMessageBox::Escape);
129 case QMessageBox::Yes:
130 Doc->insert(ReplaceEdit->text());
131 Column += ReplaceEdit->text().length();
133 case QMessageBox::No:
134 Column += SearchEdit->text().length();
141 QMessageBox::information(
this, tr(
"Search..."),
142 tr(
"Search string not found!"));
144 if(!AskBox->isHidden())
145 if(!AskBox->isChecked())
146 QMessageBox::information(
this, tr(
"Replace..."),
147 tr(
"Replaced %1 occurrences!").arg(count));
151 void SearchDialog::slotSearch()