GuiSearch::GuiSearch(GuiView & lv) : GuiDialog(lv, "findreplace", qt_("Find and Replace")) { setupUi(this); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked())); connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked())); connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked())); connect(findCO, SIGNAL(editTextChanged(QString)), this, SLOT(findChanged())); setFocusProxy(findCO); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setCancel(closePB); bc().addReadOnly(replaceCO); bc().addReadOnly(replacePB); bc().addReadOnly(replaceallPB); replacePB->setEnabled(false); replaceallPB->setEnabled(false); }
FindDialog::FindDialog(Stack* documents) : QDialog(documents->window(), Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), m_documents(documents) { // Create widgets QLabel* find_label = new QLabel(tr("Search for:"), this); m_find_string = new QLineEdit(this); m_replace_label = new QLabel(tr("Replace with:"), this); m_replace_string = new QLineEdit(this); connect(m_find_string, SIGNAL(textChanged(QString)), this, SLOT(findChanged(QString))); m_ignore_case = new QCheckBox(tr("Ignore case"), this); m_whole_words = new QCheckBox(tr("Whole words only"), this); m_regular_expressions = new QCheckBox(tr("Regular expressions"), this); connect(m_regular_expressions, SIGNAL(toggled(bool)), m_whole_words, SLOT(setDisabled(bool))); m_search_backwards = new QRadioButton(tr("Search up"), this); QRadioButton* search_forwards = new QRadioButton(tr("Search down"), this); search_forwards->setChecked(true); // Create buttons QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); m_find_button = buttons->addButton(tr("&Find"), QDialogButtonBox::ActionRole); m_find_button->setEnabled(false); connect(m_find_button, SIGNAL(clicked()), this, SLOT(find())); m_replace_button = buttons->addButton(tr("&Replace"), QDialogButtonBox::ActionRole); m_replace_button->setEnabled(false); connect(m_replace_button, SIGNAL(clicked()), this, SLOT(replace())); m_replace_all_button = buttons->addButton(tr("Replace &All"), QDialogButtonBox::ActionRole); m_replace_all_button->setEnabled(false); connect(m_replace_all_button, SIGNAL(clicked()), this, SLOT(replaceAll())); if (!buttons->button(QDialogButtonBox::Close)->icon().isNull()) { m_find_button->setIcon(QIcon::fromTheme("edit-find")); m_replace_button->setIcon(QIcon::fromTheme("edit-find-replace")); } // Lay out dialog QGridLayout* layout = new QGridLayout(this); layout->setColumnStretch(1, 1); layout->addWidget(find_label, 0, 0, Qt::AlignRight | Qt::AlignVCenter); layout->addWidget(m_find_string, 0, 1, 1, 2); layout->addWidget(m_replace_label, 1, 0, Qt::AlignRight | Qt::AlignVCenter); layout->addWidget(m_replace_string, 1, 1, 1, 2); layout->addWidget(m_ignore_case, 2, 1); layout->addWidget(m_whole_words, 3, 1); layout->addWidget(m_regular_expressions, 4, 1); layout->addWidget(m_search_backwards, 2, 2); layout->addWidget(search_forwards, 3, 2); layout->addWidget(buttons, 5, 0, 1, 3); setFixedWidth(sizeHint().width()); // Load settings QSettings settings; m_ignore_case->setChecked(!settings.value("FindDialog/CaseSensitive", false).toBool()); m_whole_words->setChecked(settings.value("FindDialog/WholeWords", false).toBool()); m_regular_expressions->setChecked(settings.value("FindDialog/RegularExpressions", false).toBool()); m_search_backwards->setChecked(settings.value("FindDialog/SearchBackwards", false).toBool()); m_find_string->installEventFilter(this); m_replace_string->installEventFilter(this); }