fix(frontend): Escape rice text & recalculate position for mainwindow.
Description: 转义富文本并重新计算主界面位置 Log: 转义富文本并重新计算主界面位置 Bug: -
This commit is contained in:
parent
d4360c87e9
commit
825062aa75
|
@ -69,7 +69,7 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
|
|||
if ((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) {
|
||||
indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置
|
||||
// paintKeywordHighlight(painter, itemOption, indexColString, indexFindLeft, m_regFindKeyWords.length());
|
||||
htmlString = indexColString.left(indexFindLeft) + "<b>" + indexColString.mid(indexFindLeft, m_regFindKeyWords.length())+ "</b>" + indexColString.right(indexColString.length() - indexFindLeft - m_regFindKeyWords.length());
|
||||
htmlString = escapeHtml(indexColString.left(indexFindLeft)) + "<b>" + escapeHtml(indexColString.mid(indexFindLeft, m_regFindKeyWords.length())) + "</b>" + escapeHtml(indexColString.right(indexColString.length() - indexFindLeft - m_regFindKeyWords.length()));
|
||||
} else {
|
||||
bool boldOpenned = false;
|
||||
for (int i = 0; i < indexColString.length(); i++) {
|
||||
|
@ -79,13 +79,13 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
|
|||
boldOpenned = true;
|
||||
htmlString.append(QString("<b>"));
|
||||
}
|
||||
htmlString.append(QString(indexColString.at(i)));
|
||||
htmlString.append(escapeHtml(QString(indexColString.at(i))));
|
||||
} else {
|
||||
if (boldOpenned) {
|
||||
boldOpenned = false;
|
||||
htmlString.append(QString("</b>"));
|
||||
}
|
||||
htmlString.append(QString(indexColString.at(i)));
|
||||
htmlString.append(escapeHtml(QString(indexColString.at(i))));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,19 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
|
|||
return htmlString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HighlightItemDelegate::escapeHtml 将文件名原本带的尖括号转义,以防被识别为富文本
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
QString HighlightItemDelegate::escapeHtml(const QString & str) const
|
||||
{
|
||||
QString temp = str;
|
||||
temp.replace("<", "<");
|
||||
temp.replace(">", ">");
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HighlightItemDelegate::paintKeywordHighlight drawitemtext方法绘制文字,印加粗字体与原字体不等宽导致像素不对齐,视觉效果较差,已暂时摒弃,保留以做底色高亮等备用
|
||||
* @param painter
|
||||
|
|
|
@ -13,6 +13,7 @@ private:
|
|||
QString m_regFindKeyWords = 0;
|
||||
void paint(QPainter *,const QStyleOptionViewItem &, const QModelIndex &) const override;
|
||||
QString getHtmlText(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
|
||||
QString escapeHtml(const QString&) const;
|
||||
void paintKeywordHighlight(QPainter *, const QStyleOptionViewItem &, const QString &, const int &, const int &) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -97,19 +97,32 @@ QString SearchDetailView::getHtmlText(const QString & text, const QString & keyw
|
|||
boldOpenned = true;
|
||||
htmlString.append(QString("<b><font size=\"4\">"));
|
||||
}
|
||||
htmlString.append(QString(text.at(i)));
|
||||
htmlString.append(escapeHtml(QString(text.at(i))));
|
||||
} else {
|
||||
if (boldOpenned) {
|
||||
boldOpenned = false;
|
||||
htmlString.append(QString("</font></b>"));
|
||||
}
|
||||
htmlString.append(QString(text.at(i)));
|
||||
htmlString.append(escapeHtml(QString(text.at(i))));
|
||||
}
|
||||
}
|
||||
htmlString.replace("\n", "<br />");//替换换行符
|
||||
return htmlString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::escapeHtml 将搜索结果内容中的标签括号转义,来防止文件内容中的标记语言被识别为富文本
|
||||
* @param str 需要转义的字段
|
||||
* @return
|
||||
*/
|
||||
QString SearchDetailView::escapeHtml(const QString & str)
|
||||
{
|
||||
QString temp = str;
|
||||
temp.replace("<", "<");
|
||||
temp.replace(">", ">");
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域
|
||||
* @param type 搜索类型
|
||||
|
|
|
@ -30,6 +30,7 @@ private:
|
|||
bool openPathAction(const QString&);
|
||||
bool copyPathAction(const QString&);
|
||||
QString getHtmlText(const QString&, const QString&);
|
||||
QString escapeHtml(const QString&);
|
||||
bool writeConfigFile(const QString&);
|
||||
bool m_isEmpty = true;
|
||||
int m_type = 0;
|
||||
|
|
|
@ -178,7 +178,7 @@ SearchLineEdit::SearchLineEdit()
|
|||
{
|
||||
this->setFocusPolicy(Qt::ClickFocus);
|
||||
this->installEventFilter(this);
|
||||
this->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
// this->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
this->setMaxLength(100);
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include <QtSingleApplication>
|
||||
#include <QtX11Extras/QX11Info>
|
||||
#include <syslog.h>
|
||||
#include <QPalette>
|
||||
|
@ -29,6 +28,7 @@
|
|||
#include <KWindowEffects>
|
||||
#include <QPixmap>
|
||||
#include "kwindowsystem.h"
|
||||
#include "qt-single-application.h"
|
||||
|
||||
//#include "inotify-manager.h"
|
||||
#include "settings-widget.h"
|
||||
|
@ -328,43 +328,25 @@ void MainWindow::moveToPanel()
|
|||
int height = QDBusReply<int>(interface.call("GetPanelPosition", "height"));
|
||||
int d = 2; //窗口边沿到任务栏距离
|
||||
|
||||
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()) {
|
||||
if (position == 0) {
|
||||
//任务栏在下侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - height - d);
|
||||
} else if(position == 1) {
|
||||
//任务栏在上侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + height + d);
|
||||
} else if (position == 2) {
|
||||
//任务栏在左侧
|
||||
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||
this->move(height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
} else {//主屏在右侧
|
||||
this->move(screenMainRect.x() + height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
}
|
||||
} else if (position == 3) {
|
||||
//任务栏在右侧
|
||||
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||
this->move(screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
} else {//主屏在右侧
|
||||
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
}
|
||||
if (position == 0) {
|
||||
//任务栏在下侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - height - d);
|
||||
} else if(position == 1) {
|
||||
//任务栏在上侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + height + d);
|
||||
} else if (position == 2) {
|
||||
//任务栏在左侧
|
||||
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||
this->move(height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
} else {//主屏在右侧
|
||||
this->move(screenMainRect.x() + height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
}
|
||||
} else if(screenGeometry.width() == availableGeometry.width() ) {
|
||||
if (m_sys_tray_icon->geometry().y() > availableGeometry.height()/2) {
|
||||
//任务栏在下侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - d);
|
||||
} else {
|
||||
//任务栏在上侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + d);
|
||||
}
|
||||
} else if (screenGeometry.height() == availableGeometry.height()) {
|
||||
if (m_sys_tray_icon->geometry().x() > availableGeometry.width()/2) {
|
||||
//任务栏在右侧
|
||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenMainRect.y() + screenGeometry.height() - this->height());
|
||||
} else {
|
||||
//任务栏在左侧
|
||||
this->move(screenGeometry.width() - availableGeometry.width() + d, screenMainRect.y() + screenGeometry.height() - this->height());
|
||||
} else if (position == 3) {
|
||||
//任务栏在右侧
|
||||
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||
this->move(screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
} else {//主屏在右侧
|
||||
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue