Merge pull request #40 from mammonsama666/0103-dev
feat(contentSearch): Add content search ui.
This commit is contained in:
commit
bcc226a650
|
@ -152,12 +152,14 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
m_listLyt->addWidget(titleLabel);
|
m_listLyt->addWidget(titleLabel);
|
||||||
m_listLyt->addWidget(searchList);
|
m_listLyt->addWidget(searchList);
|
||||||
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
|
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
|
||||||
|
|
||||||
// if (i == 0) {
|
// if (i == 0) {
|
||||||
// searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex()));
|
// searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex()));
|
||||||
// m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0));
|
// m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0));
|
||||||
// }
|
// }
|
||||||
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
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);
|
m_detailView->setupWidget(type, path);
|
||||||
searchList->is_current_list = true;
|
searchList->is_current_list = true;
|
||||||
Q_EMIT this->currentItemChanged();
|
Q_EMIT this->currentItemChanged();
|
||||||
|
@ -216,6 +218,8 @@ QString ContentWidget::getTitleName(const int& type) {
|
||||||
return tr("Files");
|
return tr("Files");
|
||||||
case SearchItem::SearchType::Dirs :
|
case SearchItem::SearchType::Dirs :
|
||||||
return tr("Dirs");
|
return tr("Dirs");
|
||||||
|
case SearchItem::SearchType::Contents :
|
||||||
|
return tr("File Contents");
|
||||||
case SearchItem::SearchType::Best :
|
case SearchItem::SearchType::Best :
|
||||||
return tr("Best Matches");
|
return tr("Best Matches");
|
||||||
default :
|
default :
|
||||||
|
@ -238,3 +242,13 @@ void ContentWidget::clearSearchList() {
|
||||||
child = NULL;
|
child = NULL;
|
||||||
m_resultList->setFixedHeight(0);
|
m_resultList->setFixedHeight(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ContentWidget::setContentList 文本内容搜索结果列表(包含所有文本段)
|
||||||
|
* @param list
|
||||||
|
*/
|
||||||
|
void ContentWidget::setContentList(const QStringList& list) {
|
||||||
|
m_contentList.clear();
|
||||||
|
m_contentList = list;
|
||||||
|
}
|
||||||
|
|
|
@ -19,8 +19,10 @@ public:
|
||||||
int currentPage();
|
int currentPage();
|
||||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
||||||
void initHomePage(const QVector<QStringList>&);
|
void initHomePage(const QVector<QStringList>&);
|
||||||
|
void setContentList(const QStringList&);
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
|
QStringList m_contentList;
|
||||||
QWidget * m_homePage = nullptr;
|
QWidget * m_homePage = nullptr;
|
||||||
QVBoxLayout * m_homePageLyt = nullptr;
|
QVBoxLayout * m_homePageLyt = nullptr;
|
||||||
QWidget * m_resultPage = nullptr;
|
QWidget * m_resultPage = nullptr;
|
||||||
|
|
|
@ -31,6 +31,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
|
||||||
g_object_unref(desktopAppInfo);
|
g_object_unref(desktopAppInfo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SearchListView::ResType::Content:
|
||||||
case SearchListView::ResType::Dir:
|
case SearchListView::ResType::Dir:
|
||||||
case SearchListView::ResType::File: {
|
case SearchListView::ResType::File: {
|
||||||
QProcess * process = new QProcess;
|
QProcess * process = new QProcess;
|
||||||
|
@ -65,6 +66,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
|
||||||
m_namelabel->setText(FileUtils::getAppName(path));
|
m_namelabel->setText(FileUtils::getAppName(path));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SearchListView::ResType::Content:
|
||||||
case SearchListView::ResType::Dir :
|
case SearchListView::ResType::Dir :
|
||||||
case SearchListView::ResType::File : {
|
case SearchListView::ResType::File : {
|
||||||
icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
||||||
|
|
|
@ -45,6 +45,7 @@ void OptionView::initComponent(const int& type) {
|
||||||
setupAppOptions();
|
setupAppOptions();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SearchListView::ResType::Content:
|
||||||
case SearchListView::ResType::File : {
|
case SearchListView::ResType::File : {
|
||||||
setupFileOptions();
|
setupFileOptions();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,6 +47,14 @@ void SearchDetailView::clearLayout() {
|
||||||
child = NULL;
|
child = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::setContent 设置文本区域内容(仅内容搜索)
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
|
void SearchDetailView::setContent(const QString& text) {
|
||||||
|
m_contentText = text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域
|
* @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域
|
||||||
* @param type 搜索类型
|
* @param type 搜索类型
|
||||||
|
@ -84,10 +92,17 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
||||||
m_layout->addWidget(hLine);
|
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);
|
QFrame * detailFrame = new QFrame(this);
|
||||||
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
|
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
|
||||||
detailLyt->setContentsMargins(0,0,0,0);
|
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 * pathFrame = new QFrame(detailFrame);
|
||||||
QFrame * timeFrame = new QFrame(detailFrame);
|
QFrame * timeFrame = new QFrame(detailFrame);
|
||||||
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame);
|
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame);
|
||||||
|
@ -139,6 +154,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
||||||
typeLabel->setText(tr("Application"));
|
typeLabel->setText(tr("Application"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SearchListView::ResType::Content:
|
||||||
case SearchListView::ResType::Dir :
|
case SearchListView::ResType::Dir :
|
||||||
case SearchListView::ResType::File : {
|
case SearchListView::ResType::File : {
|
||||||
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
||||||
|
@ -204,6 +220,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SearchListView::ResType::Content:
|
||||||
case SearchListView::ResType::Dir:
|
case SearchListView::ResType::Dir:
|
||||||
case SearchListView::ResType::File: {
|
case SearchListView::ResType::File: {
|
||||||
QProcess * process = new QProcess;
|
QProcess * process = new QProcess;
|
||||||
|
|
|
@ -13,10 +13,11 @@ public:
|
||||||
|
|
||||||
void setupWidget(const int&, const QString&);
|
void setupWidget(const int&, const QString&);
|
||||||
void clearLayout();
|
void clearLayout();
|
||||||
|
void setContent(const QString&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout * m_layout = nullptr;
|
QVBoxLayout * m_layout = nullptr;
|
||||||
|
QString m_contentText;
|
||||||
bool openAction(const int&, const QString&);
|
bool openAction(const int&, const QString&);
|
||||||
bool addDesktopShortcut(const QString&);
|
bool addDesktopShortcut(const QString&);
|
||||||
bool addPanelShortcut(const QString&);
|
bool addPanelShortcut(const QString&);
|
||||||
|
|
|
@ -53,6 +53,9 @@ int SearchListView::getCurrentType() {
|
||||||
case SearchItem::SearchType::Dirs:
|
case SearchItem::SearchType::Dirs:
|
||||||
// qDebug()<<"qDebug: One row selected, its type is dir.";
|
// qDebug()<<"qDebug: One row selected, its type is dir.";
|
||||||
return ResType::Dir;
|
return ResType::Dir;
|
||||||
|
case SearchItem::SearchType::Contents:
|
||||||
|
// qDebug()<<"qDebug: One row selected, its type is content.";
|
||||||
|
return ResType::Content;
|
||||||
default: //All或者Best的情况,需要自己判断文件类型
|
default: //All或者Best的情况,需要自己判断文件类型
|
||||||
return getResType(m_item->m_pathlist.at(this->currentIndex().row()));
|
return getResType(m_item->m_pathlist.at(this->currentIndex().row()));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -17,7 +17,8 @@ public:
|
||||||
App,
|
App,
|
||||||
File,
|
File,
|
||||||
Setting,
|
Setting,
|
||||||
Dir
|
Dir,
|
||||||
|
Content
|
||||||
};
|
};
|
||||||
|
|
||||||
int getCurrentType();
|
int getCurrentType();
|
||||||
|
|
|
@ -45,15 +45,15 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent)
|
QMainWindow(parent)
|
||||||
{
|
{
|
||||||
// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test");
|
// FileUtils::findMultiToneWords("仇仇仇仇仇仇仇仇仇仇仇翟康宁test");
|
||||||
/*-------------Inotify Test Start---------------*/
|
/*-------------Inotify Test Start---------------*/
|
||||||
// QTime t1 = QTime::currentTime();
|
// QTime t1 = QTime::currentTime();
|
||||||
// InotifyManagerRefact* im = new InotifyManagerRefact("/home");
|
// InotifyManagerRefact* im = new InotifyManagerRefact("/home");
|
||||||
// im->Traverse();
|
// im->Traverse();
|
||||||
// QTime t2 = QTime::currentTime();
|
// QTime t2 = QTime::currentTime();
|
||||||
// qDebug() << t1;
|
// qDebug() << t1;
|
||||||
// qDebug() << t2;
|
// qDebug() << t2;
|
||||||
// im->start();
|
// im->start();
|
||||||
/*-------------Inotify Test End-----------------*/
|
/*-------------Inotify Test End-----------------*/
|
||||||
|
|
||||||
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
|
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
|
||||||
|
@ -161,7 +161,7 @@ void MainWindow::initUi()
|
||||||
} else {
|
} else {
|
||||||
m_contentFrame->setCurrentIndex(1);
|
m_contentFrame->setCurrentIndex(1);
|
||||||
QTimer::singleShot(50,this,[=](){
|
QTimer::singleShot(50,this,[=](){
|
||||||
searchContent(text);
|
searchContent(text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -234,8 +234,8 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
||||||
* @param searchcontent
|
* @param searchcontent
|
||||||
*/
|
*/
|
||||||
void MainWindow::searchContent(QString searchcontent){
|
void MainWindow::searchContent(QString searchcontent){
|
||||||
// QVector<int> types;
|
// QVector<int> types;
|
||||||
// QVector<QStringList> lists;
|
// QVector<QStringList> lists;
|
||||||
m_lists.clear();
|
m_lists.clear();
|
||||||
m_types.clear();
|
m_types.clear();
|
||||||
|
|
||||||
|
@ -245,19 +245,46 @@ void MainWindow::searchContent(QString searchcontent){
|
||||||
//测试用数据
|
//测试用数据
|
||||||
QStringList list;
|
QStringList list;
|
||||||
list = appMatchor->startMatchApp(searchcontent);
|
list = appMatchor->startMatchApp(searchcontent);
|
||||||
// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
|
// 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;
|
QStringList list3;
|
||||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
list3 = settingMatchor->startMatchApp(searchcontent);
|
||||||
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||||
m_types.append(SearchItem::SearchType::Apps);
|
m_types.append(SearchItem::SearchType::Apps);
|
||||||
m_types.append(SearchItem::SearchType::Settings);
|
m_types.append(SearchItem::SearchType::Settings);
|
||||||
// types.append(SearchItem::SearchType::Files);
|
|
||||||
|
|
||||||
m_lists.append(list);
|
m_lists.append(list);
|
||||||
m_lists.append(list3);
|
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);
|
// m_contentFrame->refreshSearchList(m_types, m_lists);
|
||||||
|
|
||||||
//文件搜索
|
//文件搜索
|
||||||
|
@ -269,21 +296,21 @@ void MainWindow::searchContent(QString searchcontent){
|
||||||
QStringList list1 = resultV.at(0);
|
QStringList list1 = resultV.at(0);
|
||||||
QStringList list2 = resultV.at(1);
|
QStringList list2 = resultV.at(1);
|
||||||
|
|
||||||
// QVector<QStringList> lists;
|
// QVector<QStringList> lists;
|
||||||
m_lists.append(list1);
|
m_lists.append(list1);
|
||||||
m_lists.append(list2);
|
m_lists.append(list2);
|
||||||
// QVector<int> types;
|
// QVector<int> types;
|
||||||
m_types.append(SearchItem::SearchType::Dirs);
|
m_types.append(SearchItem::SearchType::Dirs);
|
||||||
m_types.append(SearchItem::SearchType::Files);
|
m_types.append(SearchItem::SearchType::Files);
|
||||||
m_contentFrame->refreshSearchList(m_types, m_lists);
|
m_contentFrame->refreshSearchList(m_types, m_lists);
|
||||||
});
|
});
|
||||||
searcher->onKeywordSearch(searchcontent,0,10);
|
searcher->onKeywordSearch(searchcontent,0,10);
|
||||||
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
||||||
// types.append(SearchItem::SearchType::Files);
|
// types.append(SearchItem::SearchType::Files);
|
||||||
// lists.append(res);
|
// lists.append(res);
|
||||||
|
|
||||||
//将搜索结果加入列表
|
//将搜索结果加入列表
|
||||||
// m_contentFrame->refreshSearchList(types, lists);
|
// m_contentFrame->refreshSearchList(types, lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用GSetting获取当前窗口应该使用的透明度
|
//使用GSetting获取当前窗口应该使用的透明度
|
||||||
|
@ -319,7 +346,6 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
||||||
xcb_generic_event_t *event = (xcb_generic_event_t*)message;
|
xcb_generic_event_t *event = (xcb_generic_event_t*)message;
|
||||||
|
|
||||||
switch (event->response_type & ~0x80) {
|
switch (event->response_type & ~0x80) {
|
||||||
qDebug()<<"YYF - event->response_type : "<<event->response_type;//YYF 20200922
|
|
||||||
case XCB_FOCUS_OUT:
|
case XCB_FOCUS_OUT:
|
||||||
this->close();
|
this->close();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -21,6 +21,7 @@ QIcon SearchItem::getIcon(int index) {
|
||||||
switch (m_searchtype) {
|
switch (m_searchtype) {
|
||||||
case Settings : //设置项,返回控制面板对应插件的图标
|
case Settings : //设置项,返回控制面板对应插件的图标
|
||||||
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
||||||
|
case Contents:
|
||||||
case Dirs :
|
case Dirs :
|
||||||
case Files : //文件,返回文件图标
|
case Files : //文件,返回文件图标
|
||||||
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||||
|
@ -52,6 +53,7 @@ QString SearchItem::getName(int index) {
|
||||||
switch (m_searchtype) {
|
switch (m_searchtype) {
|
||||||
case Settings : //设置项,返回功能点名
|
case Settings : //设置项,返回功能点名
|
||||||
return FileUtils::getSettingName(m_pathlist.at(index));
|
return FileUtils::getSettingName(m_pathlist.at(index));
|
||||||
|
case Contents:
|
||||||
case Dirs :
|
case Dirs :
|
||||||
case Files : //文件,返回文件名
|
case Files : //文件,返回文件名
|
||||||
return FileUtils::getFileName(m_pathlist.at(index));
|
return FileUtils::getFileName(m_pathlist.at(index));
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
Settings,
|
Settings,
|
||||||
Files,
|
Files,
|
||||||
Dirs,
|
Dirs,
|
||||||
|
Contents,
|
||||||
Best
|
Best
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue