diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index a311dbc3..7ff49470 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -14,7 +14,7 @@ LanListItem::LanListItem(const KyConnectItem *lanConnectItem, connectItemCopy(lanConnectItem); m_deviceName = deviceName; - m_nameLabel->setText(m_lanConnectItem.m_connectName); + m_nameLabel->setLabelText(m_lanConnectItem.m_connectName); m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic")); qDebug() << "LanListItem init:" << m_lanConnectItem.m_connectName << m_lanConnectItem.m_connectState << m_lanConnectItem.m_ifaceName; @@ -42,7 +42,7 @@ LanListItem::LanListItem(QWidget *parent) : ListItem(parent) m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); setIcon(false); const QString str=tr("Not connected"); - m_nameLabel->setText(str); + m_nameLabel->setLabelText(str); this->m_infoButton->hide(); } @@ -207,7 +207,7 @@ QString LanListItem::getConnectionName() void LanListItem::updateConnectionName(QString connectionName) { m_lanConnectItem.m_connectName = connectionName; - m_nameLabel->setText(m_lanConnectItem.m_connectName); + m_nameLabel->setLabelText(m_lanConnectItem.m_connectName); return; } diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index 88c8d72a..2e252ccb 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -37,7 +37,7 @@ ListItem::~ListItem() void ListItem::setName(const QString &name) { - m_nameLabel->setText(name); + m_nameLabel->setLabelText(name); } //仅无线调用,有线自己获取 @@ -140,6 +140,7 @@ void ListItem::initUI() m_netButton = new RadioItemButton(m_itemFrame); m_nameLabel = new FixLabel(m_itemFrame); + m_nameLabel->setMinimumWidth(262); m_infoButton = new InfoButton(m_itemFrame); m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT)); diff --git a/src/frontend/list-items/wlanmoreitem.cpp b/src/frontend/list-items/wlanmoreitem.cpp index 7284d703..521e2f40 100644 --- a/src/frontend/list-items/wlanmoreitem.cpp +++ b/src/frontend/list-items/wlanmoreitem.cpp @@ -5,7 +5,7 @@ WlanMoreItem::WlanMoreItem(QWidget *parent) : ListItem(parent) setObjectName(WMI_OB_NAME); m_netButton->setVisible(false); m_infoButton->setVisible(false); - m_nameLabel->setText(tr("Add Others...")); + m_nameLabel->setLabelText(tr("Add Others...")); } WlanMoreItem::~WlanMoreItem() { diff --git a/src/frontend/netdetails/detailwidget.cpp b/src/frontend/netdetails/detailwidget.cpp index 0b4f4584..82a0a9e0 100644 --- a/src/frontend/netdetails/detailwidget.cpp +++ b/src/frontend/netdetails/detailwidget.cpp @@ -1,44 +1,49 @@ #include "detailwidget.h" #include #include +#include #define ITEM_HEIGHT 36 #define ITEM_MARGINS 18,0,16,0 #define MAX_LABEL_WIDTH 138 -FixLabel::FixLabel(QWidget *parent): +FixLabel::FixLabel(QWidget *parent) : QLabel(parent) { - + const QByteArray id("org.ukui.style"); + QGSettings * fontSetting = new QGSettings(id, QByteArray(), this); + connect(fontSetting, &QGSettings::changed,[=](QString key) { + if ("systemFont" == key || "systemFontSize" ==key) { + changedLabelSlot(); + } + }); } -FixLabel::~FixLabel() -{ +void FixLabel::setLabelText(QString text) { + + mStr = text; + changedLabelSlot(); } -void FixLabel::paintEvent(QPaintEvent *event) -{ - QFontMetrics fontMetrics(this->font()); +QString FixLabel::getText(){ + return mStr; +} + +void FixLabel::changedLabelSlot() { + QFontMetrics fontMetrics(this->font()); int fontSize = fontMetrics.width(mStr); if (fontSize > this->width()) { - this->setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width()), false); - this->setToolTip(mStr); + setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width())); + setToolTip(mStr); } else { - this->setText(mStr, false); - this->setToolTip(""); + setText(mStr); + setToolTip(""); } - QLabel::paintEvent(event); } -void FixLabel::setText(const QString & text, bool saveTextFlag) -{ - if (saveTextFlag) { - mStr = text; - } - QLabel::setText(text); -} + DetailWidget::DetailWidget(QWidget *valueWidget, QWidget *parent, QWidget *buttonWidget) : m_valueWidget(valueWidget) , QWidget(parent) , m_copyButton(buttonWidget) diff --git a/src/frontend/netdetails/detailwidget.h b/src/frontend/netdetails/detailwidget.h index c97ac877..e2534618 100644 --- a/src/frontend/netdetails/detailwidget.h +++ b/src/frontend/netdetails/detailwidget.h @@ -5,20 +5,21 @@ #include #include -//文本长自动省略并添加悬浮 class FixLabel : public QLabel { - Q_OBJECT public: - FixLabel(QWidget *parent = nullptr); - ~FixLabel(); - void setText(const QString &text, bool saveTextFlag = true); -private: - void paintEvent(QPaintEvent *event); + explicit FixLabel(QWidget *parent = 0); +public: + void setLabelText(QString text); + QString getText(); + +private Q_SLOTS: + void changedLabelSlot(); private: QString mStr; + }; class DetailWidget : public QWidget