1 Star 0 Fork 13

刘智淋/dde-session-ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-fix.patch 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
Venland 提交于 2023-07-31 10:14 . upgrade to version 5.5.39
From 519a2ad6985fafb8b84c32c7a2005fe989d96fcc Mon Sep 17 00:00:00 2001
From: shaojun <wangshaojun@uniontech.com>
Date: Wed, 22 Feb 2023 13:42:53 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BD=E6=A0=87=E8=B6=85=E5=A4=A7?=
=?UTF-8?q?=E5=AD=97=E7=AC=A6=E9=9B=86=E6=96=87=E5=AD=97=E6=98=BE=E7=A4=BA?=
=?UTF-8?q?=E4=B8=8D=E5=85=A8=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修改字体计算高度方法
Log:
Bug: https://pms.uniontech.com/bug-view-187789.html
Influence: 通知中心和通知界面在不同字体下的布局。
Change-Id: I463948052b64becad4c623a22a043b6f72642d4c
---
dde-osd/notification/appbodylabel.cpp | 14 ++++++++++----
dde-osd/notification/appbodylabel.h | 1 +
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/dde-osd/notification/appbodylabel.cpp b/dde-osd/notification/appbodylabel.cpp
index 071b1ff4..fecbb84f 100644
--- a/dde-osd/notification/appbodylabel.cpp
+++ b/dde-osd/notification/appbodylabel.cpp
@@ -19,6 +19,10 @@ AppBodyLabel::AppBodyLabel(QWidget *parent)
, m_alignment(Qt::AlignVCenter)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ connect(qApp, &QGuiApplication::fontChanged, this, [&] {
+ m_fontHeight = fontMetrics().size(Qt::TextSingleLine, text()).height();
+ });
}
void AppBodyLabel::setText(const QString &text)
@@ -32,6 +36,8 @@ void AppBodyLabel::setText(const QString &text)
#endif
m_text = text;
+ m_fontHeight = fontMetrics().size(Qt::TextSingleLine, text).height();
+
updateLineCount();
update();
}
@@ -96,12 +102,12 @@ static int drawText(QPainter *painter, const QRectF &rect, int lineHeight, QText
QSize AppBodyLabel::sizeHint() const
{
- return QSize(width(), fontMetrics().height() * m_lineCount);
+ return QSize(width(), m_fontHeight * m_lineCount);
}
QSize AppBodyLabel::minimumSizeHint() const
{
- QSize size(width(), fontMetrics().height());
+ QSize size(width(), m_fontHeight);
return size;
}
@@ -162,7 +168,7 @@ void AppBodyLabel::paintEvent(QPaintEvent *event)
layout.setTextOption(option);
QRect rect(this->rect());
- int lineHeight = fontMetrics().height();
+ int lineHeight = m_fontHeight;
int lineCount = m_lineCount;
while (lineCount > 1 && lineCount * lineHeight > height()) {
@@ -185,5 +191,5 @@ void AppBodyLabel::updateLineCount()
layout.setTextOption(option);
- m_lineCount = drawText(nullptr, QRectF(QPointF(0, 0), QSizeF(width(), INT_MAX)), fontMetrics().height(), &layout, Qt::ElideNone);
+ m_lineCount = drawText(nullptr, QRectF(QPointF(0, 0), QSizeF(width(), INT_MAX)), m_fontHeight, &layout, Qt::ElideNone);
}
diff --git a/dde-osd/notification/appbodylabel.h b/dde-osd/notification/appbodylabel.h
index e05ea9b8..991bc136 100644
--- a/dde-osd/notification/appbodylabel.h
+++ b/dde-osd/notification/appbodylabel.h
@@ -42,6 +42,7 @@ private:
QString m_text;
int m_lineCount = 0;
Qt::Alignment m_alignment;
+ int m_fontHeight = 0;
};
#endif // APPBODYLABEL_H
--
2.20.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lliuzhi/dde-session-ui.git
git@gitee.com:lliuzhi/dde-session-ui.git
lliuzhi
dde-session-ui
dde-session-ui
master

搜索帮助