work save

Find&Replace Dialog UI done
This commit is contained in:
royqh1979 2021-08-02 23:42:10 +08:00
parent f16ca99a55
commit 176c92ace8
3 changed files with 374 additions and 8 deletions

View File

@ -1,14 +1,105 @@
#include "searchdialog.h" #include "searchdialog.h"
#include "ui_searchdialog.h" #include "ui_searchdialog.h"
#include <QTabBar>
SearchDialog::SearchDialog(QWidget *parent) : SearchDialog::SearchDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::SearchDialog) ui(new Ui::SearchDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
mTabBar = new QTabBar();
mTabBar->addTab(tr("Find"));
mTabBar->addTab(tr("Find in files"));
mTabBar->addTab(tr("Replace"));
mTabBar->addTab(tr("Replace in files"));
ui->dialogLayout->insertWidget(0,mTabBar);
connect(mTabBar,&QTabBar::currentChanged,this, &SearchDialog::onTabChanged);
} }
SearchDialog::~SearchDialog() SearchDialog::~SearchDialog()
{ {
delete ui; delete ui;
} }
void SearchDialog::find(const QString &text)
{
mTabBar->setCurrentIndex(0);
ui->cbFind->setCurrentText(text);
show();
}
void SearchDialog::findInFiles(const QString &text)
{
mTabBar->setCurrentIndex(1);
ui->cbFind->setCurrentText(text);
show();
}
void SearchDialog::replace(const QString &sFind, const QString &sReplace)
{
mTabBar->setCurrentIndex(2);
ui->cbFind->setCurrentText(sFind);
ui->cbReplace->setCurrentText(sReplace);
show();
}
void SearchDialog::replaceInFiles(const QString &sFind, const QString &sReplace)
{
mTabBar->setCurrentIndex(3);
ui->cbFind->setCurrentText(sFind);
ui->cbReplace->setCurrentText(sReplace);
show();
}
void SearchDialog::onTabChanged()
{
bool isfind = (mTabBar->currentIndex() == 0);
bool isfindfiles = (mTabBar->currentIndex() == 1);
bool isreplace = (mTabBar->currentIndex() == 2);
bool isreplacefiles = (mTabBar->currentIndex() == 3);
ui->lblReplace->setVisible(isreplace || isreplacefiles);
ui->cbReplace->setVisible(isreplace || isreplacefiles);
ui->grpOrigin->setVisible(isfind || isreplace);
ui->grpScope->setVisible(isfind || isreplace);
ui->grpWhere->setVisible(isfindfiles || isreplacefiles);
ui->grpDirection->setVisible(isfind || isreplace);
// grpOption is always visible
// Disable project search option when none is open
// rbProjectFiles.Enabled := Assigned(MainForm.Project);
ui->rbProject->setEnabled(false);
// if not Assigned(MainForm.Project) then
// rbOpenFiles.Checked := true;
// Disable prompt when doing finds
ui->chkPrompt->setEnabled(isreplace or isreplacefiles);
if (isfind || not isfindfiles) {
ui->btnExecute->setText(tr("Find"));
} else {
ui->btnExecute->setText(tr("Replace"));
}
setWindowTitle(mTabBar->tabText(mTabBar->currentIndex()));
}
void SearchDialog::on_cbFind_currentTextChanged(const QString &)
{
ui->btnExecute->setEnabled(!ui->cbFind->currentText().isEmpty());
}
void SearchDialog::on_btnCancel_clicked()
{
this->close();
}
void SearchDialog::closeEvent(QCloseEvent *event)
{
this->deleteLater();
}
void SearchDialog::on_btnExecute_clicked()
{
}

View File

@ -7,6 +7,7 @@ namespace Ui {
class SearchDialog; class SearchDialog;
} }
class QTabBar;
class SearchDialog : public QDialog class SearchDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -14,9 +15,25 @@ class SearchDialog : public QDialog
public: public:
explicit SearchDialog(QWidget *parent = nullptr); explicit SearchDialog(QWidget *parent = nullptr);
~SearchDialog(); ~SearchDialog();
void find(const QString& text);
void findInFiles(const QString& text);
void replace(const QString& sFind, const QString& sReplace);
void replaceInFiles(const QString& sFind, const QString& sReplace);
private slots:
void onTabChanged();
void on_cbFind_currentTextChanged(const QString &arg1);
void on_btnCancel_clicked();
void on_btnExecute_clicked();
private: private:
Ui::SearchDialog *ui; Ui::SearchDialog *ui;
QTabBar *mTabBar;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
}; };
#endif // SEARCHDIALOG_H #endif // SEARCHDIALOG_H

View File

@ -13,7 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="dialogLayout">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
@ -39,10 +39,268 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QWidget" name="widget_2" native="true">
<property name="text"> <layout class="QGridLayout" name="gridLayout">
<string>Text to Find</string> <property name="leftMargin">
</property> <number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lblFind">
<property name="text">
<string>Text to Find:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbFind">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbReplace">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblReplace">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="grpOptions">
<property name="title">
<string>Options:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="chkCaseSensetive">
<property name="text">
<string>Case Sensitive</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkWholeWord">
<property name="text">
<string>Whole words only</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkRegExp">
<property name="text">
<string>Regular Expression</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkPrompt">
<property name="text">
<string>Prompt on replace</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="grpScope">
<property name="title">
<string>Scope:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QRadioButton" name="rbGlobal">
<property name="text">
<string>Global</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbSelection">
<property name="text">
<string>Selection</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="grpOrigin">
<property name="title">
<string>Origin:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QRadioButton" name="rbFromCursor">
<property name="text">
<string>From cursor</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbEntireScope">
<property name="text">
<string>Entire scope</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>7</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="grpDirection">
<property name="title">
<string>Direction:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QRadioButton" name="rbForward">
<property name="text">
<string>Forward</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbBackward">
<property name="text">
<string>Backward</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpWhere">
<property name="title">
<string>Where:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QRadioButton" name="rbCurrentFile">
<property name="text">
<string>current file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbProject">
<property name="text">
<string>Files In project</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbOpenFiles">
<property name="text">
<string>Open files</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -53,7 +311,7 @@
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>445</height> <height>134</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -84,14 +342,14 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="btnExecute">
<property name="text"> <property name="text">
<string>Find</string> <string>Find</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_2"> <widget class="QPushButton" name="btnCancel">
<property name="text"> <property name="text">
<string>Cancel</string> <string>Cancel</string>
</property> </property>