Debian Codegraph @

src/findreplace.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #include "findreplace.h"
24 #include "documentpage.h"
25
26 FindReplace::FindReplace(QWidget *parent,
27 QTextEdit *document,
28 QString *lastSearch,
29 QString *lastReplace,
30 bool *lastCaseSensitive)
31 : QDialog(parent), m_document(document), m_lastSearch(lastSearch),
32 m_lastReplace(lastReplace),
33 m_lastCaseSensitive(lastCaseSensitive)
34 {
35 setupUi(this);
36 this->setModal(false);
37 connect(findPushButton, SIGNAL(released()), this, SLOT(find()));
38 connect(replacePushButton, SIGNAL(released()), this, SLOT(replace()));
39 connect(replaceAllPushButton, SIGNAL(released()), this, SLOT(replaceAll()));
40 connect(closePushButton, SIGNAL(released()), this, SLOT(close()));
41
42 findLineEdit->setText(*m_lastSearch);
43 findLineEdit->setFocus(Qt::PopupFocusReason);
44 replaceLineEdit->setText(*m_lastReplace);
45 caseCheckBox->setChecked(*m_lastCaseSensitive);
46 }
47
48 FindReplace::~FindReplace()
49 {
50 }
51
52 void FindReplace::find()
53 {
54 *m_lastCaseSensitive = caseCheckBox->isChecked();
55 *m_lastSearch = findLineEdit->text();
56 *m_lastReplace = replaceLineEdit->text();
57 emit(findString(*m_lastSearch));
58 }
59
60 void FindReplace::replace()
61 {
62 if (m_document->textCursor().selectedText() == findLineEdit->text()) {
63 m_document->insertPlainText(replaceLineEdit->text());
64 find();
65 }
66 else {
67 find();
68 }
69 }
70
71 void FindReplace::replaceAll()
72 {
73 int count = 0;
74 if (m_document->textCursor().selectedText() != findLineEdit->text())
75 find();
76 while (m_document->textCursor().selectedText() == findLineEdit->text()) {
77 m_document->insertPlainText(replaceLineEdit->text());
78 find();
79 count++;
80 }
81 QMessageBox::information (this, "Replace All", QString("String replaced %1 times").arg(count));
82 close();
83 }
84
85