-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchdialog.cpp
112 lines (91 loc) · 3.26 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
#include "searchdialog.h"
#include "ui_searchdialog.h"
#include "codeeditor.h"
#include <QPalette>
#include <QColor>
SearchDialog::SearchDialog(CodeEditor *parent , bool bReplace)
: QDialog(parent)
, ui(new Ui::SearchDialog),codeEditor(parent)
{
ui->setupUi(this);
ui->toolButtonShowReplace->setDefaultAction(ui->actionactionShowReplace);
showReplace(bReplace);
loadOptions();
ui->labelStatus->setText("");
QPalette plt ;
plt.setColor(QPalette::ColorRole::WindowText,Qt::blue);
ui->labelStatus->setPalette(plt);
}
void SearchDialog::loadOptions(){
SearchOptions &options = codeEditor->searchOption;
ui->checkBoxMachcase->setChecked(options.matchcase);
ui->checkBoxReverse->setChecked(options.backward);
ui->checkBoxRewind->setChecked(options.rewind);
ui->checkBoxWholeWord->setChecked(options.wholeworld);
QString text = codeEditor->textCursor().selectedText();
if(text.isEmpty()) text = options.substr;
ui->lineEditSearch->setText(text);
ui->lineEditReplace->setText(options.toReplace);
}
void SearchDialog::saveOptions(){
SearchOptions &options = codeEditor->searchOption;
options.matchcase = ui->checkBoxMachcase->isChecked();
options.rewind = ui->checkBoxRewind->isChecked();
options.wholeworld = ui->checkBoxWholeWord->isChecked();
options.backward = ui->checkBoxReverse->isChecked();
options.substr = ui ->lineEditSearch->text();
options.toReplace = ui->lineEditReplace->text();
}
SearchDialog::~SearchDialog()
{
delete ui;
}
void SearchDialog::showResultMsg(QString str)
{
ui->labelStatus->setText(str);
}
void SearchDialog::on_toolButtonShowReplace_toggled(bool checked)
{
showReplace(checked);
}
void SearchDialog::showReplace(bool show)
{
ui->groupBoxReplace->setVisible(show);
ui->toolButtonShowReplace->setChecked(show);
if(show){
QWidget::setTabOrder({ui->lineEditSearch,ui->lineEditReplace,ui->pushButtonReplace,
ui->pushButtonReplaceAll,ui->pushButtonFind,ui->checkBoxReverse,ui->checkBoxMachcase,
ui->checkBoxWholeWord,ui->checkBoxRewind,ui->toolButtonShowReplace});
}
else{
QWidget::setTabOrder({ui->lineEditSearch,ui->pushButtonFind,
ui->checkBoxReverse,ui->checkBoxMachcase,
ui->checkBoxWholeWord,ui->checkBoxRewind,ui->toolButtonShowReplace});
}
}
void SearchDialog::on_pushButtonFind_clicked()
{
saveOptions();
QString toFind = ui->lineEditSearch->text();
bool find = codeEditor->searchInEditor(toFind);
QString msg = find ? "" : codeEditor->getFindFailMsg(toFind);
ui->labelStatus->setText(msg);
if(find)
{
QPalette palette = codeEditor->palette();
palette.setColor(QPalette::Highlight,palette.color(QPalette::Active,QPalette::Highlight));
codeEditor->setPalette(palette);
}
}
void SearchDialog::on_pushButtonReplace_clicked()
{
saveOptions();
QString msg = codeEditor->replace(ui->lineEditSearch->text(),ui->lineEditReplace->text());
showResultMsg(msg);
}
void SearchDialog::on_pushButtonReplaceAll_clicked()
{
saveOptions();
QString msg = codeEditor->replaceAll(ui->lineEditSearch->text(),ui->lineEditReplace->text());
showResultMsg(msg);
}