Add keyword bord. Remove description hint.

This commit is contained in:
zhangzihao 2021-08-26 11:22:10 +08:00
parent 1230f52be5
commit d721df0784
4 changed files with 72 additions and 5 deletions

View File

@ -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("<b><font size=\"4\">"));
}
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
} else {
if(boldOpenned) {
boldOpenned = false;
htmlString.append(QString("</font></b>"));
}
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
}
}
htmlString.replace("\n", "<br />");//替换换行符
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;
}

View File

@ -39,6 +39,7 @@
#include <QApplication>
#include <QClipboard>
#include <QFontMetrics>
#include <QLabel>
#include <quazip/quazipfile.h>
#include <stdio.h>
@ -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 &);

View File

@ -35,6 +35,7 @@ void NoteSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIfac
g_mutex.lock();
++g_uniqueSymbol;
g_mutex.unlock();
m_keyword = keyword;
NoteSearch *ns = new NoteSearch(searchResult, keyword, g_uniqueSymbol);
m_pool.start(ns);
}
@ -67,8 +68,8 @@ QWidget *NoteSearchPlugin::detailPage(const SearchPluginIface::ResultInfo &ri)
m_nameLabel->setToolTip(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,9 +191,14 @@ void NoteSearch::run() {
},
actionKey : it.first
};
if (m_uniqueSymbol ^ g_uniqueSymbol) {
qDebug() << m_uniqueSymbol << g_uniqueSymbol;
return;
} else {
m_searchResult->enqueue(ri);
}
}
}
} else {
qWarning() << "Note dbus called failed!" << qi.lastError();
}

View File

@ -66,6 +66,7 @@ private:
QVBoxLayout * m_actionLyt = nullptr;
bool m_enable = true;
QString m_keyword;
QList<NoteSearchPlugin::Actioninfo> m_actionInfo;
QThreadPool m_pool;
};
@ -78,9 +79,9 @@ public:
protected:
void run() override;
private:
QString m_keyword;
DataQueue<SearchPluginIface::ResultInfo> *m_searchResult = nullptr;
size_t m_uniqueSymbol;
QString m_keyword;
};
}