Merge branch '0908dev' into 'dev-unity'

Fix: incomplete file name display;the contents of some files are not fully displayed.
This commit is contained in:
baijunjie 2021-09-13 20:43:30 +08:00
parent bc877ce406
commit 70d7135e54
4 changed files with 40 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#define COMMON_H #define COMMON_H
#include <QMap> #include <QMap>
#define UKUI_SEARCH_PIPE_PATH (QDir::homePath()+"/.config/org.ukui/ukui-search/ukuisearch").toLocal8Bit().constData() #define UKUI_SEARCH_PIPE_PATH (QDir::homePath()+"/.config/org.ukui/ukui-search/ukuisearch").toLocal8Bit().constData()
#define LABEL_MAX_WIDTH 320
#define HOME_PATH QDir::homePath() #define HOME_PATH QDir::homePath()
static const QMap<QString, bool> targetFileTypeMap = { static const QMap<QString, bool> targetFileTypeMap = {
std::map<QString, bool>::value_type("doc", true), std::map<QString, bool>::value_type("doc", true),

View File

@ -839,3 +839,32 @@ QString FileUtils::chineseSubString(const std::string &data, int start, int leng
} }
return snippet; return snippet;
} }
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;
}
}
}
return wrapText;
}

View File

@ -37,6 +37,7 @@
#include <QQueue> #include <QQueue>
#include <QApplication> #include <QApplication>
#include <QFontMetrics> #include <QFontMetrics>
#include <QLabel>
#include <quazip/quazipfile.h> #include <quazip/quazipfile.h>
#include <stdio.h> #include <stdio.h>
@ -49,6 +50,7 @@
#include <uchardet/uchardet.h> #include <uchardet/uchardet.h>
//#include <poppler-qt5.h> //#include <poppler-qt5.h>
#include <poppler/qt5/poppler-qt5.h> #include <poppler/qt5/poppler-qt5.h>
#include <common.h>
#include "libsearch_global.h" #include "libsearch_global.h"
#include "gobject-template.h" #include "gobject-template.h"
@ -86,6 +88,7 @@ public:
static void getPdfTextContent(QString &path, QString &textcontent); static void getPdfTextContent(QString &path, QString &textcontent);
static void getTxtContent(QString &path, QString &textcontent); static void getTxtContent(QString &path, QString &textcontent);
static QString chineseSubString(const std::string &data, int start, int length); static QString chineseSubString(const std::string &data, int start, int length);
static QString wrapData(QLabel *p_label, const QString &text);
static size_t _max_index_count; static size_t _max_index_count;
static size_t _current_index_count; //this one has been Abandoned,do not use it. static size_t _current_index_count; //this one has been Abandoned,do not use it.
static unsigned short _index_status; static unsigned short _index_status;

View File

@ -206,6 +206,7 @@ void SearchDetailView::setAppWidget(const QString &appname, const QString &path,
if(description != "" && !description.isEmpty()) { if(description != "" && !description.isEmpty()) {
m_detailFrame->show(); m_detailFrame->show();
m_contentLabel->show(); m_contentLabel->show();
m_contentLabel->setWordWrap(true);
m_contentLabel->setText(QString(tr("Introduction: %1")).arg(description)); m_contentLabel->setText(QString(tr("Introduction: %1")).arg(description));
} }
setIcon(iconpath, false); setIcon(iconpath, false);
@ -216,7 +217,7 @@ void SearchDetailView::setAppWidget(const QString &appname, const QString &path,
m_optionView->show(); m_optionView->show();
QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString showname = fontMetrics.elidedText(m_name, Qt::ElideRight, 274); //当字体长度超过215时显示为省略号 QString showname = fontMetrics.elidedText(m_name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
// m_nameLabel->setText(showname); // m_nameLabel->setText(showname);
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(escapeHtml(showname))); m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(escapeHtml(showname)));
if(QString::compare(showname, m_name)) { if(QString::compare(showname, m_name)) {
@ -257,7 +258,7 @@ QString SearchDetailView::getHtmlText(const QString & text, const QString & keyw
if((keyword.toUpper()).contains(QString(text.at(i)).toUpper())) { if((keyword.toUpper()).contains(QString(text.at(i)).toUpper())) {
if(! boldOpenned) { if(! boldOpenned) {
boldOpenned = true; boldOpenned = true;
htmlString.append(QString("<b><font size=\"4\">")); htmlString.append(QString("<b><font size=\"3\">"));
} }
htmlString.append(escapeHtml(QString(text.at(i)))); htmlString.append(escapeHtml(QString(text.at(i))));
} else { } else {
@ -306,7 +307,8 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
m_detailFrame->show(); m_detailFrame->show();
if(isContent) { //文件内容区域 if(isContent) { //文件内容区域
m_contentLabel->show(); m_contentLabel->show();
m_contentLabel->setText(QApplication::translate("", getHtmlText(m_contentText, m_keyword).toLocal8Bit(), nullptr)); m_contentLabel->setWordWrap(false);
m_contentLabel->setText(QApplication::translate("", getHtmlText(FileUtils::wrapData(m_contentLabel,m_contentText), m_keyword).toLocal8Bit(),nullptr));
} }
m_pathFrame->show(); m_pathFrame->show();
m_timeFrame->show(); m_timeFrame->show();
@ -351,7 +353,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
setIcon(path); setIcon(path);
QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString wholeName = FileUtils::getFileName(path); QString wholeName = FileUtils::getFileName(path);
QString name = fontMetrics.elidedText(wholeName, Qt::ElideRight, 274); QString name = fontMetrics.elidedText(wholeName, Qt::ElideRight, 215);
// m_nameLabel->setText(name); // m_nameLabel->setText(name);
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(escapeHtml(name))); m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(escapeHtml(name)));
if(QString::compare(name, wholeName)) { if(QString::compare(name, wholeName)) {
@ -514,8 +516,7 @@ void SearchDetailView::initUI() {
//文件内容区域 //文件内容区域
m_contentLabel = new QLabel(m_detailFrame); m_contentLabel = new QLabel(m_detailFrame);
m_contentLabel->setWordWrap(true); m_contentLabel->setContentsMargins(0, 0, 0, 0);
m_contentLabel->setContentsMargins(9, 0, 9, 0);
m_detailLyt->addWidget(m_contentLabel); m_detailLyt->addWidget(m_contentLabel);
//路径与修改时间区域 //路径与修改时间区域