forked from openkylin/ukui-search
Modify the form of the htmlText in order to show the correct number of spacing.Modify the code format.
This commit is contained in:
parent
9c86647520
commit
0244b8f29b
|
@ -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()<<indexColString<<"---->"<<htmlString;
|
||||
return htmlString;
|
||||
return "<pre>" + htmlString + "</pre>";
|
||||
}
|
||||
|
||||
QString ResultViewDelegate::escapeHtml(const QString &str) const
|
||||
|
|
|
@ -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("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname)));
|
||||
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
||||
if(QString::compare(showname, ri.name)) {
|
||||
m_nameLabel->setToolTip(ri.name);
|
||||
}
|
||||
|
|
|
@ -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<QString> 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<QString>* tempQueue = new QQueue<QString>;
|
||||
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<QString>* tempQueue = new QQueue<QString>;
|
||||
QQueue<QString>* tempQueueFirst = new QQueue<QString>;
|
||||
|
@ -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<QString> tempQueue;
|
||||
QQueue<QString> 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", "<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)
|
||||
|
|
|
@ -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<QString, QStringList> 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;
|
||||
|
|
|
@ -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("<h3 style=\"font-weight:normal;\">%1</h3>").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("<h3 style=\"font-weight:normal;\">%1</h3>").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("<h3 style=\"font-weight:normal;\">%1</h3>").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", "<br />");//替换换行符
|
||||
return htmlString;
|
||||
return "<pre>" + htmlString + "</pre>";
|
||||
}
|
||||
|
||||
QString FileContengSearchPlugin::wrapData(QLabel *p_label, const QString &text)
|
||||
|
|
|
@ -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("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname)));
|
||||
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
||||
if(QString::compare(showname, ri.name)) {
|
||||
m_nameLabel->setToolTip(ri.name);
|
||||
}
|
||||
|
|
|
@ -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("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname)));
|
||||
m_nameLabel->setText(FileUtils::setAllTextBold(showname));
|
||||
if(QString::compare(showname, ri.name)) {
|
||||
m_nameLabel->setToolTip(ri.name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue