feat(contentSearch): Add content search ui.

Description: 添加文本搜索ui

Log: 添加文本搜索ui
This commit is contained in:
zhangjiaping 2021-01-03 20:51:19 +08:00
parent 7bab5db46b
commit 482c286a27
11 changed files with 99 additions and 29 deletions

View File

@ -152,12 +152,14 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
m_listLyt->addWidget(titleLabel);
m_listLyt->addWidget(searchList);
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
// if (i == 0) {
// searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex()));
// m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0));
// }
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
if(type == SearchListView::ResType::Content && !m_contentList.isEmpty()) {
m_detailView->setContent(m_contentList.at(searchList->currentIndex().row()));
}
m_detailView->setupWidget(type, path);
searchList->is_current_list = true;
Q_EMIT this->currentItemChanged();
@ -216,6 +218,8 @@ QString ContentWidget::getTitleName(const int& type) {
return tr("Files");
case SearchItem::SearchType::Dirs :
return tr("Dirs");
case SearchItem::SearchType::Contents :
return tr("File Contents");
case SearchItem::SearchType::Best :
return tr("Best Matches");
default :
@ -238,3 +242,13 @@ void ContentWidget::clearSearchList() {
child = NULL;
m_resultList->setFixedHeight(0);
}
/**
* @brief ContentWidget::setContentList
* @param list
*/
void ContentWidget::setContentList(const QStringList& list) {
m_contentList.clear();
m_contentList = list;
}

View File

@ -19,8 +19,10 @@ public:
int currentPage();
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
void initHomePage(const QVector<QStringList>&);
void setContentList(const QStringList&);
private:
void initUI();
QStringList m_contentList;
QWidget * m_homePage = nullptr;
QVBoxLayout * m_homePageLyt = nullptr;
QWidget * m_resultPage = nullptr;

View File

@ -31,6 +31,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
g_object_unref(desktopAppInfo);
break;
}
case SearchListView::ResType::Content:
case SearchListView::ResType::Dir:
case SearchListView::ResType::File: {
QProcess * process = new QProcess;
@ -65,6 +66,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
m_namelabel->setText(FileUtils::getAppName(path));
break;
}
case SearchListView::ResType::Content:
case SearchListView::ResType::Dir :
case SearchListView::ResType::File : {
icon = FileUtils::getFileIcon(QString("file://%1").arg(path));

View File

@ -45,6 +45,7 @@ void OptionView::initComponent(const int& type) {
setupAppOptions();
break;
}
case SearchListView::ResType::Content:
case SearchListView::ResType::File : {
setupFileOptions();
break;

View File

@ -47,6 +47,14 @@ void SearchDetailView::clearLayout() {
child = NULL;
}
/**
* @brief SearchDetailView::setContent
* @param text
*/
void SearchDetailView::setContent(const QString& text) {
m_contentText = text;
}
/**
* @brief SearchDetailView::setupWidget
* @param type
@ -84,10 +92,17 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
m_layout->addWidget(hLine);
//文件和文件夹有一个额外的详情区域
if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File) {
if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File || type == SearchListView::ResType::Content) {
QFrame * detailFrame = new QFrame(this);
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
detailLyt->setContentsMargins(0,0,0,0);
if (type == SearchListView::ResType::Content) {
QLabel * contentLabel = new QLabel(detailFrame);
contentLabel->setWordWrap(true);
contentLabel->setContentsMargins(9, 0, 9, 0);
contentLabel->setText(m_contentText);
detailLyt->addWidget(contentLabel);
}
QFrame * pathFrame = new QFrame(detailFrame);
QFrame * timeFrame = new QFrame(detailFrame);
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame);
@ -139,6 +154,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
typeLabel->setText(tr("Application"));
break;
}
case SearchListView::ResType::Content:
case SearchListView::ResType::Dir :
case SearchListView::ResType::File : {
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
@ -204,6 +220,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
return true;
break;
}
case SearchListView::ResType::Content:
case SearchListView::ResType::Dir:
case SearchListView::ResType::File: {
QProcess * process = new QProcess;

View File

@ -13,10 +13,11 @@ public:
void setupWidget(const int&, const QString&);
void clearLayout();
void setContent(const QString&);
private:
QVBoxLayout * m_layout = nullptr;
QString m_contentText;
bool openAction(const int&, const QString&);
bool addDesktopShortcut(const QString&);
bool addPanelShortcut(const QString&);

View File

@ -53,6 +53,9 @@ int SearchListView::getCurrentType() {
case SearchItem::SearchType::Dirs:
// qDebug()<<"qDebug: One row selected, its type is dir.";
return ResType::Dir;
case SearchItem::SearchType::Contents:
// qDebug()<<"qDebug: One row selected, its type is content.";
return ResType::Content;
default: //All或者Best的情况需要自己判断文件类型
return getResType(m_item->m_pathlist.at(this->currentIndex().row()));
break;

View File

@ -17,7 +17,8 @@ public:
App,
File,
Setting,
Dir
Dir,
Content
};
int getCurrentType();

View File

@ -246,18 +246,45 @@ void MainWindow::searchContent(QString searchcontent){
QStringList list;
list = appMatchor->startMatchApp(searchcontent);
// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
// QStringList list2;
// list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
QStringList list3;
list3 = settingMatchor->startMatchApp(searchcontent);
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
m_types.append(SearchItem::SearchType::Apps);
m_types.append(SearchItem::SearchType::Settings);
// types.append(SearchItem::SearchType::Files);
m_lists.append(list);
m_lists.append(list3);
// lists.append(list2);
//内容搜索测试用数据,每个文件(路径)对应一段文本内容
FileSearcher *search = new FileSearcher();
connect(search, &FileSearcher::contentResult, this, [ = ](QMap<QString,QStringList> map) {
m_types.append(SearchItem::SearchType::Contents);
QStringList pathlist, contentList;
qDebug() << map;
for (auto i : map.keys()){
QString temp;
pathlist << i;
for (auto s : map[i]){
temp.append(s);
}
contentList.append(temp);
}
m_lists.append(pathlist);
m_contentFrame->setContentList(contentList);
});
QTime t1 = QTime::currentTime();
search->onKeywordSearchContent(searchcontent);
QTime t2 = QTime::currentTime();
qDebug() << t1;
qDebug() << t2;
// m_types.append(SearchItem::SearchType::Contents);
// QStringList pathlist;
// pathlist<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
// m_lists.append(pathlist);
// QStringList contentList;
// contentList<<"这是搜索结果.png的文件内容"<<"这是显示不全.mp4的文件内容"<<"这是dmesg.log的文件内容"<<"这是WiFi_AP选择.docx的文件内容";
// m_contentFrame->setContentList(contentList);
// m_contentFrame->refreshSearchList(m_types, m_lists);
//文件搜索
@ -319,7 +346,6 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
xcb_generic_event_t *event = (xcb_generic_event_t*)message;
switch (event->response_type & ~0x80) {
qDebug()<<"YYF - event->response_type : "<<event->response_type;//YYF 20200922
case XCB_FOCUS_OUT:
this->close();
break;

View File

@ -21,6 +21,7 @@ QIcon SearchItem::getIcon(int index) {
switch (m_searchtype) {
case Settings : //设置项,返回控制面板对应插件的图标
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
case Contents:
case Dirs :
case Files : //文件,返回文件图标
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
@ -52,6 +53,7 @@ QString SearchItem::getName(int index) {
switch (m_searchtype) {
case Settings : //设置项,返回功能点名
return FileUtils::getSettingName(m_pathlist.at(index));
case Contents:
case Dirs :
case Files : //文件,返回文件名
return FileUtils::getFileName(m_pathlist.at(index));

View File

@ -21,6 +21,7 @@ public:
Settings,
Files,
Dirs,
Contents,
Best
};