資源簡介
使用Qt實現的,功能基本和Windows自帶的記事本一樣。不同的是這個無論打開多少個文件,多少個窗口,都只保持一個進程(單進程,多主窗口),另外里面增加了猜測utf-8編碼集的功能,用于顯示無BOM格式的UTF-8源代碼時不亂碼。
代碼片段和文件信息
#include?“finddialog.h“
finddialog::finddialog(QWidget?*parent):?QDialog(parent)
{
????setupUi(this);
????connect(cancelButton?SIGNAL(clicked())
????????????this?SLOT(close()));
????connect(lineEdit?SIGNAL(textChanged(const?QString?&))
????????????this?SLOT(enableFindButton(const?QString?&)));
????connect(findButton?SIGNAL(clicked())
????????????this?SLOT(findClicked()));
????keyword_last?=?““;
}
void?finddialog::enableFindButton(const?QString?&text)
{
????findButton->setEnabled(!text.isEmpty());
}
void?finddialog::findClicked()
{
????QTextDocument::FindFlags?ff?=?0;
????if?(backwardButton->isChecked())?{
????????ff?|=?QTextDocument::FindBackward;
????}
????if?(caseBox->isChecked())?{
????????ff?|=?QTextDocument::FindCaseSensitively;
????}
????keyword_last?=?lineEdit->text();
????emitStatus();
????emit?to_find(keyword_last?ff);
}
void?finddialog::set_keyword(QString?keyword)
{
????keyword_last?=?keyword;
????lineEdit->setText(keyword_last);
}
void?finddialog::set_case(bool?cs)
{
????caseBox->setChecked(cs);
}
void?finddialog::set_forward()
{
????forwardButton->setChecked(true);
}
bool?finddialog::no_keyword()
{
????return?keyword_last.isEmpty();
}
void?finddialog::closeEvent(QCloseEvent?*event)
{
????lineEdit->setText(keyword_last);
}
void?finddialog::emitStatus()????//同步查找、替換對話框的狀態
{
????emit?keyword_changed(keyword_last);
????emit?case_changed(caseBox->isChecked());
}
評論
共有 條評論