-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchdialog.cpp
122 lines (104 loc) · 3.5 KB
/
searchdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <QtGui>
#include "searchdialog.h"
SearchOptions::SearchOptions(QObject *parent):
QObject(parent)
{
regex = false;
caseSensitive = true;
wholeWord = false;
wrap = false;
backwards = false;
start = true;
}
SearchDialog::SearchDialog(QWidget *parent)
: QDialog(parent)
{
options = new SearchOptions();
setWindowTitle("Search/Replace");
QHBoxLayout *input = new QHBoxLayout();
label = new QLabel(tr("Find Text:"));
entry = new QLineEdit();
entry->setMinimumWidth(200);
label->setBuddy(entry);
input->addWidget(label);
input->addWidget(entry);
QHBoxLayout *replace = new QHBoxLayout();
rlabel = new QLabel(tr("Replace With:"));
rentry = new QLineEdit();
rentry->setMinimumWidth(200);
rlabel->setBuddy(rentry);
replace->addWidget(rlabel);
replace->addWidget(rentry);
QVBoxLayout *optionLayout = new QVBoxLayout();
regexCheck = new QCheckBox("&Match Regular Expression");
caseCheck = new QCheckBox("&Match Case");
wholeCheck = new QCheckBox("W&hole Word");
wrapCheck = new QCheckBox("&Wrap Search");
backCheck = new QCheckBox("Search &Backwards");
advCheck = new QCheckBox("Advance on Replace");
regexCheck->setChecked(options->regex);
caseCheck->setChecked(options->caseSensitive);
wholeCheck->setChecked(options->wholeWord);
wrapCheck ->setChecked(options->wrap);
backCheck->setChecked(options->backwards);
advCheck->setChecked(true);
optionLayout->addLayout(input);
optionLayout->addLayout(replace);
optionLayout->addWidget(regexCheck);
optionLayout->addWidget(caseCheck);
optionLayout->addWidget(wholeCheck);
optionLayout->addWidget(wrapCheck);
optionLayout->addWidget(backCheck);
optionLayout->addWidget(advCheck);
QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Vertical);
findButton = new QPushButton(tr("&Find"));
findButton->setDefault(true);
replaceButton = new QPushButton(tr("&Replace"));
cancelButton = new QPushButton(tr("&Close"));
buttons->addButton(findButton, QDialogButtonBox::ActionRole);
buttons->addButton(replaceButton, QDialogButtonBox::ActionRole);
buttons->addButton(cancelButton, QDialogButtonBox::ActionRole);
QGridLayout *mainLayout = new QGridLayout();
mainLayout->addLayout(optionLayout, 0, 0);
mainLayout->addWidget(buttons, 0, 1);
setLayout(mainLayout);
connect(entry, SIGNAL(textChanged(const QString)), this, SLOT(textChanged(const QString)));
connect(entry, SIGNAL(returnPressed()), this, SLOT(findButtonPressed()));
connect(findButton, SIGNAL(pressed()), this, SLOT(findButtonPressed()));
connect(replaceButton, SIGNAL(pressed()), this, SLOT(replaceButtonPressed()));
connect(cancelButton, SIGNAL(pressed()), this, SLOT(close()));
connect(regexCheck, SIGNAL(toggled(bool)), options, SLOT(setRegex(bool)));
connect(caseCheck, SIGNAL(toggled(bool)), options, SLOT(setCaseSensitive(bool)));
connect(wholeCheck, SIGNAL(toggled(bool)), options, SLOT(setWholeWord(bool)));
connect(wrapCheck, SIGNAL(toggled(bool)), options, SLOT(setWrap(bool)));
connect(backCheck, SIGNAL(toggled(bool)), options, SLOT(setBackwards(bool)));
}
void SearchDialog::setSearchText(const QString text)
{
entry->setText(text);
}
void SearchDialog::findButtonPressed()
{
QString text;
text = entry->text();
if (!text.isEmpty()) {
emit searchText(text, options);
}
}
void SearchDialog::replaceButtonPressed()
{
QString text;
text = rentry->text();
if (text.isEmpty())
return;
if (options->start)
return;
emit replaceWithText(text);
if (advCheck->isChecked()) {
findButtonPressed();
}
}
void SearchDialog::textChanged(const QString text)
{
options->start = true;
}