diff --git a/frontend/view/result-view-delegate.cpp b/frontend/view/result-view-delegate.cpp index e6998e7..6770636 100644 --- a/frontend/view/result-view-delegate.cpp +++ b/frontend/view/result-view-delegate.cpp @@ -54,7 +54,7 @@ QString ResultViewDelegate::getHtmlText(QPainter *painter, const QStyleOptionVie QString indexString = index.model()->data(index, Qt::DisplayRole).toString(); QFont ft(painter->font().family(), GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toInt()); QFontMetrics fm(ft); - QString indexColString = fm.elidedText(indexString, Qt::ElideRight, itemOption.rect.width() - 30); //当字体超过Item的长度时显示为省略号 + QString indexColString = fm.elidedText(indexString, Qt::ElideRight, itemOption.rect.width() - 30 - 10); //当字体超过Item的长度时显示为省略号 QString htmlString; if((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) { indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置 @@ -79,7 +79,7 @@ QString ResultViewDelegate::getHtmlText(QPainter *painter, const QStyleOptionVie } } // qDebug()<"<" + htmlString + ""; } QString ResultViewDelegate::escapeHtml(const QString &str) const diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 505587b..149cc6e 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -99,7 +99,7 @@ QWidget *AppSearchPlugin::detailPage(const ResultInfo &ri) m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); } diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 901d045..527ebbe 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -107,7 +107,7 @@ QIcon FileUtils::getAppIcon(const QString &path) { * @param is_white 选择是否返回白色图标 * @return */ -QIcon FileUtils::getSettingIcon(const QString& setting, const bool& is_white) { +QIcon FileUtils::getSettingIcon(const QString &setting, const bool is_white) { QString name = setting.left(setting.indexOf("/")); if(! name.isEmpty()) { name.replace(QString(name.at(0)), QString(name.at(0).toUpper())); @@ -140,7 +140,7 @@ QIcon FileUtils::getSettingIcon() { * @param uri 格式为"file:///home/xxx/xxx/xxxx.txt" * @return */ -QString FileUtils::getFileName(const QString& uri) { +QString FileUtils::getFileName(const QString &uri) { QFileInfo info(uri); if(info.exists()) { return info.fileName(); @@ -159,7 +159,7 @@ QString FileUtils::getFileName(const QString& uri) { * @param path .destop文件的完整路径 * @return */ -QString FileUtils::getAppName(const QString& path) { +QString FileUtils::getAppName(const QString &path) { QByteArray ba; ba = path.toUtf8(); GKeyFile * keyfile; @@ -178,7 +178,7 @@ QString FileUtils::getAppName(const QString& path) { * @param setting 设置项传入参数,格式为 About/About->Properties * @return */ -QString FileUtils::getSettingName(const QString& setting) { +QString FileUtils::getSettingName(const QString &setting) { return setting.right(setting.length() - setting.lastIndexOf("/") - 1); } @@ -242,7 +242,7 @@ QString FileUtils::find(const QString &hanzi) { } //DFS多音字太多直接GG -void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYin, const QString& resultFirst, QStringList& resultList) { +void stitchMultiToneWordsDFS(const QString &hanzi, const QString &resultAllPinYin, const QString &resultFirst, QStringList &resultList) { if(hanzi.size() == 0) { resultList.append(resultAllPinYin); resultList.append(resultFirst); @@ -258,7 +258,7 @@ void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYi } //BFS+Stack多音字太多会爆栈 -void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList) { +void stitchMultiToneWordsBFSStack(const QString &hanzi, QStringList &resultList) { QString tempHanzi, resultAllPinYin, resultFirst; QQueue tempQueue; tempHanzi = hanzi; @@ -293,7 +293,7 @@ void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList) } } //BFS+Heap,多音字太多会耗尽内存 -void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList) { +void stitchMultiToneWordsBFSHeap(const QString &hanzi, QStringList &resultList) { QString tempHanzi, resultAllPinYin, resultFirst; QQueue* tempQueue = new QQueue; tempHanzi = hanzi; @@ -331,7 +331,7 @@ void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList) } //BFS+Heap+超过3个多音字只建一个索引,比较折中的方案 -void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultList) { +void stitchMultiToneWordsBFSHeapLess3(const QString &hanzi, QStringList &resultList) { QString tempHanzi, resultAllPinYin, resultFirst; QQueue* tempQueue = new QQueue; QQueue* tempQueueFirst = new QQueue; @@ -404,7 +404,7 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL } //BFS+Stack+超过3个多音字只建一个索引,比较折中的方案 -void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& resultList) { +void stitchMultiToneWordsBFSStackLess3(const QString &hanzi, QStringList &resultList) { QString tempHanzi, resultAllPinYin, resultFirst; QQueue tempQueue; QQueue tempQueueFirst; @@ -476,7 +476,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result return; } -QStringList FileUtils::findMultiToneWords(const QString& hanzi) { +QStringList FileUtils::findMultiToneWords(const QString &hanzi) { // QStringList* output = new QStringList(); QStringList output; QString tempAllPinYin, tempFirst; @@ -983,7 +983,12 @@ QString FileUtils::getHtmlText(const QString &text, const QString &keyword) } } htmlString.replace("\n", "
");//替换换行符 - return htmlString; + return "
" + htmlString + "
"; +} + +QString FileUtils::setAllTextBold(const QString &name) +{ + return QString("

%1

").arg(escapeHtml(name)); } QString FileUtils::wrapData(QLabel *p_label, const QString &text) diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index 0dc6393..8176ae9 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -62,25 +62,26 @@ namespace UkuiSearch { class LIBSEARCH_EXPORT FileUtils { public: - static QString getHtmlText(const QString & text, const QString & keyword); + static QString getHtmlText(const QString &text, const QString &keyword); + static QString setAllTextBold(const QString &name); 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 &); - static QIcon getSettingIcon(const QString &, const bool&); + static std::string makeDocUterm(QString path); + static QIcon getFileIcon(const QString &uri, bool checkValid = true); + static QIcon getAppIcon(const QString &path); + static QIcon getSettingIcon(const QString &setting, const bool is_white); static QIcon getSettingIcon(); - static QString getFileName(const QString &); - static QString getAppName(const QString &); - static QString getSettingName(const QString &); + static QString getFileName(const QString &uri); + static QString getAppName(const QString &path); + static QString getSettingName(const QString &setting); //A is or under B static bool isOrUnder(QString pathA, QString pathB); //chinese character to pinyin static QMap map_chinese2pinyin; - static QString find(const QString&); - static QStringList findMultiToneWords(const QString&); - static void loadHanziTable(const QString&); + static QString find(const QString &hanzi); + static QStringList findMultiToneWords(const QString &hanzi); + static void loadHanziTable(const QString &fileName); //parse text,docx..... static QMimeType getMimetype(QString &path); @@ -92,9 +93,9 @@ public: static int openFile(QString &path, bool openInDir = false); static bool copyPath(QString &path); - static QString escapeHtml(const QString & str); + static QString escapeHtml(const QString &str); static QString chineseSubString(const std::string &myStr,int start,int length); - static QIcon iconFromTheme(const QString& name, const QIcon &iconDefault); + static QIcon iconFromTheme(const QString &name, const QIcon &iconDefault); static bool isOpenXMLFileEncrypted(QString &path); static bool isEncrypedOrUnreadable(QString path); static size_t _max_index_count; diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index ed08bb0..6e86f8c 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -86,7 +86,7 @@ QWidget *FileSearchPlugin::detailPage(const ResultInfo &ri) m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); //if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); //} @@ -277,7 +277,7 @@ QWidget *DirSearchPlugin::detailPage(const ResultInfo &ri) m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); //if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); //} @@ -452,7 +452,7 @@ QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri) m_pluginLabel->setText(tr("File")); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); //if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); //} @@ -484,7 +484,7 @@ QString FileContengSearchPlugin::getHtmlText(const QString &text, const QString } } htmlString.replace("\n", "
");//替换换行符 - return htmlString; + return "
" + htmlString + "
"; } QString FileContengSearchPlugin::wrapData(QLabel *p_label, const QString &text) diff --git a/libsearch/notesearch/note-search-plugin.cpp b/libsearch/notesearch/note-search-plugin.cpp index 17bf611..74ebac8 100644 --- a/libsearch/notesearch/note-search-plugin.cpp +++ b/libsearch/notesearch/note-search-plugin.cpp @@ -64,7 +64,7 @@ QWidget *NoteSearchPlugin::detailPage(const SearchPluginIface::ResultInfo &ri) m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); } diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index ab7a3c6..012e1d3 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -70,7 +70,7 @@ QWidget *SettingsSearchPlugin::detailPage(const ResultInfo &ri) m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 - m_nameLabel->setText(QString("

%1

").arg(FileUtils::escapeHtml(showname))); + m_nameLabel->setText(FileUtils::setAllTextBold(showname)); if(QString::compare(showname, ri.name)) { m_nameLabel->setToolTip(ri.name); }