mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00

bug24279 【TR4】【桌面专业版】【SP1】【华为】【Kunpeng920】【uos-20-pangu-daliy-20200505-build48】【任务栏-蓝牙】任务栏蓝牙tooltips显示异常,功能无法使用 (cherry picked from commit 882ad1ee7704dfc824019a391a3d35efd49e0e23) # Conflicts: # translations/dde-dock.ts # widgets/tipswidget.cpp # widgets/tipswidget.h
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include "tipswidget.h"
|
|
|
|
#include <QPainter>
|
|
|
|
TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent)
|
|
{
|
|
|
|
}
|
|
|
|
void TipsWidget::setText(const QString &text)
|
|
{
|
|
m_text = text;
|
|
|
|
setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
|
|
|
|
update();
|
|
}
|
|
|
|
void TipsWidget::setTextList(const QStringList &textList)
|
|
{
|
|
m_textList = textList;
|
|
|
|
int maxLength = 0;
|
|
int k = fontMetrics().height() * m_textList.size();
|
|
setFixedHeight(k);
|
|
for (QString text : m_textList) {
|
|
int fontLength = fontMetrics().width(text) + 6;
|
|
maxLength = maxLength > fontLength ? maxLength : fontLength;
|
|
}
|
|
m_width = maxLength;
|
|
setFixedWidth(maxLength);
|
|
|
|
update();
|
|
}
|
|
|
|
void TipsWidget::paintEvent(QPaintEvent *event)
|
|
{
|
|
QFrame::paintEvent(event);
|
|
|
|
QPainter painter(this);
|
|
painter.setPen(QPen(palette().brightText(), 1));
|
|
QTextOption option;
|
|
int fontHeight = fontMetrics().height();
|
|
option.setAlignment(Qt::AlignCenter);
|
|
|
|
if (!m_text.isEmpty() && m_textList.isEmpty()) {
|
|
painter.drawText(rect(), m_text, option);
|
|
}
|
|
|
|
int y = 0;
|
|
if (m_text.isEmpty() && !m_textList.isEmpty()) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|