Modify the form of the htmlText in order to show the correct number of spacing.Modify the code format.

This commit is contained in:
baijunjie 2021-12-17 17:39:37 +08:00 committed by iaom
parent 9c86647520
commit 0244b8f29b
7 changed files with 39 additions and 33 deletions

View File

@ -54,7 +54,7 @@ QString ResultViewDelegate::getHtmlText(QPainter *painter, const QStyleOptionVie
QString indexString = index.model()->data(index, Qt::DisplayRole).toString(); QString indexString = index.model()->data(index, Qt::DisplayRole).toString();
QFont ft(painter->font().family(), GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toInt()); QFont ft(painter->font().family(), GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toInt());
QFontMetrics fm(ft); 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; QString htmlString;
if((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) { if((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) {
indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置 indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置
@ -79,7 +79,7 @@ QString ResultViewDelegate::getHtmlText(QPainter *painter, const QStyleOptionVie
} }
} }
// qDebug()<<indexColString<<"---->"<<htmlString; // qDebug()<<indexColString<<"---->"<<htmlString;
return htmlString; return "<pre>" + htmlString + "</pre>";
} }
QString ResultViewDelegate::escapeHtml(const QString &str) const QString ResultViewDelegate::escapeHtml(const QString &str) const

View File

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

View File

@ -107,7 +107,7 @@ QIcon FileUtils::getAppIcon(const QString &path) {
* @param is_white * @param is_white
* @return * @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("/")); QString name = setting.left(setting.indexOf("/"));
if(! name.isEmpty()) { if(! name.isEmpty()) {
name.replace(QString(name.at(0)), QString(name.at(0).toUpper())); 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" * @param uri "file:///home/xxx/xxx/xxxx.txt"
* @return * @return
*/ */
QString FileUtils::getFileName(const QString& uri) { QString FileUtils::getFileName(const QString &uri) {
QFileInfo info(uri); QFileInfo info(uri);
if(info.exists()) { if(info.exists()) {
return info.fileName(); return info.fileName();
@ -159,7 +159,7 @@ QString FileUtils::getFileName(const QString& uri) {
* @param path .destop文件的完整路径 * @param path .destop文件的完整路径
* @return * @return
*/ */
QString FileUtils::getAppName(const QString& path) { QString FileUtils::getAppName(const QString &path) {
QByteArray ba; QByteArray ba;
ba = path.toUtf8(); ba = path.toUtf8();
GKeyFile * keyfile; GKeyFile * keyfile;
@ -178,7 +178,7 @@ QString FileUtils::getAppName(const QString& path) {
* @param setting About/About->Properties * @param setting About/About->Properties
* @return * @return
*/ */
QString FileUtils::getSettingName(const QString& setting) { QString FileUtils::getSettingName(const QString &setting) {
return setting.right(setting.length() - setting.lastIndexOf("/") - 1); return setting.right(setting.length() - setting.lastIndexOf("/") - 1);
} }
@ -242,7 +242,7 @@ QString FileUtils::find(const QString &hanzi) {
} }
//DFS多音字太多直接GG //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) { if(hanzi.size() == 0) {
resultList.append(resultAllPinYin); resultList.append(resultAllPinYin);
resultList.append(resultFirst); resultList.append(resultFirst);
@ -258,7 +258,7 @@ void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYi
} }
//BFS+Stack多音字太多会爆栈 //BFS+Stack多音字太多会爆栈
void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList) { void stitchMultiToneWordsBFSStack(const QString &hanzi, QStringList &resultList) {
QString tempHanzi, resultAllPinYin, resultFirst; QString tempHanzi, resultAllPinYin, resultFirst;
QQueue<QString> tempQueue; QQueue<QString> tempQueue;
tempHanzi = hanzi; tempHanzi = hanzi;
@ -293,7 +293,7 @@ void stitchMultiToneWordsBFSStack(const QString& hanzi, QStringList& resultList)
} }
} }
//BFS+Heap多音字太多会耗尽内存 //BFS+Heap多音字太多会耗尽内存
void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList) { void stitchMultiToneWordsBFSHeap(const QString &hanzi, QStringList &resultList) {
QString tempHanzi, resultAllPinYin, resultFirst; QString tempHanzi, resultAllPinYin, resultFirst;
QQueue<QString>* tempQueue = new QQueue<QString>; QQueue<QString>* tempQueue = new QQueue<QString>;
tempHanzi = hanzi; tempHanzi = hanzi;
@ -331,7 +331,7 @@ void stitchMultiToneWordsBFSHeap(const QString& hanzi, QStringList& resultList)
} }
//BFS+Heap+超过3个多音字只建一个索引比较折中的方案 //BFS+Heap+超过3个多音字只建一个索引比较折中的方案
void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultList) { void stitchMultiToneWordsBFSHeapLess3(const QString &hanzi, QStringList &resultList) {
QString tempHanzi, resultAllPinYin, resultFirst; QString tempHanzi, resultAllPinYin, resultFirst;
QQueue<QString>* tempQueue = new QQueue<QString>; QQueue<QString>* tempQueue = new QQueue<QString>;
QQueue<QString>* tempQueueFirst = new QQueue<QString>; QQueue<QString>* tempQueueFirst = new QQueue<QString>;
@ -404,7 +404,7 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL
} }
//BFS+Stack+超过3个多音字只建一个索引比较折中的方案 //BFS+Stack+超过3个多音字只建一个索引比较折中的方案
void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& resultList) { void stitchMultiToneWordsBFSStackLess3(const QString &hanzi, QStringList &resultList) {
QString tempHanzi, resultAllPinYin, resultFirst; QString tempHanzi, resultAllPinYin, resultFirst;
QQueue<QString> tempQueue; QQueue<QString> tempQueue;
QQueue<QString> tempQueueFirst; QQueue<QString> tempQueueFirst;
@ -476,7 +476,7 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result
return; return;
} }
QStringList FileUtils::findMultiToneWords(const QString& hanzi) { QStringList FileUtils::findMultiToneWords(const QString &hanzi) {
// QStringList* output = new QStringList(); // QStringList* output = new QStringList();
QStringList output; QStringList output;
QString tempAllPinYin, tempFirst; QString tempAllPinYin, tempFirst;
@ -983,7 +983,12 @@ QString FileUtils::getHtmlText(const QString &text, const QString &keyword)
} }
} }
htmlString.replace("\n", "<br />");//替换换行符 htmlString.replace("\n", "<br />");//替换换行符
return htmlString; return "<pre>" + htmlString + "</pre>";
}
QString FileUtils::setAllTextBold(const QString &name)
{
return QString("<h3 style=\"font-weight:normal;\"><pre>%1</pre></h3>").arg(escapeHtml(name));
} }
QString FileUtils::wrapData(QLabel *p_label, const QString &text) QString FileUtils::wrapData(QLabel *p_label, const QString &text)

View File

@ -62,25 +62,26 @@
namespace UkuiSearch { namespace UkuiSearch {
class LIBSEARCH_EXPORT FileUtils { class LIBSEARCH_EXPORT FileUtils {
public: 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 QString wrapData(QLabel *p_label, const QString &text);
static std::string makeDocUterm(QString); static std::string makeDocUterm(QString path);
static QIcon getFileIcon(const QString &, bool checkValid = true); static QIcon getFileIcon(const QString &uri, bool checkValid = true);
static QIcon getAppIcon(const QString &); static QIcon getAppIcon(const QString &path);
static QIcon getSettingIcon(const QString &, const bool&); static QIcon getSettingIcon(const QString &setting, const bool is_white);
static QIcon getSettingIcon(); static QIcon getSettingIcon();
static QString getFileName(const QString &); static QString getFileName(const QString &uri);
static QString getAppName(const QString &); static QString getAppName(const QString &path);
static QString getSettingName(const QString &); static QString getSettingName(const QString &setting);
//A is or under B //A is or under B
static bool isOrUnder(QString pathA, QString pathB); static bool isOrUnder(QString pathA, QString pathB);
//chinese character to pinyin //chinese character to pinyin
static QMap<QString, QStringList> map_chinese2pinyin; static QMap<QString, QStringList> map_chinese2pinyin;
static QString find(const QString&); static QString find(const QString &hanzi);
static QStringList findMultiToneWords(const QString&); static QStringList findMultiToneWords(const QString &hanzi);
static void loadHanziTable(const QString&); static void loadHanziTable(const QString &fileName);
//parse text,docx..... //parse text,docx.....
static QMimeType getMimetype(QString &path); static QMimeType getMimetype(QString &path);
@ -92,9 +93,9 @@ public:
static int openFile(QString &path, bool openInDir = false); static int openFile(QString &path, bool openInDir = false);
static bool copyPath(QString &path); 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 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 isOpenXMLFileEncrypted(QString &path);
static bool isEncrypedOrUnreadable(QString path); static bool isEncrypedOrUnreadable(QString path);
static size_t _max_index_count; static size_t _max_index_count;

View File

@ -86,7 +86,7 @@ QWidget *FileSearchPlugin::detailPage(const ResultInfo &ri)
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120)); m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname))); m_nameLabel->setText(FileUtils::setAllTextBold(showname));
//if(QString::compare(showname, ri.name)) { //if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(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)); m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname))); m_nameLabel->setText(FileUtils::setAllTextBold(showname));
//if(QString::compare(showname, ri.name)) { //if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(ri.name); m_nameLabel->setToolTip(ri.name);
//} //}
@ -452,7 +452,7 @@ QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri)
m_pluginLabel->setText(tr("File")); m_pluginLabel->setText(tr("File"));
QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname))); m_nameLabel->setText(FileUtils::setAllTextBold(showname));
//if(QString::compare(showname, ri.name)) { //if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(ri.name); m_nameLabel->setToolTip(ri.name);
//} //}
@ -484,7 +484,7 @@ QString FileContengSearchPlugin::getHtmlText(const QString &text, const QString
} }
} }
htmlString.replace("\n", "<br />");//替换换行符 htmlString.replace("\n", "<br />");//替换换行符
return htmlString; return "<pre>" + htmlString + "</pre>";
} }
QString FileContengSearchPlugin::wrapData(QLabel *p_label, const QString &text) QString FileContengSearchPlugin::wrapData(QLabel *p_label, const QString &text)

View File

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

View File

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