Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/dialogs/searchdialog.cpp
Go to the documentation of this file.
00001 /*
00002  * searchdialog.cpp - implementation of search dialog
00003  *
00004  * Copyright (C) 2006, Michael Margraf, michael.margraf@alumni.tu-berlin.de
00005  * Copyright (C) 2014, Yodalee, lc85301@gmail.com
00006  *
00007  * This file is part of Qucs
00008  *
00009  * Qucs is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013  *
00014  * This software is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with Qucs.  If not, see <http://www.gnu.org/licenses/>.
00021  *
00022  */
00023 
00024 #include "searchdialog.h"
00025 #include "ui_searchdialog.h"
00026 
00027 SearchDialog::SearchDialog(QWidget *parent) : 
00028     QDialog(parent),
00029     ui(new Ui::SearchDialog)
00030 {
00031   ui->setupUi(this);
00032 
00033   connect(ui->ButtonSearch, SIGNAL(clicked()), SLOT(slotSearch()));
00034   connect(this, SIGNAL(finished(int)), SLOT(slotDisconnect()));
00035 }
00036 
00037 SearchDialog::~SearchDialog()
00038 {
00039   delete ui;
00040 }
00041 
00042 // ---------------------------------------------------------------------
00043 void SearchDialog::initSearch(QWidget *_doc, const QString &text, bool replace)
00044 {
00045   doc = _doc;
00046 
00047   if(replace) {
00048     setWindowTitle(tr("Replace Text"));
00049     ui->AskBox->setHidden(false);
00050     ui->ReplaceGroup->setHidden(false);
00051     connect(this, SIGNAL(replace(const QString &, const QString &, bool, bool, bool, bool)),
00052         doc, SLOT(replace(const QString &, const QString &, bool, bool, bool, bool)));
00053   }
00054   else {
00055     setWindowTitle(tr("Search Text"));
00056     ui->AskBox->setHidden(true);
00057     ui->ReplaceGroup->setHidden(true);
00058     connect(this, SIGNAL(search(const QString &, bool, bool, bool)),
00059         doc, SLOT(search(const QString &, bool, bool, bool)));
00060   }
00061 
00062   ui->ReplaceEdit->clear();
00063   ui->SearchEdit->setText(text);
00064   ui->SearchEdit->selectAll();
00065 
00066   ui->SearchEdit->setFocus();
00067   layout()->setSizeConstraint(QLayout::SetFixedSize);
00068   show();
00069   raise();
00070   activateWindow();
00071 }
00072 
00073 // ---------------------------------------------------------------------
00074 void SearchDialog::slotSearch()
00075 {
00076   if(ui->SearchEdit->text().isEmpty()) {
00077     return;
00078   }
00079 
00080   if(ui->AskBox->isHidden()) { //search
00081     emit search(
00082         ui->SearchEdit->text(), ui->CaseBox->isChecked(), ui->WordBox->isChecked(),
00083         ui->BackwardBox->isChecked());
00084   } else {
00085     emit replace(
00086         ui->SearchEdit->text(), ui->ReplaceEdit->text(),
00087         ui->AskBox->isChecked(), ui->CaseBox->isChecked(),
00088         ui->WordBox->isChecked(), ui->BackwardBox->isChecked());
00089   }
00090 }
00091 
00092 // ---------------------------------------------------------------------
00093 void SearchDialog::slotDisconnect()
00094 {
00095   //hidden -> search
00096   if (ui->AskBox->isHidden()) {
00097     disconnect(this, SIGNAL(search(const QString &, bool, bool, bool)),
00098         doc, SLOT(search(const QString &, bool, bool, bool)));
00099   } else {
00100     disconnect(this, SIGNAL(replace(const QString &, const QString &, bool, bool, bool, bool)),
00101         doc, SLOT(replace(const QString &, const QString &, bool, bool, bool, bool)));
00102   }
00103 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines