Merge pull request #22 from mammonsama666/zjp-best-match
feat(searchList): Add best matching list.
This commit is contained in:
commit
109a2e5bbd
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public:
|
|||
int getCurrentType();
|
||||
static int getResType(const QString&);
|
||||
|
||||
bool is_current_list = false;
|
||||
|
||||
private:
|
||||
SearchItemModel * m_model = nullptr;
|
||||
SearchItem * m_item = nullptr;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "content-widget.h"
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
|
||||
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
||||
{
|
||||
|
@ -38,7 +39,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 +51,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 +137,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 +153,52 @@ 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);
|
||||
searchList->is_current_list = true;
|
||||
Q_EMIT this->currentItemChanged();
|
||||
searchList->is_current_list = false;
|
||||
});
|
||||
connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() {
|
||||
if (! searchList->is_current_list) {
|
||||
searchList->blockSignals(true);
|
||||
searchList->clearSelection();
|
||||
searchList->blockSignals(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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, 0, 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);
|
||||
searchList->is_current_list = true;
|
||||
Q_EMIT this->currentItemChanged();
|
||||
searchList->is_current_list = false;
|
||||
});
|
||||
connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() {
|
||||
if (! searchList->is_current_list) {
|
||||
searchList->blockSignals(true);
|
||||
searchList->clearSelection();
|
||||
searchList->blockSignals(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,9 @@ private:
|
|||
|
||||
QString getTitleName(const int&);
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentItemChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void clearSearchList();
|
||||
};
|
||||
|
|
|
@ -191,21 +191,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函数里面需要用
|
||||
|
@ -303,6 +288,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