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) {
|
||||
m_widget = new QWidget(this);
|
||||
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);
|
||||
connect(this, &HomePageItem::onItemClicked, this, [ = ]() {
|
||||
switch (SearchListView::getResType(path)) {
|
||||
|
@ -116,10 +116,10 @@ bool HomePageItem::eventFilter(QObject *watched, QEvent *event){
|
|||
if (watched == m_widget){
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "search-item.h"
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
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)));
|
||||
case Apps : //应用,返回应用图标
|
||||
return FileUtils::getAppIcon(m_pathlist.at(index));
|
||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||
case Best : {//最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
||||
// 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:
|
||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||
}
|
||||
|
@ -49,7 +58,14 @@ QString SearchItem::getName(int index) {
|
|||
case Apps : //应用,返回应用名
|
||||
return FileUtils::getAppName(m_pathlist.at(index));
|
||||
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:
|
||||
return m_pathlist.at(index);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ void ContentWidget::initUI() {
|
|||
m_resultDetailArea = new QScrollArea(m_resultPage);
|
||||
m_resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_resultListArea->setFixedWidth(240);
|
||||
m_resultListArea->setFixedWidth(244);
|
||||
m_resultPageLyt->addWidget(m_resultListArea);
|
||||
m_resultPageLyt->addWidget(m_resultDetailArea);
|
||||
m_resultPage->setLayout(m_resultPageLyt);
|
||||
|
@ -50,7 +50,7 @@ void ContentWidget::initUI() {
|
|||
m_resultList->setFixedWidth(240);
|
||||
m_resultList->setFixedHeight(0);
|
||||
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_resultListArea->setWidget(m_resultList);
|
||||
m_resultListArea->setWidgetResizable(true);
|
||||
|
@ -136,10 +136,12 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
|||
clearSearchList();
|
||||
}
|
||||
bool isEmpty = true;
|
||||
QStringList bestList;
|
||||
for (int i = 0; i < types.count(); i ++) {
|
||||
if (lists.at(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
bestList << lists.at(i).at(0);
|
||||
isEmpty = false;
|
||||
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
||||
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_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));
|
||||
}
|
||||
// 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) {
|
||||
m_detailView->setupWidget(type, path);
|
||||
});
|
||||
}
|
||||
|
||||
if (isEmpty) {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标点击窗口外部事件
|
||||
*/
|
||||
bool MainWindow::event ( QEvent * event )
|
||||
{
|
||||
switch (event->type()){
|
||||
case QEvent::ActivationChange:
|
||||
if(QApplication::activeWindow() != this){
|
||||
this->close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief loadMainWindow 加载主界面的函数
|
||||
* 不删除的原因是在单例和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) {
|
||||
Q_UNUSED(event)
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
void searchContent(QString searchcontent);
|
||||
|
||||
private:
|
||||
bool nativeEvent(const QByteArray&, void *, long *);
|
||||
|
||||
QFrame * m_line = nullptr;//Vertical dividing line
|
||||
QFrame * m_frame = nullptr;
|
||||
|
||||
|
@ -75,14 +77,9 @@ private:
|
|||
|
||||
QVector<int> m_types;
|
||||
QVector<QStringList> m_lists;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void initUi();
|
||||
/**
|
||||
* @brief Handle events clicking on the outside of the window
|
||||
*/
|
||||
bool event(QEvent *event);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue