feat(searchList): Add best matching list.
Description: 添加最佳匹配列表 Log: 添加最佳匹配列表
This commit is contained in:
parent
0c82dd5997
commit
8f3d91cb1f
|
@ -21,7 +21,7 @@ HomePageItem::~HomePageItem()
|
||||||
void HomePageItem::setupUi(const int& type, const QString& path) {
|
void HomePageItem::setupUi(const int& type, const QString& path) {
|
||||||
m_widget = new QWidget(this);
|
m_widget = new QWidget(this);
|
||||||
m_widget->setObjectName("MainWidget");
|
m_widget->setObjectName("MainWidget");
|
||||||
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
|
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.05); border-radius: 4px;}");
|
||||||
m_widget->installEventFilter(this);
|
m_widget->installEventFilter(this);
|
||||||
connect(this, &HomePageItem::onItemClicked, this, [ = ]() {
|
connect(this, &HomePageItem::onItemClicked, this, [ = ]() {
|
||||||
switch (SearchListView::getResType(path)) {
|
switch (SearchListView::getResType(path)) {
|
||||||
|
@ -116,10 +116,10 @@ bool HomePageItem::eventFilter(QObject *watched, QEvent *event){
|
||||||
if (watched == m_widget){
|
if (watched == m_widget){
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
Q_EMIT this->onItemClicked();
|
Q_EMIT this->onItemClicked();
|
||||||
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.2); border-radius: 4px;}");
|
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
|
||||||
return true;
|
return true;
|
||||||
} else if (event->type() == QEvent::MouseButtonRelease) {
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
||||||
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
|
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.05); border-radius: 4px;}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "search-item.h"
|
#include "search-item.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
SearchItem::SearchItem(QObject *parent) : QObject(parent)
|
SearchItem::SearchItem(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -25,8 +26,16 @@ QIcon SearchItem::getIcon(int index) {
|
||||||
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||||
case Apps : //应用,返回应用图标
|
case Apps : //应用,返回应用图标
|
||||||
return FileUtils::getAppIcon(m_pathlist.at(index));
|
return FileUtils::getAppIcon(m_pathlist.at(index));
|
||||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
case Best : {//最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
||||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
// return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||||
|
if (m_pathlist.at(index).endsWith(".desktop")) {
|
||||||
|
return FileUtils::getAppIcon(m_pathlist.at(index));
|
||||||
|
} else if (QFileInfo(m_pathlist.at(index)).isFile() || QFileInfo(m_pathlist.at(index)).isDir()) {
|
||||||
|
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||||
|
} else {
|
||||||
|
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||||
}
|
}
|
||||||
|
@ -49,7 +58,14 @@ QString SearchItem::getName(int index) {
|
||||||
case Apps : //应用,返回应用名
|
case Apps : //应用,返回应用名
|
||||||
return FileUtils::getAppName(m_pathlist.at(index));
|
return FileUtils::getAppName(m_pathlist.at(index));
|
||||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的名称
|
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的名称
|
||||||
return m_pathlist.at(index);
|
// return m_pathlist.at(index);
|
||||||
|
if (m_pathlist.at(index).endsWith(".desktop")) {
|
||||||
|
return FileUtils::getAppName(m_pathlist.at(index));
|
||||||
|
} else if (QFileInfo(m_pathlist.at(index)).isFile() || QFileInfo(m_pathlist.at(index)).isDir()) {
|
||||||
|
return FileUtils::getFileName(m_pathlist.at(index));
|
||||||
|
} else {
|
||||||
|
return FileUtils::getSettingName(m_pathlist.at(index));
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return m_pathlist.at(index);
|
return m_pathlist.at(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ void ContentWidget::initUI() {
|
||||||
m_resultDetailArea = new QScrollArea(m_resultPage);
|
m_resultDetailArea = new QScrollArea(m_resultPage);
|
||||||
m_resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
m_resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
m_resultListArea->setFixedWidth(240);
|
m_resultListArea->setFixedWidth(244);
|
||||||
m_resultPageLyt->addWidget(m_resultListArea);
|
m_resultPageLyt->addWidget(m_resultListArea);
|
||||||
m_resultPageLyt->addWidget(m_resultDetailArea);
|
m_resultPageLyt->addWidget(m_resultDetailArea);
|
||||||
m_resultPage->setLayout(m_resultPageLyt);
|
m_resultPage->setLayout(m_resultPageLyt);
|
||||||
|
@ -50,7 +50,7 @@ void ContentWidget::initUI() {
|
||||||
m_resultList->setFixedWidth(240);
|
m_resultList->setFixedWidth(240);
|
||||||
m_resultList->setFixedHeight(0);
|
m_resultList->setFixedHeight(0);
|
||||||
m_resultList->setStyleSheet("QWidget{background:transparent;}");
|
m_resultList->setStyleSheet("QWidget{background:transparent;}");
|
||||||
m_listLyt->setContentsMargins(0, 0, 20, 0);
|
m_listLyt->setContentsMargins(0, 0, 15, 0);
|
||||||
m_listLyt->setSpacing(0);
|
m_listLyt->setSpacing(0);
|
||||||
m_resultListArea->setWidget(m_resultList);
|
m_resultListArea->setWidget(m_resultList);
|
||||||
m_resultListArea->setWidgetResizable(true);
|
m_resultListArea->setWidgetResizable(true);
|
||||||
|
@ -136,10 +136,12 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
clearSearchList();
|
clearSearchList();
|
||||||
}
|
}
|
||||||
bool isEmpty = true;
|
bool isEmpty = true;
|
||||||
|
QStringList bestList;
|
||||||
for (int i = 0; i < types.count(); i ++) {
|
for (int i = 0; i < types.count(); i ++) {
|
||||||
if (lists.at(i).isEmpty()) {
|
if (lists.at(i).isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
bestList << lists.at(i).at(0);
|
||||||
isEmpty = false;
|
isEmpty = false;
|
||||||
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
||||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||||
|
@ -150,17 +152,32 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
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) {
|
||||||
m_detailView->setupWidget(type, path);
|
m_detailView->setupWidget(type, path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
SearchListView * searchList = new SearchListView(m_resultList, bestList, SearchItem::SearchType::Best); //Treeview
|
||||||
|
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||||
|
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
|
titleLabel->setText(getTitleName(SearchItem::SearchType::Best));
|
||||||
|
m_listLyt->insertWidget(0, searchList);
|
||||||
|
m_listLyt->insertWidget(0, titleLabel);
|
||||||
|
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
|
||||||
|
searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex()));
|
||||||
|
m_detailView->setupWidget(searchList->getCurrentType(), bestList.at(0));
|
||||||
|
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
||||||
|
m_detailView->setupWidget(type, path);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -178,21 +178,6 @@ void MainWindow::clearSearchResult() {
|
||||||
m_searchLayout->clearText();
|
m_searchLayout->clearText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 鼠标点击窗口外部事件
|
|
||||||
*/
|
|
||||||
bool MainWindow::event ( QEvent * event )
|
|
||||||
{
|
|
||||||
switch (event->type()){
|
|
||||||
case QEvent::ActivationChange:
|
|
||||||
if(QApplication::activeWindow() != this){
|
|
||||||
this->close();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return QWidget::event(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief loadMainWindow 加载主界面的函数
|
* @brief loadMainWindow 加载主界面的函数
|
||||||
* 不删除的原因是在单例和main函数里面需要用
|
* 不删除的原因是在单例和main函数里面需要用
|
||||||
|
@ -290,6 +275,32 @@ double MainWindow::getTransparentData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MainWindow::nativeEvent 处理窗口失焦事件
|
||||||
|
* @param eventType
|
||||||
|
* @param message
|
||||||
|
* @param result
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
|
{
|
||||||
|
Q_UNUSED(result);
|
||||||
|
if (eventType != "xcb_generic_event_t") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::paintEvent(QPaintEvent *event) {
|
void MainWindow::paintEvent(QPaintEvent *event) {
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
void searchContent(QString searchcontent);
|
void searchContent(QString searchcontent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool nativeEvent(const QByteArray&, void *, long *);
|
||||||
|
|
||||||
QFrame * m_line = nullptr;//Vertical dividing line
|
QFrame * m_line = nullptr;//Vertical dividing line
|
||||||
QFrame * m_frame = nullptr;
|
QFrame * m_frame = nullptr;
|
||||||
|
|
||||||
|
@ -75,14 +77,9 @@ private:
|
||||||
|
|
||||||
QVector<int> m_types;
|
QVector<int> m_types;
|
||||||
QVector<QStringList> m_lists;
|
QVector<QStringList> m_lists;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void initUi();
|
void initUi();
|
||||||
/**
|
|
||||||
* @brief Handle events clicking on the outside of the window
|
|
||||||
*/
|
|
||||||
bool event(QEvent *event);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue