Merge branch '0629' into 'dbus-interface'

fixlabel

See merge request kylin-desktop/kylin-nm!648
This commit is contained in:
赵世旭 2022-07-05 06:40:38 +00:00
commit 955a38b759
5 changed files with 38 additions and 31 deletions

View File

@ -33,7 +33,7 @@ LanListItem::LanListItem(const KyConnectItem *lanConnectItem,
connectItemCopy(lanConnectItem); connectItemCopy(lanConnectItem);
m_deviceName = deviceName; 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")); m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
qDebug() << "LanListItem init:" << m_lanConnectItem.m_connectName << m_lanConnectItem.m_connectState << m_lanConnectItem.m_ifaceName; qDebug() << "LanListItem init:" << m_lanConnectItem.m_connectName << m_lanConnectItem.m_connectState << m_lanConnectItem.m_ifaceName;
@ -61,7 +61,7 @@ LanListItem::LanListItem(QWidget *parent) : ListItem(parent)
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic")); m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
setIcon(false); setIcon(false);
const QString str=tr("Not connected"); const QString str=tr("Not connected");
m_nameLabel->setText(str); m_nameLabel->setLabelText(str);
this->m_infoButton->hide(); this->m_infoButton->hide();
} }
@ -226,7 +226,7 @@ QString LanListItem::getConnectionName()
void LanListItem::updateConnectionName(QString connectionName) void LanListItem::updateConnectionName(QString connectionName)
{ {
m_lanConnectItem.m_connectName = connectionName; m_lanConnectItem.m_connectName = connectionName;
m_nameLabel->setText(m_lanConnectItem.m_connectName); m_nameLabel->setLabelText(m_lanConnectItem.m_connectName);
return; return;
} }

View File

@ -56,7 +56,7 @@ ListItem::~ListItem()
void ListItem::setName(const QString &name) void ListItem::setName(const QString &name)
{ {
m_nameLabel->setText(name); m_nameLabel->setLabelText(name);
} }
//仅无线调用,有线自己获取 //仅无线调用,有线自己获取
@ -159,6 +159,7 @@ void ListItem::initUI()
m_netButton = new RadioItemButton(m_itemFrame); m_netButton = new RadioItemButton(m_itemFrame);
m_nameLabel = new FixLabel(m_itemFrame); m_nameLabel = new FixLabel(m_itemFrame);
m_nameLabel->setMinimumWidth(262);
m_infoButton = new InfoButton(m_itemFrame); m_infoButton = new InfoButton(m_itemFrame);
m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT)); m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT));

View File

@ -24,7 +24,7 @@ WlanMoreItem::WlanMoreItem(QWidget *parent) : ListItem(parent)
setObjectName(WMI_OB_NAME); setObjectName(WMI_OB_NAME);
m_netButton->setVisible(false); m_netButton->setVisible(false);
m_infoButton->setVisible(false); m_infoButton->setVisible(false);
m_nameLabel->setText(tr("Add Others...")); m_nameLabel->setLabelText(tr("Add Others..."));
} }
WlanMoreItem::~WlanMoreItem() { WlanMoreItem::~WlanMoreItem() {

View File

@ -20,44 +20,49 @@
#include "detailwidget.h" #include "detailwidget.h"
#include <QFontMetrics> #include <QFontMetrics>
#include <QDebug> #include <QDebug>
#include <QGSettings>
#define ITEM_HEIGHT 36 #define ITEM_HEIGHT 36
#define ITEM_MARGINS 18,0,16,0 #define ITEM_MARGINS 18,0,16,0
#define MAX_LABEL_WIDTH 138 #define MAX_LABEL_WIDTH 138
FixLabel::FixLabel(QWidget *parent): FixLabel::FixLabel(QWidget *parent) :
QLabel(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) QString FixLabel::getText(){
{ return mStr;
}
void FixLabel::changedLabelSlot() {
QFontMetrics fontMetrics(this->font()); QFontMetrics fontMetrics(this->font());
int fontSize = fontMetrics.width(mStr); int fontSize = fontMetrics.width(mStr);
if (fontSize > this->width()) { if (fontSize > this->width()) {
this->setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width()), false); setText(fontMetrics.elidedText(mStr, Qt::ElideRight, this->width()));
this->setToolTip(mStr); setToolTip(mStr);
} else { } else {
this->setText(mStr, false); setText(mStr);
this->setToolTip(""); 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) DetailWidget::DetailWidget(QWidget *valueWidget, QWidget *parent, QWidget *buttonWidget)
: m_valueWidget(valueWidget) , QWidget(parent) , m_copyButton(buttonWidget) : m_valueWidget(valueWidget) , QWidget(parent) , m_copyButton(buttonWidget)

View File

@ -24,20 +24,21 @@
#include <QLabel> #include <QLabel>
#include <QHBoxLayout> #include <QHBoxLayout>
//文本长自动省略并添加悬浮
class FixLabel : public QLabel class FixLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
FixLabel(QWidget *parent = nullptr); explicit FixLabel(QWidget *parent = 0);
~FixLabel();
void setText(const QString &text, bool saveTextFlag = true);
private:
void paintEvent(QPaintEvent *event);
public:
void setLabelText(QString text);
QString getText();
private Q_SLOTS:
void changedLabelSlot();
private: private:
QString mStr; QString mStr;
}; };
class DetailWidget : public QWidget class DetailWidget : public QWidget