Merge pull request #115 from mammonsama666/0129-dev
fix(frontend): Escape rice text & recalculate position for mainwindow.
This commit is contained in:
commit
77d60cfc3f
|
@ -69,7 +69,7 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
|
||||||
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字体中的位置
|
||||||
// paintKeywordHighlight(painter, itemOption, indexColString, indexFindLeft, m_regFindKeyWords.length());
|
// 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 {
|
} else {
|
||||||
bool boldOpenned = false;
|
bool boldOpenned = false;
|
||||||
for (int i = 0; i < indexColString.length(); i++) {
|
for (int i = 0; i < indexColString.length(); i++) {
|
||||||
|
@ -79,13 +79,13 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption
|
||||||
boldOpenned = true;
|
boldOpenned = true;
|
||||||
htmlString.append(QString("<b>"));
|
htmlString.append(QString("<b>"));
|
||||||
}
|
}
|
||||||
htmlString.append(QString(indexColString.at(i)));
|
htmlString.append(escapeHtml(QString(indexColString.at(i))));
|
||||||
} else {
|
} else {
|
||||||
if (boldOpenned) {
|
if (boldOpenned) {
|
||||||
boldOpenned = false;
|
boldOpenned = false;
|
||||||
htmlString.append(QString("</b>"));
|
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;
|
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方法绘制文字,印加粗字体与原字体不等宽导致像素不对齐,视觉效果较差,已暂时摒弃,保留以做底色高亮等备用
|
* @brief HighlightItemDelegate::paintKeywordHighlight drawitemtext方法绘制文字,印加粗字体与原字体不等宽导致像素不对齐,视觉效果较差,已暂时摒弃,保留以做底色高亮等备用
|
||||||
* @param painter
|
* @param painter
|
||||||
|
|
|
@ -13,6 +13,7 @@ private:
|
||||||
QString m_regFindKeyWords = 0;
|
QString m_regFindKeyWords = 0;
|
||||||
void paint(QPainter *,const QStyleOptionViewItem &, const QModelIndex &) const override;
|
void paint(QPainter *,const QStyleOptionViewItem &, const QModelIndex &) const override;
|
||||||
QString getHtmlText(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
|
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;
|
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;
|
boldOpenned = true;
|
||||||
htmlString.append(QString("<b><font size=\"4\">"));
|
htmlString.append(QString("<b><font size=\"4\">"));
|
||||||
}
|
}
|
||||||
htmlString.append(QString(text.at(i)));
|
htmlString.append(escapeHtml(QString(text.at(i))));
|
||||||
} else {
|
} else {
|
||||||
if (boldOpenned) {
|
if (boldOpenned) {
|
||||||
boldOpenned = false;
|
boldOpenned = false;
|
||||||
htmlString.append(QString("</font></b>"));
|
htmlString.append(QString("</font></b>"));
|
||||||
}
|
}
|
||||||
htmlString.append(QString(text.at(i)));
|
htmlString.append(escapeHtml(QString(text.at(i))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
htmlString.replace("\n", "<br />");//替换换行符
|
htmlString.replace("\n", "<br />");//替换换行符
|
||||||
return htmlString;
|
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 构建右侧搜索结果详情区域
|
* @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域
|
||||||
* @param type 搜索类型
|
* @param type 搜索类型
|
||||||
|
|
|
@ -30,6 +30,7 @@ private:
|
||||||
bool openPathAction(const QString&);
|
bool openPathAction(const QString&);
|
||||||
bool copyPathAction(const QString&);
|
bool copyPathAction(const QString&);
|
||||||
QString getHtmlText(const QString&, const QString&);
|
QString getHtmlText(const QString&, const QString&);
|
||||||
|
QString escapeHtml(const QString&);
|
||||||
bool writeConfigFile(const QString&);
|
bool writeConfigFile(const QString&);
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
int m_type = 0;
|
int m_type = 0;
|
||||||
|
|
|
@ -178,7 +178,7 @@ SearchLineEdit::SearchLineEdit()
|
||||||
{
|
{
|
||||||
this->setFocusPolicy(Qt::ClickFocus);
|
this->setFocusPolicy(Qt::ClickFocus);
|
||||||
this->installEventFilter(this);
|
this->installEventFilter(this);
|
||||||
this->setContextMenuPolicy(Qt::NoContextMenu);
|
// this->setContextMenuPolicy(Qt::NoContextMenu);
|
||||||
this->setMaxLength(100);
|
this->setMaxLength(100);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QtSingleApplication>
|
|
||||||
#include <QtX11Extras/QX11Info>
|
#include <QtX11Extras/QX11Info>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
@ -29,6 +28,7 @@
|
||||||
#include <KWindowEffects>
|
#include <KWindowEffects>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include "kwindowsystem.h"
|
#include "kwindowsystem.h"
|
||||||
|
#include "qt-single-application.h"
|
||||||
|
|
||||||
//#include "inotify-manager.h"
|
//#include "inotify-manager.h"
|
||||||
#include "settings-widget.h"
|
#include "settings-widget.h"
|
||||||
|
@ -328,43 +328,25 @@ void MainWindow::moveToPanel()
|
||||||
int height = QDBusReply<int>(interface.call("GetPanelPosition", "height"));
|
int height = QDBusReply<int>(interface.call("GetPanelPosition", "height"));
|
||||||
int d = 2; //窗口边沿到任务栏距离
|
int d = 2; //窗口边沿到任务栏距离
|
||||||
|
|
||||||
if (screenGeometry.width() == availableGeometry.width() && screenGeometry.height() == availableGeometry.height()) {
|
if (position == 0) {
|
||||||
if (position == 0) {
|
//任务栏在下侧
|
||||||
//任务栏在下侧
|
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - height - d);
|
||||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - height - d);
|
} else if(position == 1) {
|
||||||
} else if(position == 1) {
|
//任务栏在上侧
|
||||||
//任务栏在上侧
|
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + height + d);
|
||||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + screenGeometry.height() - availableGeometry.height() + height + d);
|
} else if (position == 2) {
|
||||||
} else if (position == 2) {
|
//任务栏在左侧
|
||||||
//任务栏在左侧
|
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||||
if (screenGeometry.x() == 0) {//主屏在左侧
|
this->move(height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||||
this->move(height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
} else {//主屏在右侧
|
||||||
} else {//主屏在右侧
|
this->move(screenMainRect.x() + height + d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if(screenGeometry.width() == availableGeometry.width() ) {
|
} else if (position == 3) {
|
||||||
if (m_sys_tray_icon->geometry().y() > availableGeometry.height()/2) {
|
//任务栏在右侧
|
||||||
//任务栏在下侧
|
if (screenGeometry.x() == 0) {//主屏在左侧
|
||||||
this->move(availableGeometry.x() + availableGeometry.width() - this->width(), screenMainRect.y() + availableGeometry.height() - this->height() - d);
|
this->move(screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||||
} else {
|
} else {//主屏在右侧
|
||||||
//任务栏在上侧
|
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - height - d, screenMainRect.y() + screenMainRect.height() - this->height());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue