Debian Codegraph @

finddialog.cpp

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #include "finddialog.h"
42
43 /**
44 * @file finddialog.cpp
45 * Implements the find text widget.
46 */
47
48 FindDialog::FindDialog(QWidget *parent)
49 : QWidget(parent)
50 {
51 searchLabel = new QLabel(tr("Find what:"));
52 searchEdit = new QLineEdit;
53 searchLabel->setBuddy(searchEdit);
54
55 replaceLabel = new QLabel(tr("Replace with:"));
56 replaceEdit = new QLineEdit;
57 replaceLabel->setBuddy(replaceEdit);
58
59 caseCheckBox = new QCheckBox(tr("Match case"));
60
61 findButton = new QPushButton(tr("Find next"));
62 findButton->setDefault(true);
63 findButton->setEnabled(false);
64
65 findAllButton = new QPushButton(tr("Find all"));
66 findAllButton->setAutoDefault(true);
67 findAllButton->setEnabled(false);
68
69 replaceButton = new QPushButton(tr("Replace"));
70 replaceButton->setAutoDefault(true);
71 replaceButton->setEnabled(false);
72
73 replaceAllButton = new QPushButton(tr("Replace all"));
74 replaceAllButton->setAutoDefault(true);
75 replaceAllButton->setEnabled(false);
76
77 closeButton = new QPushButton(tr("Close"));
78 closeButton->setAutoDefault(true);
79
80 connect(searchEdit, SIGNAL(textChanged(const QString &)),
81 this, SLOT(enableFindButton(const QString &)));
82 connect(searchEdit, SIGNAL(returnPressed()),
83 findButton, SLOT(click()));
84
85 connect(replaceEdit, SIGNAL(returnPressed()),
86 replaceButton, SLOT(click()));
87
88 connect(findButton, SIGNAL(clicked()),
89 this, SLOT(findClicked()));
90
91 connect(findAllButton, SIGNAL(clicked()),
92 this, SLOT(findAllClicked()));
93
94 connect(replaceButton, SIGNAL(clicked()),
95 this, SLOT(replaceClicked()));
96
97 connect(replaceAllButton, SIGNAL(clicked()),
98 this, SLOT(replaceAllClicked()));
99
100 connect(closeButton, SIGNAL(clicked()),
101 this, SLOT(close()));
102
103 replaceLayout = new QHBoxLayout;
104 replaceLayout->addWidget(replaceLabel);
105 replaceLayout->addWidget(replaceEdit);
106
107 searchLayout = new QHBoxLayout;
108 searchLayout->addWidget(searchLabel);
109 searchSpacer = new QSpacerItem(
110 replaceLabel->fontMetrics().horizontalAdvance(tr("Replace with:")) -
111 searchLabel->fontMetrics().horizontalAdvance(tr("Find what:")),
112 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
113 searchLayout->addSpacerItem(searchSpacer);
114 searchLayout->addWidget(searchEdit);
115
116 replaceButtonLayout = new QHBoxLayout;
117 replaceButtonLayout->addWidget(replaceButton);
118 replaceButtonLayout->addWidget(replaceAllButton);
119
120 leftLayout = new QVBoxLayout;
121 leftLayout->addLayout(searchLayout);
122 leftLayout->addWidget(caseCheckBox);
123 leftLayout->addSpacing(20);
124 leftLayout->addLayout(replaceLayout);
125 leftLayout->addLayout(replaceButtonLayout);
126
127 rightLayout = new QVBoxLayout;
128 rightLayout->addWidget(findButton);
129 rightLayout->addWidget(findAllButton);
130 rightLayout->addWidget(closeButton);
131 rightLayout->addStretch();
132
133 mainLayout = new QHBoxLayout;
134 mainLayout->addLayout(leftLayout);
135 mainLayout->addLayout(rightLayout);
136 setLayout(mainLayout);
137
138 setWindowFlags(Qt::Dialog);
139 setWindowTitle(tr("Find and replace"));
140 setFixedHeight(sizeHint().height());
141 }
142
143 void FindDialog::enableFindButton(const QString &text)
144 {
145 findButton->setEnabled(!text.isEmpty());
146 findAllButton->setEnabled(!text.isEmpty());
147 replaceButton->setEnabled(!text.isEmpty());
148 replaceAllButton->setEnabled(!text.isEmpty());
149 }
150
151 void FindDialog::findClicked()
152 {
153 QString text = searchEdit->text();
154 Qt::CaseSensitivity cs =
155 caseCheckBox->isChecked() ? Qt::CaseSensitive
156 : Qt::CaseInsensitive;
157
158 emit findNext(text, cs, false, false);
159 }
160
161 void FindDialog::findAllClicked()
162 {
163 QString text = searchEdit->text();
164 Qt::CaseSensitivity cs =
165 caseCheckBox->isChecked() ? Qt::CaseSensitive
166 : Qt::CaseInsensitive;
167
168 emit findNext(text, cs, true, false);
169 }
170
171 void FindDialog::replaceClicked()
172 {
173 QString text = searchEdit->text();
174 Qt::CaseSensitivity cs =
175 caseCheckBox->isChecked() ? Qt::CaseSensitive
176 : Qt::CaseInsensitive;
177
178 emit findNext(text, cs, false, true, replaceEdit->text());
179 }
180
181 void FindDialog::replaceAllClicked()
182 {
183 QString text = searchEdit->text();
184 Qt::CaseSensitivity cs =
185 caseCheckBox->isChecked() ? Qt::CaseSensitive
186 : Qt::CaseInsensitive;
187
188 emit findNext(text, cs, true, true, replaceEdit->text());
189 }
190
191 bool FindDialog::close()
192 {
193 emit findNext(QString(), Qt::CaseSensitive, true, false);
194 return QWidget::close();
195 }
196
197 void FindDialog::setSearchText(const QString &text)
198 {
199 searchEdit->setText(text);
200 }
201
202 void FindDialog::keyPressEvent(QKeyEvent *e)
203 {
204 switch(e->key())
205 {
206 case Qt::Key_Escape:
207 close();
208 break;
209 default:
210 QWidget::keyPressEvent(e);
211 }
212 }
213
214 void FindDialog::showEvent(QShowEvent *e)
215 {
216 searchEdit->setFocus();
217 e->accept();
218 }
219
220 void FindDialog::closeEvent(QCloseEvent *e)
221 {
222 close();
223 e->accept();
224 }
225
226 FindDialog::~FindDialog()
227 {
228 delete searchLabel;
229 delete replaceLabel;
230 delete searchEdit;
231 delete replaceEdit;
232 delete caseCheckBox;
233 delete findButton;
234 delete findAllButton;
235 delete replaceButton;
236 delete replaceAllButton;
237 delete closeButton;
238 delete replaceLayout;
239 delete searchLayout;
240 delete replaceButtonLayout;
241 delete leftLayout;
242 delete rightLayout;
243 delete mainLayout;
244 }