Merge pull request #115 from mammonsama666/0129-dev

fix(frontend): Escape rice text & recalculate position for mainwindow.
This commit is contained in:
iaom 2021-01-29 10:47:46 +08:00 committed by GitHub
commit 77d60cfc3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 43 deletions

View File

@ -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("<", "&lt;");
temp.replace(">", "&gt;");
return temp;
}
/**
* @brief HighlightItemDelegate::paintKeywordHighlight drawitemtext方法绘制文字
* @param painter

View File

@ -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;
};

View File

@ -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("<", "&lt;");
temp.replace(">", "&gt;");
return temp;
}
/**
* @brief SearchDetailView::setupWidget
* @param type

View File

@ -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;

View File

@ -178,7 +178,7 @@ SearchLineEdit::SearchLineEdit()
{
this->setFocusPolicy(Qt::ClickFocus);
this->installEventFilter(this);
this->setContextMenuPolicy(Qt::NoContextMenu);
// this->setContextMenuPolicy(Qt::NoContextMenu);
this->setMaxLength(100);

View File

@ -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,7 +328,6 @@ 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);
@ -350,23 +349,6 @@ void MainWindow::moveToPanel()
this->move(screenMainRect.x() + screenMainRect.width() - this->width() - 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());
}
}
}
//使用GSetting获取当前窗口应该使用的透明度