diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index ecb5e6e..e4e95a7 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -837,3 +837,60 @@ QString FileUtils::chineseSubString(const std::string &myStr, int start, int len } return sub; } + +QString FileUtils::getHtmlText(const QString &text, const QString &keyword) +{ + QString htmlString; + bool boldOpenned = false; + for(int i = 0; i < text.length(); i++) { + if((keyword.toUpper()).contains(QString(text.at(i)).toUpper())) { + if(! boldOpenned) { + boldOpenned = true; + htmlString.append(QString("")); + } + htmlString.append(FileUtils::escapeHtml(QString(text.at(i)))); + } else { + if(boldOpenned) { + boldOpenned = false; + htmlString.append(QString("")); + } + htmlString.append(FileUtils::escapeHtml(QString(text.at(i)))); + } + } + htmlString.replace("\n", "
");//替换换行符 + return htmlString; +} + +QString FileUtils::wrapData(QLabel *p_label, const QString &text) +{ + QString wrapText = text; + + QFontMetrics fontMetrics = p_label->fontMetrics(); + int textSize = fontMetrics.width(wrapText); + + if(textSize > LABEL_MAX_WIDTH){ + int lastIndex = 0; + int count = 0; + + for(int i = lastIndex; i < wrapText.length(); i++) { + + if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) == LABEL_MAX_WIDTH) { + lastIndex = i; + wrapText.insert(i, '\n'); + count++; + } else if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) > LABEL_MAX_WIDTH) { + lastIndex = i; + wrapText.insert(i - 1, '\n'); + count++; + } else { + continue; + } + + if(count == 2){ + break; + } + } + } +// p_label->setText(wrapText); + return wrapText; +} diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index 856acd2..0b3bd69 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,8 @@ namespace Zeeker { class LIBSEARCH_EXPORT FileUtils { public: + static QString getHtmlText(const QString & text, const QString & keyword); + static QString wrapData(QLabel *p_label, const QString &text); static std::string makeDocUterm(QString); static QIcon getFileIcon(const QString &, bool checkValid = true); static QIcon getAppIcon(const QString &); diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index 4bbc87a..c3deb62 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -35,6 +35,7 @@ void NoteSearchPlugin::KeywordSearch(QString keyword, DataQueuesetToolTip(ri.name); } m_pluginLabel->setText(tr("Application")); - QString showDesc = fontMetrics.elidedText(ri.description.at(0).key + " " + ri.description.at(0).value, Qt::ElideRight, 3114); //当字体长度超过215时显示为省略号 - m_descLabel->setText(FileUtils::escapeHtml(showDesc)); + QString showDesc = fontMetrics.elidedText(/*ri.description.at(0).key + " " + */ri.description.at(0).value, Qt::ElideRight, m_descLabel->width() * 2); //当字体长度超过215时显示为省略号 + m_descLabel->setText(FileUtils::getHtmlText(FileUtils::wrapData(m_descLabel, showDesc), m_keyword)); m_descFrame->show(); m_line_2->show(); return m_detailPage; @@ -105,7 +106,7 @@ void NoteSearchPlugin::initDetailPage() m_descFrame = new QFrame(m_detailPage); m_descFrameLyt = new QVBoxLayout(m_descFrame); m_descLabel = new QLabel(m_descFrame); - m_descLabel->setTextFormat(Qt::PlainText); + m_descLabel->setTextFormat(Qt::AutoText); m_descLabel->setWordWrap(true); m_descFrameLyt->addWidget(m_descLabel); m_descFrame->setLayout(m_descFrameLyt); @@ -190,7 +191,12 @@ void NoteSearch::run() { }, actionKey : it.first }; - m_searchResult->enqueue(ri); + if (m_uniqueSymbol ^ g_uniqueSymbol) { + qDebug() << m_uniqueSymbol << g_uniqueSymbol; + return; + } else { + m_searchResult->enqueue(ri); + } } } } else { diff --git a/libsearch/notesearch/note-search-plugin.h b/libsearch/notesearch/note-search-plugin.h index 2080bac..addbc1b 100644 --- a/libsearch/notesearch/note-search-plugin.h +++ b/libsearch/notesearch/note-search-plugin.h @@ -66,6 +66,7 @@ private: QVBoxLayout * m_actionLyt = nullptr; bool m_enable = true; + QString m_keyword; QList m_actionInfo; QThreadPool m_pool; }; @@ -78,9 +79,9 @@ public: protected: void run() override; private: + QString m_keyword; DataQueue *m_searchResult = nullptr; size_t m_uniqueSymbol; - QString m_keyword; }; }