From fb09d6354c0b6badb449f532f40af9a8037377a3 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Sat, 3 Jul 2010 06:08:59 +0000 Subject: Theme Editor: Removed some old debug code in skindocument.cpp, began implementing a new find/replace dialog, due to licensing issues git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27252 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/findreplace/findreplaceform.cpp | 222 ---------------------- 1 file changed, 222 deletions(-) delete mode 100644 utils/themeeditor/findreplace/findreplaceform.cpp (limited to 'utils/themeeditor/findreplace/findreplaceform.cpp') diff --git a/utils/themeeditor/findreplace/findreplaceform.cpp b/utils/themeeditor/findreplace/findreplaceform.cpp deleted file mode 100644 index cd2700f033..0000000000 --- a/utils/themeeditor/findreplace/findreplaceform.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * This file has been copied from Lorenzo Bettini, with minor modifications - * made available under the LGPL version 3, as the original file was licensed - * - **************************************************************************** - * - * Copyright (C) 2009 Lorenzo Bettini - * See COPYING file that comes with this distribution - */ - -#include -#include -#include -#include - -#include "findreplaceform.h" -#include "ui_findreplaceform.h" - -#define TEXT_TO_FIND "textToFind" -#define TEXT_TO_REPLACE "textToReplace" -#define DOWN_RADIO "downRadio" -#define UP_RADIO "upRadio" -#define CASE_CHECK "caseCheck" -#define WHOLE_CHECK "wholeCheck" -#define REGEXP_CHECK "regexpCheck" - -FindReplaceForm::FindReplaceForm(QWidget *parent) : - QWidget(parent), - ui(new Ui::FindReplaceForm), textEdit(0) -{ - ui->setupUi(this); - - ui->errorLabel->setText(""); - - connect(ui->textToFind, SIGNAL(textChanged(QString)), this, SLOT(textToFindChanged())); - connect(ui->textToFind, SIGNAL(textChanged(QString)), this, SLOT(validateRegExp(QString))); - - connect(ui->regexCheckBox, SIGNAL(toggled(bool)), this, SLOT(regexpSelected(bool))); - - connect(ui->findButton, SIGNAL(clicked()), this, SLOT(find())); - connect(ui->closeButton, SIGNAL(clicked()), parent, SLOT(close())); - - connect(ui->replaceButton, SIGNAL(clicked()), this, SLOT(replace())); - connect(ui->replaceAllButton, SIGNAL(clicked()), this, SLOT(replaceAll())); -} - -FindReplaceForm::~FindReplaceForm() -{ - delete ui; -} - -void FindReplaceForm::hideReplaceWidgets() { - ui->replaceLabel->setVisible(false); - ui->textToReplace->setVisible(false); - ui->replaceButton->setVisible(false); - ui->replaceAllButton->setVisible(false); -} - -void FindReplaceForm::setTextEdit(QPlainTextEdit *textEdit_) { - textEdit = textEdit_; - connect(textEdit, SIGNAL(copyAvailable(bool)), ui->replaceButton, SLOT(setEnabled(bool))); - connect(textEdit, SIGNAL(copyAvailable(bool)), ui->replaceAllButton, SLOT(setEnabled(bool))); -} - -void FindReplaceForm::changeEvent(QEvent *e) -{ - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void FindReplaceForm::textToFindChanged() { - ui->findButton->setEnabled(ui->textToFind->text().size() > 0); -} - -void FindReplaceForm::regexpSelected(bool sel) { - if (sel) - validateRegExp(ui->textToFind->text()); - else - validateRegExp(""); -} - -void FindReplaceForm::validateRegExp(const QString &text) { - if (!ui->regexCheckBox->isChecked() || text.size() == 0) { - ui->errorLabel->setText(""); - return; // nothing to validate - } - - QRegExp reg(text, - (ui->caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive)); - - if (reg.isValid()) { - showError(""); - } else { - showError(reg.errorString()); - } -} - -void FindReplaceForm::showError(const QString &error) { - if (error == "") { - ui->errorLabel->setText(""); - } else { - ui->errorLabel->setText("" + - error + - ""); - } -} - -void FindReplaceForm::showMessage(const QString &message) { - if (message == "") { - ui->errorLabel->setText(""); - } else { - ui->errorLabel->setText("" + - message + - ""); - } -} - -void FindReplaceForm::find() { - find(ui->downRadioButton->isChecked()); -} - -void FindReplaceForm::find(bool next) { - if (!textEdit) - return; // TODO: show some warning? - - // backward search - bool back = !next; - - const QString &toSearch = ui->textToFind->text(); - - bool result = false; - - QTextDocument::FindFlags flags; - - if (back) - flags |= QTextDocument::FindBackward; - if (ui->caseCheckBox->isChecked()) - flags |= QTextDocument::FindCaseSensitively; - if (ui->wholeCheckBox->isChecked()) - flags |= QTextDocument::FindWholeWords; - - if (ui->regexCheckBox->isChecked()) { - QRegExp reg(toSearch, - (ui->caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive)); - - qDebug() << "searching for regexp: " << reg.pattern(); - - textCursor = textEdit->document()->find(reg, textCursor, flags); - textEdit->setTextCursor(textCursor); - result = (!textCursor.isNull()); - } else { - qDebug() << "searching for: " << toSearch; - - result = textEdit->find(toSearch, flags); - } - - if (result) { - showError(""); - } else { - showError(tr("no match found")); - // move to the beginning of the document for the next find - textCursor.setPosition(0); - textEdit->setTextCursor(textCursor); - } -} - -void FindReplaceForm::replace() { - if (!textEdit->textCursor().hasSelection()) { - find(); - } else { - textEdit->textCursor().insertText(ui->textToReplace->text()); - find(); - } -} - -void FindReplaceForm::replaceAll() { - int i=0; - while (textEdit->textCursor().hasSelection()){ - textEdit->textCursor().insertText(ui->textToReplace->text()); - find(); - i++; - } - showMessage(tr("Replaced %1 occurrence(s)").arg(i)); -} - -void FindReplaceForm::writeSettings(QSettings &settings, const QString &prefix) { - settings.beginGroup(prefix); - settings.setValue(TEXT_TO_FIND, ui->textToFind->text()); - settings.setValue(TEXT_TO_REPLACE, ui->textToReplace->text()); - settings.setValue(DOWN_RADIO, ui->downRadioButton->isChecked()); - settings.setValue(UP_RADIO, ui->upRadioButton->isChecked()); - settings.setValue(CASE_CHECK, ui->caseCheckBox->isChecked()); - settings.setValue(WHOLE_CHECK, ui->wholeCheckBox->isChecked()); - settings.setValue(REGEXP_CHECK, ui->regexCheckBox->isChecked()); - settings.endGroup(); -} - -void FindReplaceForm::readSettings(QSettings &settings, const QString &prefix) { - settings.beginGroup(prefix); - ui->textToFind->setText(settings.value(TEXT_TO_FIND, "").toString()); - ui->textToReplace->setText(settings.value(TEXT_TO_REPLACE, "").toString()); - ui->downRadioButton->setChecked(settings.value(DOWN_RADIO, true).toBool()); - ui->upRadioButton->setChecked(settings.value(UP_RADIO, false).toBool()); - ui->caseCheckBox->setChecked(settings.value(CASE_CHECK, false).toBool()); - ui->wholeCheckBox->setChecked(settings.value(WHOLE_CHECK, false).toBool()); - ui->regexCheckBox->setChecked(settings.value(REGEXP_CHECK, false).toBool()); - settings.endGroup(); -} -- cgit v1.2.3