2
JuffEd - An advanced text editor
3
Copyright 2007-2009 Mikhail Murzin
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
version 2 as published by the Free Software Foundation.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <QtGui/QKeyEvent>
23
#include <QtGui/QLineEdit>
25
#include "IconManager.h"
26
#include "MainSettings.h"
31
QString FindDlg::lastString_ = "";
32
QString FindDlg::lastReplaceText_ = "";
33
bool FindDlg::matchCase_ = true;
34
bool FindDlg::backward_ = false;
35
bool FindDlg::regExpMode_ = false;
36
bool FindDlg::wholeWords_ = false;
37
bool FindDlg::multiLine_ = false;
38
QStringList FindDlg::strings_;
39
QStringList FindDlg::replaces_;
41
FindDlg::FindDlg(QWidget* parent, bool repl) :
46
foreach (QString str, strings_)
47
uiFind.findCmb->addItem(str);
48
foreach (QString repl, replaces_)
49
uiFind.replaceCmb->addItem(repl);
51
uiFind.findCmb->setCompleter(0);
52
uiFind.replaceCmb->setCompleter(0);
54
connect(uiFind.findBtn, SIGNAL(clicked()), SLOT(accept()));
55
connect(uiFind.cancelBtn, SIGNAL(clicked()), SLOT(reject()));
56
connect(uiFind.replaceChk, SIGNAL(toggled(bool)), SLOT(setReplaceMode(bool)));
57
connect(uiFind.multiLineChk, SIGNAL(toggled(bool)), SLOT(multiLineChecked(bool)));
58
connect(uiFind.regexpChk, SIGNAL(toggled(bool)), SLOT(regExpChecked(bool)));
60
uiFind.findCmb->setEditText(lastString_);
61
uiFind.mlEd->setText(lastString_);
62
uiFind.replaceCmb->setEditText(lastReplaceText_);
63
uiFind.matchCaseChk->setChecked(matchCase_);
64
uiFind.backwardChk->setChecked(backward_);
65
uiFind.replaceChk->setChecked(false);
66
uiFind.regexpChk->setChecked(regExpMode_);
67
uiFind.multiLineChk->setChecked(multiLine_);
68
uiFind.wholeWordsChk->setChecked(wholeWords_);
72
uiFind.findCmb->setFocus();
73
uiFind.findCmb->lineEdit()->selectAll();
76
uiFind.mlEd->setFocus();
77
uiFind.mlEd->selectAll();
79
uiFind.mlEd->setVisible(multiLine_);
80
uiFind.findCmb->setVisible(!multiLine_);
82
resize(MainSettings::findDlgRect().size());
86
lastReplaceText_ = uiFind.replaceCmb->currentText();
87
matchCase_ = uiFind.matchCaseChk->isChecked();
88
backward_ = uiFind.backwardChk->isChecked();
89
regExpMode_ = uiFind.regexpChk->isChecked();
90
wholeWords_ = uiFind.wholeWordsChk->isChecked();
91
multiLine_ = uiFind.multiLineChk->isChecked();
93
lastString_ = uiFind.mlEd->toPlainText();
96
lastString_ = uiFind.findCmb->currentText();
99
MainSettings::setFindDlgRect(rect());
101
if ( strings_.contains(lastString_) )
102
strings_.removeAll(lastString_);
103
if ( replaces_.contains(lastReplaceText_) )
104
replaces_.removeAll(lastReplaceText_);
105
if ( !lastString_.isEmpty() )
106
strings_.prepend(lastString_);
107
if ( !lastReplaceText_.isEmpty() )
108
replaces_.prepend(lastReplaceText_);
111
void FindDlg::setText(const QString& t) {
112
if ( uiFind.multiLineChk->isChecked() ) {
113
uiFind.mlEd->setText(t);
114
uiFind.mlEd->selectAll();
117
if ( !t.isEmpty() ) {
118
uiFind.findCmb->insertItem(0, t);
119
uiFind.findCmb->setCurrentIndex(0);
120
uiFind.findCmb->lineEdit()->selectAll();
125
QString FindDlg::text() const {
126
if ( uiFind.multiLineChk->isChecked() )
127
return uiFind.mlEd->toPlainText();
129
return uiFind.findCmb->currentText();
132
QString FindDlg::replaceTo() const {
133
QString replStr = uiFind.replaceCmb->currentText();
134
replStr.replace("\\n", "\n");
135
replStr.replace("\\r", "\r");
136
replStr.replace("\\t", "\t");
140
DocFindFlags FindDlg::flags() const {
141
return DocFindFlags(uiFind.replaceChk->isChecked(), uiFind.matchCaseChk->isChecked(),
142
uiFind.backwardChk->isChecked(), uiFind.regexpChk->isChecked(),
143
uiFind.wholeWordsChk->isChecked(), uiFind.multiLineChk->isChecked());
146
void FindDlg::keyPressEvent(QKeyEvent* e) {
147
if ( ( e->key() == Qt::Key_F || e->key() == Qt::Key_R ) && e->modifiers() & Qt::ControlModifier) {
148
uiFind.replaceChk->toggle();
150
QDialog::keyPressEvent(e);
153
void FindDlg::setReplaceMode(bool replaceMode) {
155
uiFind.findBtn->setText(tr("Replace"));
156
uiFind.findBtn->setIcon(IconManager::instance()->getIcon(ID_REPLACE));
157
setWindowTitle(tr("Replace"));
158
uiFind.replaceCmb->setFocus();
159
uiFind.replaceCmb->lineEdit()->selectAll();
162
uiFind.findBtn->setText(tr("Find"));
163
uiFind.findBtn->setIcon(IconManager::instance()->getIcon(ID_FIND));
164
setWindowTitle(tr("Find"));
166
if (uiFind.replaceChk->isChecked() != replaceMode)
167
uiFind.replaceChk->setChecked(replaceMode);
170
void FindDlg::multiLineChecked(bool chk) {
172
uiFind.lowerSpacer->changeSize(0, 0, QSizePolicy::Minimum, QSizePolicy::Fixed);
173
uiFind.mlEd->setText(uiFind.findCmb->currentText());
176
uiFind.findCmb->setEditText(uiFind.mlEd->toPlainText());
177
uiFind.lowerSpacer->changeSize(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
181
void FindDlg::regExpChecked(bool chk) {
183
if ( uiFind.multiLineChk->isChecked() ) {
185
uiFind.multiLineChk->setChecked(false);
189
uiFind.multiLineChk->setChecked(multiLine_);