Merge branch '0629' into 'dbus-interface'
fixlabel See merge request kylin-desktop/kylin-nm!648
This commit is contained in:
commit
955a38b759
|
@ -33,7 +33,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;
|
||||
|
@ -61,7 +61,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();
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ ListItem::~ListItem()
|
|||
|
||||
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_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));
|
||||
|
||||
|
|
|
@ -24,7 +24,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() {
|
||||
|
|
|
@ -20,44 +20,49 @@
|
|||
#include "detailwidget.h"
|
||||
#include <QFontMetrics>
|
||||
#include <QDebug>
|
||||
#include <QGSettings>
|
||||
|
||||
#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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -24,20 +24,21 @@
|
|||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
//文本长自动省略并添加悬浮
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue