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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
e->ignore();
|
||||
|
@ -136,7 +136,6 @@ public slots:
|
||||
|
||||
private:
|
||||
using QWidget::show;
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void enterEvent(QEvent *e) override;
|
||||
|
@ -3,13 +3,12 @@
|
||||
#include <QPainter>
|
||||
#include <QAccessible>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace Dock{
|
||||
TipsWidget::TipsWidget(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, m_width(0)
|
||||
, m_type(SingleLine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TipsWidget::setText(const QString &text)
|
||||
@ -21,7 +20,13 @@ void TipsWidget::setText(const QString &text)
|
||||
// 同时去掉两边的空白信息,例如qBittorrent的提示
|
||||
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();
|
||||
|
||||
@ -38,15 +43,14 @@ void TipsWidget::setTextList(const QStringList &textList)
|
||||
m_type = TipsWidget::MultiLine;
|
||||
m_textList = textList;
|
||||
|
||||
int maxLength = 0;
|
||||
int k = fontMetrics().height() * m_textList.size();
|
||||
setFixedHeight(k);
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
for (QString text : m_textList) {
|
||||
int fontLength = fontMetrics().width(text) + 20;
|
||||
maxLength = maxLength > fontLength ? maxLength : fontLength;
|
||||
width = qMax(width, fontMetrics().width(text) + 20);
|
||||
height += fontMetrics().boundingRect(text).height();
|
||||
}
|
||||
m_width = maxLength;
|
||||
setFixedWidth(maxLength);
|
||||
|
||||
setFixedSize(width, height);
|
||||
|
||||
update();
|
||||
}
|
||||
@ -57,13 +61,9 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setPen(QPen(palette().brightText(), 1));
|
||||
QTextOption option;
|
||||
int fontHeight = fontMetrics().height();
|
||||
option.setAlignment(Qt::AlignCenter);
|
||||
|
||||
QFont textFont;
|
||||
textFont.setPixelSize(rect().height() / 2 - 1);
|
||||
painter.setFont(textFont);
|
||||
QTextOption option;
|
||||
option.setAlignment(Qt::AlignCenter);
|
||||
|
||||
switch (m_type) {
|
||||
case SingleLine: {
|
||||
@ -75,8 +75,9 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
||||
if (m_textList.size() != 1)
|
||||
option.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
for (QString text : m_textList) {
|
||||
painter.drawText(QRect(0, y, m_width, fontHeight), text, option);
|
||||
y += fontHeight;
|
||||
int lineHeight = fontMetrics().boundingRect(text).height();
|
||||
painter.drawText(QRect(0, y, rect().width(), lineHeight), text, option);
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -86,23 +87,17 @@ void TipsWidget::paintEvent(QPaintEvent *event)
|
||||
bool TipsWidget::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::FontChange) {
|
||||
if (m_type == SingleLine) {
|
||||
if (!m_text.trimmed().isEmpty()) {
|
||||
setFixedSize(fontMetrics().width(m_text) + 6, fontMetrics().height());
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
if (m_textList.size() > 0) {
|
||||
int maxLength = 0;
|
||||
setFixedHeight(fontMetrics().height() * m_textList.size());
|
||||
for (QString text : m_textList) {
|
||||
int fontLength = fontMetrics().width(text) + 6;
|
||||
maxLength = qMax(maxLength,fontLength);
|
||||
}
|
||||
m_width = maxLength;
|
||||
setFixedWidth(maxLength);
|
||||
update();
|
||||
}
|
||||
switch (m_type) {
|
||||
case SingleLine:
|
||||
{
|
||||
setText(m_text);
|
||||
break;
|
||||
}
|
||||
case MultiLine:
|
||||
{
|
||||
setTextList(m_textList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QFrame::event(event);
|
||||
|
@ -26,7 +26,6 @@ protected:
|
||||
private:
|
||||
QString m_text;
|
||||
QStringList m_textList;
|
||||
int m_width;
|
||||
ShowType m_type;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user