diff options
Diffstat (limited to 'utils/themeeditor/gui/findreplacedialog.cpp')
-rw-r--r-- | utils/themeeditor/gui/findreplacedialog.cpp | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/utils/themeeditor/gui/findreplacedialog.cpp b/utils/themeeditor/gui/findreplacedialog.cpp deleted file mode 100644 index 2a6161189e..0000000000 --- a/utils/themeeditor/gui/findreplacedialog.cpp +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "findreplacedialog.h" | ||
23 | #include "ui_findreplacedialog.h" | ||
24 | |||
25 | #include <QTextBlock> | ||
26 | |||
27 | FindReplaceDialog::FindReplaceDialog(QWidget *parent) : | ||
28 | QDialog(parent), | ||
29 | ui(new Ui::FindReplaceDialog), editor(0), textFound() | ||
30 | { | ||
31 | ui->setupUi(this); | ||
32 | setupUI(); | ||
33 | } | ||
34 | |||
35 | FindReplaceDialog::~FindReplaceDialog() | ||
36 | { | ||
37 | delete ui; | ||
38 | } | ||
39 | |||
40 | void FindReplaceDialog::changeEvent(QEvent *e) | ||
41 | { | ||
42 | QDialog::changeEvent(e); | ||
43 | switch (e->type()) { | ||
44 | case QEvent::LanguageChange: | ||
45 | ui->retranslateUi(this); | ||
46 | break; | ||
47 | default: | ||
48 | break; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void FindReplaceDialog::closeEvent(QCloseEvent* event) | ||
53 | { | ||
54 | ui->statusLabel->setText(""); | ||
55 | event->accept(); | ||
56 | } | ||
57 | |||
58 | void FindReplaceDialog::setupUI() | ||
59 | { | ||
60 | QObject::connect(ui->findButton, SIGNAL(clicked()), | ||
61 | this, SLOT(find())); | ||
62 | QObject::connect(ui->replaceButton, SIGNAL(clicked()), | ||
63 | this, SLOT(replace())); | ||
64 | QObject::connect(ui->replaceAllButton, SIGNAL(clicked()), | ||
65 | this, SLOT(replaceAll())); | ||
66 | QObject::connect(ui->closeButton, SIGNAL(clicked()), | ||
67 | this, SLOT(close())); | ||
68 | QObject::connect(ui->findBox, SIGNAL(textChanged(QString)), | ||
69 | this, SLOT(textChanged())); | ||
70 | |||
71 | textChanged(); | ||
72 | } | ||
73 | |||
74 | void FindReplaceDialog::find() | ||
75 | { | ||
76 | |||
77 | if(!editor) | ||
78 | return; | ||
79 | |||
80 | QTextDocument::FindFlags flags = 0; | ||
81 | if(ui->caseBox->isChecked()) | ||
82 | flags |= QTextDocument::FindCaseSensitively; | ||
83 | if(ui->backwardsBox->isChecked()) | ||
84 | flags |= QTextDocument::FindBackward; | ||
85 | |||
86 | QTextCursor start = textFound.isNull() ? editor->textCursor() : textFound; | ||
87 | |||
88 | textFound = editor->document()->find(ui->findBox->text(), start, flags); | ||
89 | |||
90 | if(textFound.isNull() && ui->wrapBox->isChecked()) | ||
91 | { | ||
92 | if(ui->backwardsBox->isChecked()) | ||
93 | { | ||
94 | textFound = editor->document() | ||
95 | ->find(ui->findBox->text(), | ||
96 | editor->document()->toPlainText().length(), | ||
97 | flags); | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | textFound = editor->document()->find(ui->findBox->text(), 0, flags); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | QPalette newPal; | ||
106 | if(!textFound.isNull()) | ||
107 | { | ||
108 | newPal.setColor(QPalette::Foreground, QColor(0, 150, 0)); | ||
109 | ui->statusLabel->setPalette(newPal); | ||
110 | ui->statusLabel->setText(tr("Match Found")); | ||
111 | editor->setTextCursor(textFound); | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | newPal.setColor(QPalette::Foreground, Qt::red); | ||
116 | ui->statusLabel->setPalette(newPal); | ||
117 | ui->statusLabel->setText(tr("Match Not Found")); | ||
118 | editor->setTextCursor(start); | ||
119 | } | ||
120 | |||
121 | } | ||
122 | |||
123 | void FindReplaceDialog::replace() | ||
124 | { | ||
125 | if(textFound.isNull()) | ||
126 | find(); | ||
127 | |||
128 | if(textFound.isNull()) | ||
129 | return; | ||
130 | |||
131 | editor->setTextCursor(textFound); | ||
132 | editor->insertPlainText(ui->replaceBox->text()); | ||
133 | textFound = QTextCursor(); | ||
134 | } | ||
135 | |||
136 | void FindReplaceDialog::replaceAll() | ||
137 | { | ||
138 | |||
139 | do | ||
140 | { | ||
141 | if(!textFound.isNull()) | ||
142 | { | ||
143 | editor->setTextCursor(textFound); | ||
144 | editor->insertPlainText(ui->replaceBox->text()); | ||
145 | } | ||
146 | |||
147 | find(); | ||
148 | }while(!textFound.isNull()); | ||
149 | |||
150 | } | ||
151 | |||
152 | void FindReplaceDialog::textChanged() | ||
153 | { | ||
154 | bool enabled = ui->findBox->text() != ""; | ||
155 | |||
156 | ui->findButton->setEnabled(enabled); | ||
157 | ui->replaceButton->setEnabled(enabled); | ||
158 | ui->replaceAllButton->setEnabled(enabled); | ||
159 | } | ||