mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 修复藏语环境下字体显示不全的问题
藏语字体环境下,计算得到字体高度会出现,换用QFontMetrics的boundingRect函数获取其高度即可 Log: 修复藏语环境下字体显示不全的问题 Bug: https://pms.uniontech.com/zentao/bug-view-79014.html Bug: https://pms.uniontech.com/zentao/bug-view-78763.html Change-Id: I6388b74b1d2930c98d3b4dfb5db496505234c954
This commit is contained in:
parent
d0bbfe7208
commit
8ad3d835ed
@ -199,30 +199,6 @@ void MainWindow::relaodPlugins()
|
|||||||
qApp->setProperty("PLUGINSLOADED", true);
|
qApp->setProperty("PLUGINSLOADED", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent(QShowEvent *e)
|
|
||||||
{
|
|
||||||
QWidget::showEvent(e);
|
|
||||||
|
|
||||||
// connect(qGuiApp, &QGuiApplication::primaryScreenChanged,
|
|
||||||
// windowHandle(), [this](QScreen * new_screen) {
|
|
||||||
// QScreen *old_screen = windowHandle()->screen();
|
|
||||||
// windowHandle()->setScreen(new_screen);
|
|
||||||
// // 屏幕变化后可能导致控件缩放比变化,此时应该重设控件位置大小
|
|
||||||
// // 比如:窗口大小为 100 x 100, 显示在缩放比为 1.0 的屏幕上,此时窗口的真实大小 = 100x100
|
|
||||||
// // 随后窗口被移动到了缩放比为 2.0 的屏幕上,应该将真实大小改为 200x200。另外,只能使用
|
|
||||||
// // QPlatformWindow直接设置大小来绕过QWidget和QWindow对新旧geometry的比较。
|
|
||||||
// const qreal scale = devicePixelRatioF();
|
|
||||||
// const QPoint screenPos = new_screen->geometry().topLeft();
|
|
||||||
// const QPoint posInScreen = this->pos() - old_screen->geometry().topLeft();
|
|
||||||
// const QPoint pos = screenPos + posInScreen * scale;
|
|
||||||
// const QSize size = this->size() * scale;
|
|
||||||
|
|
||||||
// windowHandle()->handle()->setGeometry(QRect(pos, size));
|
|
||||||
// }, Qt::UniqueConnection);
|
|
||||||
|
|
||||||
// windowHandle()->setScreen(qGuiApp->primaryScreen());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::mousePressEvent(QMouseEvent *e)
|
void MainWindow::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
e->ignore();
|
e->ignore();
|
||||||
|
@ -136,7 +136,6 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
using QWidget::show;
|
using QWidget::show;
|
||||||
void showEvent(QShowEvent *e) override;
|
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
void enterEvent(QEvent *e) override;
|
void enterEvent(QEvent *e) override;
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
namespace Dock{
|
namespace Dock{
|
||||||
TipsWidget::TipsWidget(QWidget *parent)
|
TipsWidget::TipsWidget(QWidget *parent)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
, m_width(0)
|
|
||||||
, m_type(SingleLine)
|
, m_type(SingleLine)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TipsWidget::setText(const QString &text)
|
void TipsWidget::setText(const QString &text)
|
||||||
@ -21,7 +20,13 @@ void TipsWidget::setText(const QString &text)
|
|||||||
// 同时去掉两边的空白信息,例如qBittorrent的提示
|
// 同时去掉两边的空白信息,例如qBittorrent的提示
|
||||||
m_text = document.toPlainText().simplified();
|
m_text = document.toPlainText().simplified();
|
||||||
|
|
||||||
setFixedSize(fontMetrics().width(m_text) + 20, fontMetrics().height());
|
#if 0 //测试时可以使用下面的语句
|
||||||
|
// FIXME:藏语字体绘制会有异常,设置高度时需要使用fontMetrics().boundingRect()去获取整体的边界矩形的高度,
|
||||||
|
// 使用fontMetrics().height()去获取时,针对藏语这种字体,其高度和实际显示区域并不等同
|
||||||
|
m_text = "བོད་སྐད་ཡིག་གཟུགས་ཚད་ལེན་ཚོད་ལྟའི་སྐོར་གྱི་རྗོད་ཚིག";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setFixedSize(fontMetrics().width(m_text) + 20, fontMetrics().boundingRect(m_text).height());
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
@ -38,15 +43,14 @@ void TipsWidget::setTextList(const QStringList &textList)
|
|||||||
m_type = TipsWidget::MultiLine;
|
m_type = TipsWidget::MultiLine;
|
||||||
m_textList = textList;
|
m_textList = textList;
|
||||||
|
|
||||||
int maxLength = 0;
|
int width = 0;
|
||||||
int k = fontMetrics().height() * m_textList.size();
|
int height = 0;
|
||||||
setFixedHeight(k);
|
|
||||||
for (QString text : m_textList) {
|
for (QString text : m_textList) {
|
||||||
int fontLength = fontMetrics().width(text) + 20;
|
width = qMax(width, fontMetrics().width(text) + 20);
|
||||||
maxLength = maxLength > fontLength ? maxLength : fontLength;
|
height += fontMetrics().boundingRect(text).height();
|
||||||
}
|
}
|
||||||
m_width = maxLength;
|
|
||||||
setFixedWidth(maxLength);
|
setFixedSize(width, height);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -57,13 +61,9 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setPen(QPen(palette().brightText(), 1));
|
painter.setPen(QPen(palette().brightText(), 1));
|
||||||
QTextOption option;
|
|
||||||
int fontHeight = fontMetrics().height();
|
|
||||||
option.setAlignment(Qt::AlignCenter);
|
|
||||||
|
|
||||||
QFont textFont;
|
QTextOption option;
|
||||||
textFont.setPixelSize(rect().height() / 2 - 1);
|
option.setAlignment(Qt::AlignCenter);
|
||||||
painter.setFont(textFont);
|
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case SingleLine: {
|
case SingleLine: {
|
||||||
@ -75,8 +75,9 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
|||||||
if (m_textList.size() != 1)
|
if (m_textList.size() != 1)
|
||||||
option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
for (QString text : m_textList) {
|
for (QString text : m_textList) {
|
||||||
painter.drawText(QRect(0, y, m_width, fontHeight), text, option);
|
int lineHeight = fontMetrics().boundingRect(text).height();
|
||||||
y += fontHeight;
|
painter.drawText(QRect(0, y, rect().width(), lineHeight), text, option);
|
||||||
|
y += lineHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -86,23 +87,17 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
|||||||
bool TipsWidget::event(QEvent *event)
|
bool TipsWidget::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::FontChange) {
|
if (event->type() == QEvent::FontChange) {
|
||||||
if (m_type == SingleLine) {
|
switch (m_type) {
|
||||||
if (!m_text.trimmed().isEmpty()) {
|
case SingleLine:
|
||||||
setFixedSize(fontMetrics().width(m_text) + 6, fontMetrics().height());
|
{
|
||||||
update();
|
setText(m_text);
|
||||||
}
|
break;
|
||||||
} else {
|
}
|
||||||
if (m_textList.size() > 0) {
|
case MultiLine:
|
||||||
int maxLength = 0;
|
{
|
||||||
setFixedHeight(fontMetrics().height() * m_textList.size());
|
setTextList(m_textList);
|
||||||
for (QString text : m_textList) {
|
break;
|
||||||
int fontLength = fontMetrics().width(text) + 6;
|
}
|
||||||
maxLength = qMax(maxLength,fontLength);
|
|
||||||
}
|
|
||||||
m_width = maxLength;
|
|
||||||
setFixedWidth(maxLength);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QFrame::event(event);
|
return QFrame::event(event);
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
const QStringList &textList() { return m_textList; }
|
const QStringList &textList() { return m_textList; }
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
void setTextList(const QStringList &textList);
|
void setTextList(const QStringList &textList);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
@ -26,7 +26,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QString m_text;
|
QString m_text;
|
||||||
QStringList m_textList;
|
QStringList m_textList;
|
||||||
int m_width;
|
|
||||||
ShowType m_type;
|
ShowType m_type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user