diff --git a/control/home-page-item.cpp b/control/home-page-item.cpp index ad18b3e..5171a94 100644 --- a/control/home-page-item.cpp +++ b/control/home-page-item.cpp @@ -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; } } diff --git a/model/search-item.cpp b/model/search-item.cpp index c4dcb5b..9037751 100644 --- a/model/search-item.cpp +++ b/model/search-item.cpp @@ -1,5 +1,6 @@ #include "search-item.h" #include +#include 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); } diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 550f4ae..cd33649 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -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& types, const QVector& types, const QVectoraddWidget(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); + }); } /** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 646e189..f3ec51d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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 : "<response_type;//YYF 20200922 + case XCB_FOCUS_OUT: + this->close(); + break; + } + + return false; +} + void MainWindow::paintEvent(QPaintEvent *event) { Q_UNUSED(event) diff --git a/src/mainwindow.h b/src/mainwindow.h index 37edb5a..36c3a42 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 m_types; QVector 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: /**