Merge branch 'new-frontend' into 'new-frontend'

Fix detail page content display bug;

See merge request kylin-desktop/ukui-search!148
This commit is contained in:
PengfeiZhang 2021-09-23 12:52:14 +00:00
commit 9b34938b9b
2 changed files with 33 additions and 20 deletions

View File

@ -842,33 +842,47 @@ QString FileUtils::chineseSubString(const std::string &myStr, int start, int len
if(start < 0 || length < 0){
return " ";
}
if (length >= myStr.length()) {
return QString::fromStdString(myStr);
}
QString sub = "";
QString sub = QString::fromStdString(myStr);
QFont ft(QApplication::font().family(),QApplication::font().pointSize());
QFontMetrics fm (ft);
if (length >= myStr.length()) {
afterSub = myStr.substr(start,length); //截取;
if (fm.width(QString::fromStdString(afterSub)) >= 2*LABEL_MAX_WIDTH) {
sub = fm.elidedText(sub, Qt::ElideRight, 2*LABEL_MAX_WIDTH); //超过两行则省略
} else {
sub = fm.elidedText(sub, Qt::ElideLeft, 2*LABEL_MAX_WIDTH); //超过两行则省略
}
return sub;
}
if (start + length <= myStr.length()) {
afterSub = myStr.substr(start,length); //截取
sub = QString::fromStdString(afterSub); //转QString
if(start + length < myStr.length()){
sub.replace(sub.length()-3,3,"..."); //替换后三位
}
else{
sub.append("..."); //直接加
sub.replace(sub.length()-3,3,""); //替换后三位
} else{
sub.append(""); //直接加
}
sub = fm.elidedText(sub, Qt::ElideRight, 2*LABEL_MAX_WIDTH); //超过两行则省略
}
else {
} else {
int newStart = myStr.length()-length; //更新截取位置
afterSub = myStr.substr(newStart, length);
sub=QString::fromStdString(afterSub);
sub.replace(0,3,"...").append("...");
sub = fm.elidedText(sub, Qt::ElideLeft, 2*LABEL_MAX_WIDTH);
if (fm.width(QString::fromStdString(myStr.substr(newStart, start))) >= 2*LABEL_MAX_WIDTH) {
sub = fm.elidedText(sub, Qt::ElideLeft, 2*LABEL_MAX_WIDTH);
} else {
if (newStart + 3 < start) {
sub.replace(0,3,"").append("");
} else {
afterSub = myStr.substr(start, length);
sub = "" + QString::fromStdString(afterSub);
sub.append("");
}
sub = fm.elidedText(sub, Qt::ElideRight, 2*LABEL_MAX_WIDTH);
}
}
return sub;
}

View File

@ -87,9 +87,9 @@ QWidget *FileSearchPlugin::detailPage(const ResultInfo &ri)
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
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)));
if(QString::compare(showname, ri.name)) {
//if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(ri.name);
}
//}
m_pluginLabel->setText(tr("File"));
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
@ -284,9 +284,9 @@ QWidget *DirSearchPlugin::detailPage(const ResultInfo &ri)
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
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)));
if(QString::compare(showname, ri.name)) {
//if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(ri.name);
}
//}
m_pluginLabel->setText(tr("directory"));
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
@ -465,9 +465,9 @@ QWidget *FileContengSearchPlugin::detailPage(const ResultInfo &ri)
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
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)));
if(QString::compare(showname, ri.name)) {
//if(QString::compare(showname, ri.name)) {
m_nameLabel->setToolTip(ri.name);
}
//}
m_snippetLabel->setText(getHtmlText(wrapData(m_snippetLabel,ri.description.at(0).value), m_keyWord));
m_pathLabel2->setText(m_pathLabel2->fontMetrics().elidedText(m_currentActionKey, Qt::ElideRight, m_pathLabel2->width()));
@ -505,7 +505,6 @@ QString FileContengSearchPlugin::wrapData(QLabel *p_label, const QString &text)
QFontMetrics fontMetrics = p_label->fontMetrics();
int textSize = fontMetrics.width(wrapText);
if(textSize > LABEL_MAX_WIDTH){
int lastIndex = 0;
int count = 0;