diff --git a/frontend/view/best-list-view.cpp b/frontend/view/best-list-view.cpp index 03ee802..ccdd9b1 100644 --- a/frontend/view/best-list-view.cpp +++ b/frontend/view/best-list-view.cpp @@ -295,6 +295,7 @@ void BestListWidget::initConnections() connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &BestListWidget::expandListSlot); connect(m_titleLabel, &TitleLabel::retractClicked, this, &BestListWidget::reduceListSlot); connect(m_bestListView, &BestListView::listLengthChanged, this, &BestListWidget::onListLengthChanged); + connect(m_bestListView, &BestListView::listLengthChanged, m_titleLabel, &TitleLabel::onListLengthChanged); connect(m_bestListView, &BestListView::clicked, this, &BestListWidget::rowClicked); connect(qApp, &QApplication::paletteChanged, this, [ = ]() { int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT : 0; diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index 27af944..a22ec58 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -33,10 +33,14 @@ QString SettingsSearchPlugin::getPluginName() void Zeeker::SettingsSearchPlugin::KeywordSearch(QString keyword, DataQueue *searchResult) { + if (keyword == "/") + return; QStringList pinyinlist; + QStringList resultName; ResultInfo resultInfo; resultInfo.type = 0; QLocale ql; + /* if (ql.language() == QLocale::Chinese) { for (auto i = m_chineseSearchList.constBegin(); i != m_chineseSearchList.constEnd(); ++i) { QStringList regmatch = *i; @@ -99,6 +103,108 @@ void Zeeker::SettingsSearchPlugin::KeywordSearch(QString keyword, DataQueueenqueue(resultInfo); + continue; + } + if (ql.language() == QLocale::Chinese) { + pinyinlist = FileUtils::findMultiToneWords(str); + for (int i = 0; i < pinyinlist.size() / 2; i++) { + str = regmatch.at(t); + QString shouzimu = pinyinlist.at(2 * i + 1); // 中文转首字母 + if (shouzimu.contains(keyword, Qt::CaseInsensitive)) { + resultInfo.name = str; + if (resultName.contains(resultInfo.name)) { + continue; + } + resultName.append(resultInfo.name); + str = key + "/" + str; + resultInfo.icon = FileUtils::getSettingIcon(str, true); + resultInfo.actionKey = str; + searchResult->enqueue(resultInfo); + break; + } + if (keyword.size() < 2) + break; + QString pinyin = pinyinlist.at(2 * i); // 中文转拼音 + if (pinyin.contains(keyword, Qt::CaseInsensitive)) { + resultInfo.name = str; + if (resultName.contains(resultInfo.name)) { + continue; + } + resultName.append(resultInfo.name); + str = key + "/" + str; + resultInfo.icon = FileUtils::getSettingIcon(str, true); + resultInfo.actionKey = str; + searchResult->enqueue(resultInfo); + break; + } + } + } + } + } + for (auto i = m_englishSearchList.constBegin(); i != m_englishSearchList.constEnd(); ++i) { + QStringList regmatch = *i; + QString key = i.key(); + for (int t = 0; t < regmatch.size(); t++) { + QString str = regmatch.at(t); + if (str.contains(keyword, Qt::CaseInsensitive)) { + resultInfo.name = ql.language() == QLocale::Chinese ? m_chineseSearchList[key].at(t) : str; + if (resultName.contains(resultInfo.name)) { + continue; + } + resultName.append(resultInfo.name); + str = key + "/" + str; + resultInfo.icon = FileUtils::getSettingIcon(str, true); + resultInfo.actionKey = str; + searchResult->enqueue(resultInfo); + } + } + } + for (auto i = m_mixSearchList.constBegin(); i != m_mixSearchList.constEnd(); ++i) { + QMap regmatch = *i; + QString key = i.key(); + for (auto t = regmatch.begin(); t != regmatch.end(); ++t) { + QString englishStr = t.value(); + QString chineseStr = t.key(); + if (chineseStr.contains(keyword, Qt::CaseInsensitive)) { + resultInfo.name = ql.language() == QLocale::Chinese ? chineseStr : englishStr; + if (resultName.contains(resultInfo.name)) { + continue; + } + resultName.append(resultInfo.name); + chineseStr = key + "/" + chineseStr; + resultInfo.icon = FileUtils::getSettingIcon(chineseStr, true); + resultInfo.actionKey = chineseStr; + searchResult->enqueue(resultInfo); + } + if (englishStr.contains(keyword, Qt::CaseInsensitive)) { + resultInfo.name = ql.language() == QLocale::Chinese ? chineseStr : englishStr; + if (resultName.contains(resultInfo.name)) { + continue; + } + resultName.append(resultInfo.name); + englishStr = key + "/" + englishStr; + resultInfo.icon = FileUtils::getSettingIcon(englishStr, true); + resultInfo.actionKey = englishStr; + searchResult->enqueue(resultInfo); + } + } + } } QList SettingsSearchPlugin::getActioninfo(int type) @@ -186,9 +292,16 @@ void SettingsSearchPlugin::xmlElement() { } continue; } - - if (n.nodeName() == QString::fromLocal8Bit("ChinesePlugin") - or n.nodeName() == QString::fromLocal8Bit("ChineseFunc")) { + if (n.nodeName() == QString::fromLocal8Bit("ChinesePlugin")) { + chineseIndex = n.toElement().text(); + if (chineseIndex.isEmpty()) { + continue; + } + if (0 == m_mixSearchList[key].count(chineseIndex)) { + m_mixSearchList[key].insert(chineseIndex, key); + } + } + if (n.nodeName() == QString::fromLocal8Bit("ChineseFunc")) { chineseIndex = n.toElement().text(); if (chineseIndex.isEmpty()) { continue; @@ -201,7 +314,7 @@ void SettingsSearchPlugin::xmlElement() { } if (n.nodeName() == QString::fromLocal8Bit("EnglishFunc")) { - englishIndex = QString::fromLocal8Bit("/") + n.toElement().text(); + englishIndex = /*QString::fromLocal8Bit("/") + */n.toElement().text(); if (englishIndex.isEmpty()) { continue; } diff --git a/libsearch/settingsearch/settings-search-plugin.h b/libsearch/settingsearch/settings-search-plugin.h index 41cb6c5..a618cae 100644 --- a/libsearch/settingsearch/settings-search-plugin.h +++ b/libsearch/settingsearch/settings-search-plugin.h @@ -17,6 +17,7 @@ class LIBSEARCH_EXPORT SettingsSearchPlugin : public QObject, public SearchPlugi { Q_OBJECT public: + SettingsSearchPlugin(QObject *parent = nullptr); PluginType pluginType() {return PluginType::SearchPlugin;} const QString name(); @@ -51,9 +52,9 @@ private: QVBoxLayout * m_actionLyt = nullptr; - QMap m_chineseSearchList; QMap m_englishSearchList; + QMap> m_mixSearchList;//map数据对应Chinese Name和English Name bool m_enable = true; QList m_actionInfo;