-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinddialog.cpp
More file actions
129 lines (105 loc) · 3.59 KB
/
finddialog.cpp
File metadata and controls
129 lines (105 loc) · 3.59 KB
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
123
124
125
126
127
128
129
#include "finddialog.h"
#include <QHBoxLayout>
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)
{
initializeWidgets();
// Ensures that the line edit gets the focus whenever the dialog is the active window
setFocusProxy(findLineEdit);
initializeLayout();
setWindowTitle(tr("Find and Replace"));
connect(findNextButton, SIGNAL(clicked()), this, SLOT(on_findNextButton_clicked()));
connect(replaceButton, SIGNAL(clicked()), this, SLOT(on_replaceOperation_initiated()));
connect(replaceAllButton, SIGNAL(clicked()), this, SLOT(on_replaceOperation_initiated()));
}
/* Performs all required memory cleanup operations.
*/
FindDialog::~FindDialog()
{
delete findLabel;
delete replaceLabel;
delete findLineEdit;
delete replaceLineEdit;
delete findNextButton;
delete replaceButton;
delete replaceAllButton;
delete caseSensitiveCheckBox;
delete wholeWordsCheckBox;
delete findHorizontalLayout;
delete replaceHorizontalLayout;
delete optionsLayout;
delete verticalLayout;
}
/* Initialize
*/
void FindDialog::initializeWidgets()
{
findLabel = new QLabel(tr("Find what: "));
replaceLabel = new QLabel(tr("Replace with:"));
findLineEdit = new QLineEdit();
replaceLineEdit = new QLineEdit();
findNextButton = new QPushButton(tr("&Find next"));
replaceButton = new QPushButton(tr("&Replace"));
replaceAllButton = new QPushButton(tr("&Replace all"));
caseSensitiveCheckBox = new QCheckBox(tr("&Match case"));
wholeWordsCheckBox = new QCheckBox(tr("&Whole words"));
}
/* Defines this FindDialog's layout
*/
void FindDialog::initializeLayout()
{
findHorizontalLayout = new QHBoxLayout();
replaceHorizontalLayout = new QHBoxLayout();
optionsLayout = new QHBoxLayout();
verticalLayout = new QVBoxLayout();
verticalLayout->addLayout(findHorizontalLayout);
verticalLayout->addLayout(replaceHorizontalLayout);
verticalLayout->addLayout(optionsLayout);
findHorizontalLayout->addWidget(findLabel);
findHorizontalLayout->addWidget(findLineEdit);
replaceHorizontalLayout->addWidget(replaceLabel);
replaceHorizontalLayout->addWidget(replaceLineEdit);
optionsLayout->addWidget(caseSensitiveCheckBox);
optionsLayout->addWidget(wholeWordsCheckBox);
optionsLayout->addWidget(findNextButton);
optionsLayout->addWidget(replaceButton);
optionsLayout->addWidget(replaceAllButton);
setLayout(verticalLayout);
}
/* User clicked Find Next button. If the query is empty, it informs the user.
*/
void FindDialog::on_findNextButton_clicked()
{
QString query = findLineEdit->text();
if (query.isEmpty())
{
QMessageBox::information(this, tr("Empty Field"), tr("Please enter a query."));
return;
}
bool caseSensitive = caseSensitiveCheckBox->isChecked();
bool wholeWords = wholeWordsCheckBox->isChecked();
emit(startFinding(query, caseSensitive, wholeWords));
}
/* User clicked Replace or Replace All button.
*/
void FindDialog::on_replaceOperation_initiated()
{
QString what = findLineEdit->text();
if (what.isEmpty())
{
QMessageBox::information(this, tr("Empty Field"), tr("Please enter a query."));
return;
}
QString with = replaceLineEdit->text();
bool caseSensitive = caseSensitiveCheckBox->isChecked();
bool wholeWords = wholeWordsCheckBox->isChecked();
bool replace = sender() == replaceButton;
if (replace)
{
emit(startReplacing(what, with, caseSensitive, wholeWords));
}
else
{
emit(startReplacingAll(what, with, caseSensitive, wholeWords));
}
}