diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 6bf7d28..1866a47 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -42,6 +42,7 @@ ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent) { qRegisterMetaType("SearchPluginIface::ResultInfo"); initUi(); + initConnections(); } void ResultArea::appendWidet(ResultWidget *widget) @@ -75,8 +76,11 @@ void ResultArea::onWidgetSizeChanged() Q_FOREACH (ResultWidget *widget, m_widget_list) { whole_height += widget->height(); } + whole_height += m_bestListWidget->height(); + //TODO 网页高度 int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0; m_widget->setFixedHeight(whole_height + spacing_height * (m_widget_list.length() - 1)); + Q_EMIT this->resizeHeight(whole_height + spacing_height * (m_widget_list.length() - 1)); } void ResultArea::initUi() @@ -95,15 +99,25 @@ void ResultArea::initUi() this->setWidget(m_widget); m_mainLyt = new QVBoxLayout(m_widget); m_widget->setLayout(m_mainLyt); + m_bestListWidget = new BestListWidget(this); + m_mainLyt->addWidget(m_bestListWidget); m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS); } +void ResultArea::initConnections() +{ + connect(this, &ResultArea::startSearch, m_bestListWidget, &BestListWidget::startSearch); + connect(m_bestListWidget, &BestListWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged); + connect(m_bestListWidget, &BestListWidget::currentRowChanged, this, &ResultArea::currentRowChanged); + connect(this, &ResultArea::clearSelectedRow, m_bestListWidget, &BestListWidget::clearSelectedRow); +} + void ResultArea::setupConnectionsForWidget(ResultWidget *widget) { connect(this, &ResultArea::startSearch, widget, &ResultWidget::startSearch); - connect(this, &ResultArea::stopSearch, widget, &ResultWidget::stopSearch); connect(widget, &ResultWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged); + connect(widget, &ResultWidget::sendBestListData, m_bestListWidget, &BestListWidget::sendBestListData); } DetailArea::DetailArea(QWidget *parent) : QScrollArea(parent) diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 9f51ca7..0d8273f 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -26,6 +26,7 @@ #include #include "result-view.h" #include "search-plugin-iface.h" +#include "best-list-view.h" namespace Zeeker { class ResultArea : public QScrollArea @@ -42,15 +43,19 @@ public Q_SLOTS: private: void initUi(); + void initConnections(); void setupConnectionsForWidget(ResultWidget *); QWidget * m_widget = nullptr; QVBoxLayout * m_mainLyt = nullptr; + BestListWidget * m_bestListWidget; QList m_widget_list; Q_SIGNALS: void startSearch(const QString &); void stopSearch(); - + void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); + void clearSelectedRow(); + void resizeHeight(int height); }; class DetailWidget : public QWidget diff --git a/frontend/control/stack-pages/search-result-page.cpp b/frontend/control/stack-pages/search-result-page.cpp index 9146c6c..56866a2 100644 --- a/frontend/control/stack-pages/search-result-page.cpp +++ b/frontend/control/stack-pages/search-result-page.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2020, KylinSoft Co., Ltd. + * Copyright (C) 2021, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Authors: zhangjiaping + * Authors: jixiaoxu * */ #include "search-result-page.h" @@ -131,6 +131,11 @@ void SearchResultPage::initConnections() connect(this, &SearchResultPage::stopSearch, m_resultArea, &ResultArea::stopSearch); connect(this, &SearchResultPage::startSearch, m_detailArea, &DetailArea::hide); connect(this, &SearchResultPage::stopSearch, m_detailArea, &DetailArea::hide); + + connect(m_resultArea, &ResultArea::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo); + connect(m_resultArea, &ResultArea::currentRowChanged, this, &SearchResultPage::currentRowChanged); + connect(this, &SearchResultPage::currentRowChanged, m_resultArea, &ResultArea::clearSelectedRow); + connect(m_resultArea, &ResultArea::resizeHeight, this, &SearchResultPage::resizeHeight); } void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget) diff --git a/frontend/control/stack-pages/search-result-page.h b/frontend/control/stack-pages/search-result-page.h index 057edcf..18686a7 100644 --- a/frontend/control/stack-pages/search-result-page.h +++ b/frontend/control/stack-pages/search-result-page.h @@ -42,7 +42,7 @@ private: void initConnections(); void setupConnectionsForWidget(ResultWidget *); QSplitter * m_splitter = nullptr; - QHBoxLayout *m_hlayout = nullptr; + QHBoxLayout * m_hlayout = nullptr; ResultArea * m_resultArea = nullptr; DetailArea * m_detailArea = nullptr; @@ -51,6 +51,7 @@ Q_SIGNALS: void stopSearch(); void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); void effectiveSearch(); + void resizeHeight(int height); }; } diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index c3fde1d..4c6aee1 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -170,6 +170,7 @@ void MainWindow::initConnections() // }); connect(m_searchBarWidget, &SeachBarWidget::requestSearchKeyword, this, &MainWindow::searchKeywordSlot); // connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord); + //connect(m_searchResultPage, &SearchResultPage::resizeHeight, this, &MainWindow::resizeHeight); } /** @@ -303,7 +304,7 @@ void MainWindow::searchKeywordSlot(const QString &keyword) if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH) m_askTimer->start(); Q_EMIT m_searchResultPage->startSearch(keyword); - this->resizeHeight(610); + this->resizeHeight(WINDOW_HEIGHT); m_searchResultPage->move(0, 58); m_searchResultPage->show(); diff --git a/frontend/model/best-list-model.cpp b/frontend/model/best-list-model.cpp new file mode 100644 index 0000000..3ff96c0 --- /dev/null +++ b/frontend/model/best-list-model.cpp @@ -0,0 +1,138 @@ +/* + * + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: jixiaoxu + * + */ +#include "best-list-model.h" +using namespace Zeeker; + +BestListModel::BestListModel(QObject *parent) + : QAbstractItemModel(parent) +{ + m_item = new SearchResultItem; + initConnections(); +} + +QModelIndex BestListModel::index(int row, int column, const QModelIndex &parent) const +{ + if(row < 0 || row > m_item->m_result_info_list.length() - 1) + return QModelIndex(); + return createIndex(row, column, m_item); +} + +QModelIndex BestListModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} + +int BestListModel::rowCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : (m_isExpanded ? m_item->m_result_info_list.length() : NUM_LIMIT_SHOWN_DEFAULT); +} + +int BestListModel::columnCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : 1; +} + +QVariant BestListModel::data(const QModelIndex &index, int role) const +{ + switch(role) { + case Qt::DecorationRole: { + return m_item->m_result_info_list.at(index.row()).icon; + } + case Qt::DisplayRole: { + return m_item->m_result_info_list.at(index.row()).name; + } + default: + return QVariant(); + } + return QVariant(); +} + +const SearchPluginIface::ResultInfo &BestListModel::getInfo(const QModelIndex &index) +{ + return m_item->m_result_info_list.at(index.row()); +} + +const QString &BestListModel::getPluginInfo(const QModelIndex &index) +{ + return m_plugin_id_list.at(index.row()); +} + +void BestListModel::setExpanded(const bool &is_expanded) +{ + this->beginResetModel(); + m_isExpanded = is_expanded; + this->endResetModel(); + Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); +} + +const bool &BestListModel::isExpanded() +{ + return m_isExpanded; +} + +QStringList BestListModel::getActions(const QModelIndex &index) +{ +// if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0) +// return m_item->m_result_info_list.at(index.row()).actionList; + return QStringList(); +} + +QString BestListModel::getKey(const QModelIndex &index) +{ + if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0) + return m_item->m_result_info_list.at(index.row()).actionKey; + return NULL; +} + +void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface::ResultInfo &info) +{ + if (m_plugin_id_list.contains(pluginId)) { + if (info.name == m_item->m_result_info_list.at(m_plugin_id_list.lastIndexOf(pluginId)).name) { + return; + } + qDebug()<<"plugin ID:"< m_plugin_id_list; + bool m_isExpanded = false; +}; +} +#endif // BESTLISTMODEL_H diff --git a/frontend/model/model.pri b/frontend/model/model.pri index 05b21b8..7e704a4 100644 --- a/frontend/model/model.pri +++ b/frontend/model/model.pri @@ -1,9 +1,11 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/best-list-model.h \ $$PWD/search-result-manager.h \ $$PWD/search-result-model.h \ SOURCES += \ + $$PWD/best-list-model.cpp \ $$PWD/search-result-manager.cpp \ $$PWD/search-result-model.cpp \ diff --git a/frontend/model/search-result-model.cpp b/frontend/model/search-result-model.cpp index a3928ba..288bc94 100644 --- a/frontend/model/search-result-model.cpp +++ b/frontend/model/search-result-model.cpp @@ -79,8 +79,9 @@ void SearchResultModel::appendInfo(const SearchPluginIface::ResultInfo &info) this->beginResetModel(); qDebug()<<"Got a result. name ="<m_result_info_list.append(info); - Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); this->endResetModel(); + Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); + Q_EMIT this->sendBestListData(m_plugin_id, m_item->m_result_info_list.at(0)); } void SearchResultModel::startSearch(const QString &keyword) @@ -88,8 +89,8 @@ void SearchResultModel::startSearch(const QString &keyword) if (!m_item->m_result_info_list.isEmpty()) { this->beginResetModel(); m_item->m_result_info_list.clear(); - Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); this->endResetModel(); + Q_EMIT this->itemListChanged(m_item->m_result_info_list.length()); } m_search_manager->startSearch(keyword); } diff --git a/frontend/model/search-result-model.h b/frontend/model/search-result-model.h index 968e40b..f9b01b3 100644 --- a/frontend/model/search-result-model.h +++ b/frontend/model/search-result-model.h @@ -29,6 +29,7 @@ namespace Zeeker { class SearchResultItem : public QObject { friend class SearchResultModel; + friend class BestListModel; Q_OBJECT public: explicit SearchResultItem(QObject *parent = nullptr); @@ -62,6 +63,7 @@ public Q_SLOTS: Q_SIGNALS: void stopSearch(); void itemListChanged(const int&); + void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); private: void initConnections(); diff --git a/frontend/view/best-list-view.cpp b/frontend/view/best-list-view.cpp new file mode 100644 index 0000000..b86f228 --- /dev/null +++ b/frontend/view/best-list-view.cpp @@ -0,0 +1,244 @@ +#include "best-list-view.h" +#define MAIN_MARGINS 0,0,0,0 +#define MAIN_SPACING 0 +#define TITLE_HEIGHT 30 +#define UNFOLD_LABEL_HEIGHT 30 + +using namespace Zeeker; +BestListView::BestListView(QWidget *parent) : QTreeView(parent) +{ + this->setFrameShape(QFrame::NoFrame); + this->viewport()->setAutoFillBackground(false); + this->setRootIsDecorated(false); + this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->setSelectionBehavior(QAbstractItemView::SelectRows); + this->setSelectionMode(QAbstractItemView::SingleSelection); + this->setHeaderHidden(true); + m_model = new BestListModel(this); + this->setModel(m_model); + initConnections(); + m_style_delegate = new ResultViewDelegate(this); + this->setItemDelegate(m_style_delegate); +} +bool BestListView::isSelected() +{ + return m_is_selected; +} + +int BestListView::showHeight() +{ + int height; + int rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())) + 1; + if (this->isExpanded()) { + height = m_count * rowheight; + } else { + int show_count = m_count > NUM_LIMIT_SHOWN_DEFAULT ? NUM_LIMIT_SHOWN_DEFAULT : m_count; + height = show_count * rowheight; + } + return height; +} + +void BestListView::clearSelectedRow() +{ + if (!m_is_selected) { + this->blockSignals(true); + this->clearSelection(); + this->blockSignals(false); + } +} + +/** + * @brief BestListView::onRowDoubleClickedSlot 处理列表中的双击打开事件 + * @param index 点击的条目 + */ +void BestListView::onRowDoubleClickedSlot(const QModelIndex &index) +{ + const SearchPluginIface::ResultInfo &info = m_model->getInfo(index); +// SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id); +// try { +// if (plugin) { +//// if (!info.actionList.isEmpty()) { +//// plugin->openAction(info.actionList.at(0), info.key); +//// } else { +//// throw -2; +//// } +// } else { +// throw -1; +// } +// } catch(int e) { +// qWarning()<<"Open failed, reason="<currentRowChanged(m_model->getPluginInfo(this->currentIndex()), m_model->getInfo(this->currentIndex())); + m_is_selected = false; + if(!selected.isEmpty()) { + QRegion region = visualRegionForSelection(selected); + QRect rect = region.boundingRect(); +// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft())); + } +} + +void BestListView::onItemListChanged(const int &count) +{ + m_count = count; + Q_EMIT this->listLengthChanged(count); +} + +void BestListView::setExpanded(const bool &is_expanded) +{ + m_model->setExpanded(is_expanded); +} + +const bool &BestListView::isExpanded() +{ + return m_model->isExpanded(); +} + +/** + * @brief BestListView::onMenuTriggered 点击右键菜单的槽函数 + * @param action + */ +void BestListView::onMenuTriggered(QAction *action) +{ + //NEW_TODO 接口调整后需要修改 +// SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id); +// if (plugin) { +//// plugin->openAction(action->text(), m_model->getKey(this->currentIndex())); +// } else { +// qWarning()<<"Get plugin failed!"; +// } +} + +void BestListView::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) { + //加一点点延时,等待列表先被选中 + QTimer::singleShot(10, this, [ = ] { + QMenu * menu = new QMenu(this); + QStringList actions = m_model->getActions(this->currentIndex()); + Q_FOREACH (QString action, actions) { + menu->addAction(new QAction(action, this)); + } + menu->move(cursor().pos()); + menu->show(); + connect(menu, &QMenu::triggered, this, &BestListView::onMenuTriggered); + }); + } + Q_EMIT this->rowClicked(); + return QTreeView::mousePressEvent(event); +} + +void BestListView::initConnections() +{ + connect(this, &BestListView::startSearch, [ = ](const QString &keyword) { + qDebug() << "==========start search!"; + m_style_delegate->setSearchKeyword(keyword); + m_model->startSearch(keyword); + }); + connect(this, &BestListView::startSearch, m_model, &BestListModel::startSearch); + connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &BestListView::onRowSelectedSlot); + connect(this, &BestListView::activated, this, &BestListView::onRowDoubleClickedSlot); + connect(m_model, &BestListModel::itemListChanged, this, &BestListView::onItemListChanged); + connect(this, &BestListView::sendBestListData, m_model, &BestListModel::appendInfo); +} + +BestListWidget::BestListWidget(QWidget *parent) : QWidget(parent) +{ + this->initUi(); + initConnections(); +} + +void BestListWidget::setEnabled(const bool &enabled) +{ + m_enabled = enabled; +} + +/** + * @brief BestListWidget::expandListSlot 展开列表的槽函数 + */ +void BestListWidget::expandListSlot() +{ + qWarning()<<"List will be expanded!"; + m_bestListView->setExpanded(true); +} + +/** + * @brief BestListWidget::reduceListSlot 收起列表的槽函数 + */ +void BestListWidget::reduceListSlot() +{ + qWarning()<<"List will be reduced!"; + m_bestListView->setExpanded(false); +} + +/** + * @brief BestListWidget::onListLengthChanged 响应列表长度改变的槽函数 + */ +void BestListWidget::onListLengthChanged(const int &length) +{ + this->setVisible(length > 0); + m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT); + int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; + int whole_height = this->isVisible() ? (m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height) : 0; + this->setFixedHeight(whole_height); + Q_EMIT this->sizeChanged(); +} + +void BestListWidget::initUi() +{ + m_mainLyt = new QVBoxLayout(this); + this->setLayout(m_mainLyt); + m_mainLyt->setContentsMargins(MAIN_MARGINS); + m_mainLyt->setSpacing(MAIN_SPACING); + + m_titleLabel = new TitleLabel(this); + m_titleLabel->setText(tr("Best Matches")); + m_titleLabel->setFixedHeight(TITLE_HEIGHT); + + m_bestListView = new BestListView(this); + + m_showMoreLabel = new ShowMoreLabel(this); + m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT); + m_showMoreLabel->hide(); + + m_mainLyt->addWidget(m_titleLabel); + m_mainLyt->addWidget(m_bestListView); + m_mainLyt->addWidget(m_showMoreLabel); + this->setFixedHeight(m_bestListView->height() + TITLE_HEIGHT); +} + +void BestListWidget::initConnections() +{ + connect(this, &BestListWidget::startSearch, m_bestListView, &BestListView::startSearch); + connect(this, &BestListWidget::startSearch, this, [ = ]() { + m_showMoreLabel->resetLabel(); + }); + //connect(this, &BestListWidget::stopSearch, m_bestListView, &BestListView::stopSearch); + connect(this, &BestListWidget::stopSearch, this, [ = ]() { + m_showMoreLabel->resetLabel(); + m_bestListView->setExpanded(false); + }); + connect(this, &BestListWidget::sendBestListData, m_bestListView, &BestListView::sendBestListData); + connect(m_bestListView, &BestListView::currentRowChanged, this, &BestListWidget::currentRowChanged); + connect(this, &BestListWidget::clearSelectedRow, m_bestListView, &BestListView::clearSelectedRow); + connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &BestListWidget::expandListSlot); + connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &BestListWidget::reduceListSlot); + connect(m_bestListView, &BestListView::listLengthChanged, this, &BestListWidget::onListLengthChanged); + connect(m_bestListView, &BestListView::rowClicked, this, &BestListWidget::rowClicked); + connect(qApp, &QApplication::paletteChanged, this, [ = ]() { + int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; + int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height : 0; + this->setFixedHeight(whole_height); + Q_EMIT this->sizeChanged(); + }); +} diff --git a/frontend/view/best-list-view.h b/frontend/view/best-list-view.h new file mode 100644 index 0000000..d6a7060 --- /dev/null +++ b/frontend/view/best-list-view.h @@ -0,0 +1,88 @@ +#ifndef BESTLISTVIEW_H +#define BESTLISTVIEW_H +#include +#include +#include +#include +#include +#include "best-list-model.h" +#include "show-more-label.h" +#include "title-label.h" +#include "result-view-delegate.h" + +namespace Zeeker { + +class BestListView : public QTreeView +{ + Q_OBJECT +public: + BestListView(QWidget *parent = nullptr); + ~BestListView() = default; + bool isSelected(); + int showHeight(); + +public Q_SLOTS: + void clearSelectedRow(); + void onRowDoubleClickedSlot(const QModelIndex &); + void onRowSelectedSlot(const QItemSelection &, const QItemSelection &); + void onItemListChanged(const int &); + void setExpanded(const bool &); + const bool &isExpanded(); + void onMenuTriggered(QAction *); + +protected: + void mousePressEvent(QMouseEvent *event) override; + +private: + void initConnections(); + BestListModel * m_model = nullptr; + bool m_is_selected = false; + ResultViewDelegate * m_style_delegate = nullptr; + int m_count = 0; + +Q_SIGNALS: + void startSearch(const QString &); + void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); + void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); + void listLengthChanged(const int &); + void rowClicked(); + +}; + + +class BestListWidget : public QWidget +{ + Q_OBJECT +public: + BestListWidget(QWidget *parent = nullptr); + ~BestListWidget() = default; + void setEnabled(const bool&); + +public Q_SLOTS: + void expandListSlot(); + void reduceListSlot(); + void onListLengthChanged(const int &); + +private: + bool m_enabled = true; + + void initUi(); + void initConnections(); + QVBoxLayout * m_mainLyt = nullptr; + TitleLabel * m_titleLabel = nullptr; + BestListView * m_bestListView = nullptr; + ShowMoreLabel * m_showMoreLabel = nullptr; + +Q_SIGNALS: + void startSearch(const QString &); + void stopSearch(); + void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); + void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); + void clearSelectedRow(); + void sizeChanged(); + void rowClicked(); +}; + +} + +#endif // BESTLISTVIEW_H diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index d8b109f..5dac241 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -99,6 +99,7 @@ void ResultWidget::initConnections() this->setFixedHeight(whole_height); Q_EMIT this->sizeChanged(); }); + connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData); } ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(parent) @@ -249,4 +250,5 @@ void ResultView::initConnections() connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResultView::onRowSelectedSlot); connect(this, &ResultView::activated, this, &ResultView::onRowDoubleClickedSlot); connect(m_model, &SearchResultModel::itemListChanged, this, &ResultView::onItemListChanged); + connect(m_model, &SearchResultModel::sendBestListData, this, &ResultView::sendBestListData); } diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index 190cd40..c129f11 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -45,6 +45,7 @@ Q_SIGNALS: void startSearch(const QString &); void stopSearch(); void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); + void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); void listLengthChanged(const int &); void rowClicked(); }; @@ -78,6 +79,7 @@ Q_SIGNALS: void startSearch(const QString &); void stopSearch(); void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); + void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); void clearSelectedRow(); void sizeChanged(); void rowClicked(); diff --git a/frontend/view/view.pri b/frontend/view/view.pri index 7e6d820..347b8d5 100644 --- a/frontend/view/view.pri +++ b/frontend/view/view.pri @@ -1,9 +1,11 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/best-list-view.h \ $$PWD/result-view-delegate.h \ $$PWD/result-view.h \ SOURCES += \ + $$PWD/best-list-view.cpp \ $$PWD/result-view-delegate.cpp \ $$PWD/result-view.cpp \ diff --git a/libsearch/pluginmanage/search-plugin-manager.cpp b/libsearch/pluginmanage/search-plugin-manager.cpp index 0eaf131..3183201 100644 --- a/libsearch/pluginmanage/search-plugin-manager.cpp +++ b/libsearch/pluginmanage/search-plugin-manager.cpp @@ -9,19 +9,20 @@ using namespace Zeeker; static SearchPluginManager *global_instance = nullptr; SearchPluginManager::SearchPluginManager(QObject *parent) { - registerPlugin(new FileSearchPlugin(this)); - registerPlugin(new DirSearchPlugin(this)); - registerPlugin(new FileContengSearchPlugin(this)); registerPlugin(new AppSearchPlugin(this)); registerPlugin(new SettingsSearchPlugin(this)); + registerPlugin(new DirSearchPlugin(this)); + registerPlugin(new FileSearchPlugin(this)); + registerPlugin(new FileContengSearchPlugin(this)); + } bool SearchPluginManager::registerPlugin(Zeeker::SearchPluginIface *plugin) { - if (m_hash.value(plugin->name())) { + if (m_map.end() != m_map.find(plugin->name())){ return false; } - m_hash.insert(plugin->name(), plugin); + m_map[plugin->name()] = plugin; return true; } @@ -35,12 +36,16 @@ SearchPluginManager *SearchPluginManager::getInstance() const QStringList SearchPluginManager::getPluginIds() { - return m_hash.keys(); + QStringList list; + for (auto i = m_map.begin(); i != m_map.end(); i++) { + list.append((*i).first); + } + return list; } SearchPluginIface *SearchPluginManager::getPlugin(const QString &pluginId) { - return m_hash.value(pluginId); + return m_map[pluginId]; } void SearchPluginManager::close() @@ -50,5 +55,5 @@ void SearchPluginManager::close() SearchPluginManager::~SearchPluginManager() { - m_hash.clear(); + m_map.clear(); } diff --git a/libsearch/pluginmanage/search-plugin-manager.h b/libsearch/pluginmanage/search-plugin-manager.h index 5722ce2..cb96c7b 100644 --- a/libsearch/pluginmanage/search-plugin-manager.h +++ b/libsearch/pluginmanage/search-plugin-manager.h @@ -5,6 +5,14 @@ #include "search-plugin-iface.h" namespace Zeeker { + +struct cmpPluginId +{ + bool operator ()(const QString& k1, const QString& k2){ + return k1 > k2; + } +}; + class SearchPluginManager : public QObject { Q_OBJECT @@ -18,8 +26,7 @@ public: void close(); private: - QHash m_hash; - + std::map m_map; explicit SearchPluginManager(QObject *parent = nullptr); ~SearchPluginManager(); diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 61231e5..6aacb22 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -9,6 +9,14 @@ + + Zeeker::BestListWidget + + + Best Matches + + + Zeeker::CreateIndexAskDialog diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index 219d00a..a37f8ab 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -244,6 +244,14 @@ Yükleniyor... + + Zeeker::BestListWidget + + + Best Matches + En İyi Eşleşen + + Zeeker::ContentWidget diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index e5bfe35..013eb08 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -9,6 +9,14 @@ + + Zeeker::BestListWidget + + + Best Matches + 最佳匹配 + + Zeeker::ContentWidget @@ -274,7 +282,7 @@ Whether to delete this directory? - 是否要删除此目录 + 是否要删除此目录? @@ -289,7 +297,7 @@ Creating ... - 正在索引 + 正在索引...