mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(bluetooth):popup and tooltips display are abnormal
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
This commit is contained in:
parent
20bb074f01
commit
1b6db122f3
@ -117,6 +117,17 @@ bool BluetoothApplet::hasAadapter()
|
|||||||
return m_adaptersManager->adaptersCount();
|
return m_adaptersManager->adaptersCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList BluetoothApplet::connectedDevsName()
|
||||||
|
{
|
||||||
|
QStringList devicesName;
|
||||||
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
|
if (adapterItem) {
|
||||||
|
devicesName << adapterItem->connectedDevsName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return devicesName;
|
||||||
|
}
|
||||||
|
|
||||||
void BluetoothApplet::onPowerChanged()
|
void BluetoothApplet::onPowerChanged()
|
||||||
{
|
{
|
||||||
bool powerState = false;
|
bool powerState = false;
|
||||||
@ -210,7 +221,7 @@ void BluetoothApplet::updateView()
|
|||||||
|
|
||||||
contentHeight += itemCount * ITEMHEIGHT;
|
contentHeight += itemCount * ITEMHEIGHT;
|
||||||
m_centralWidget->setFixedHeight(contentHeight);
|
m_centralWidget->setFixedHeight(contentHeight);
|
||||||
setFixedHeight(qMin(10,itemCount) * ITEMHEIGHT);
|
setFixedHeight(itemCount <= 10 ? contentHeight : 10 * ITEMHEIGHT);
|
||||||
setVerticalScrollBarPolicy(itemCount <= 10 ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(itemCount <= 10 ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
void setAdapterPowered(bool powered);
|
void setAdapterPowered(bool powered);
|
||||||
bool poweredInitState();
|
bool poweredInitState();
|
||||||
bool hasAadapter();
|
bool hasAadapter();
|
||||||
|
QStringList connectedDevsName();
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
void addAdapter(Adapter *adapter);
|
void addAdapter(Adapter *adapter);
|
||||||
|
@ -41,6 +41,7 @@ DGUI_USE_NAMESPACE
|
|||||||
|
|
||||||
BluetoothItem::BluetoothItem(QWidget *parent)
|
BluetoothItem::BluetoothItem(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_tipsLabel(new TipsWidget(this))
|
||||||
, m_applet(new BluetoothApplet(this))
|
, m_applet(new BluetoothApplet(this))
|
||||||
, m_timer(new QTimer(this))
|
, m_timer(new QTimer(this))
|
||||||
{
|
{
|
||||||
@ -61,9 +62,11 @@ BluetoothItem::BluetoothItem(QWidget *parent)
|
|||||||
connect(m_applet, SIGNAL(justHasAdapter()), this, SIGNAL(justHasAdapter()));
|
connect(m_applet, SIGNAL(justHasAdapter()), this, SIGNAL(justHasAdapter()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//QWidget *BluetoothItem::tipsWidget()
|
QWidget *BluetoothItem::tipsWidget()
|
||||||
//{
|
{
|
||||||
//}
|
refreshTips();
|
||||||
|
return m_tipsLabel;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *BluetoothItem::popupApplet()
|
QWidget *BluetoothItem::popupApplet()
|
||||||
{
|
{
|
||||||
@ -165,6 +168,39 @@ void BluetoothItem::refreshIcon()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BluetoothItem::refreshTips()
|
||||||
|
{
|
||||||
|
if (!m_applet)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString tipsText;
|
||||||
|
|
||||||
|
if (m_adapterPowered) {
|
||||||
|
switch (m_devState) {
|
||||||
|
case Device::StateConnected: {
|
||||||
|
QStringList textList;
|
||||||
|
for (QString devName : m_applet->connectedDevsName()) {
|
||||||
|
textList << tr("%1 connected").arg(devName);
|
||||||
|
}
|
||||||
|
m_tipsLabel->setTextList(textList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case Device::StateAvailable: {
|
||||||
|
tipsText = tr("Connecting...");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
case Device::StateUnavailable: {
|
||||||
|
tipsText = tr("Bluetooth");
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tipsText = tr("Bluetooth");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tipsLabel->setText(tipsText);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BluetoothItem::hasAdapter()
|
bool BluetoothItem::hasAdapter()
|
||||||
{
|
{
|
||||||
return m_applet->hasAadapter();
|
return m_applet->hasAadapter();
|
||||||
|
@ -38,13 +38,14 @@ class BluetoothItem : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit BluetoothItem(QWidget *parent = nullptr);
|
explicit BluetoothItem(QWidget *parent = nullptr);
|
||||||
|
|
||||||
// QWidget *tipsWidget();
|
QWidget *tipsWidget();
|
||||||
QWidget *popupApplet();
|
QWidget *popupApplet();
|
||||||
|
|
||||||
const QString contextMenu() const;
|
const QString contextMenu() const;
|
||||||
void invokeMenuItem(const QString menuId, const bool checked);
|
void invokeMenuItem(const QString menuId, const bool checked);
|
||||||
|
|
||||||
void refreshIcon();
|
void refreshIcon();
|
||||||
|
void refreshTips();
|
||||||
|
|
||||||
bool hasAdapter();
|
bool hasAdapter();
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ signals:
|
|||||||
void justHasAdapter();
|
void justHasAdapter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TipsWidget *m_tipsLabel;
|
TipsWidget *m_tipsLabel;
|
||||||
BluetoothApplet *m_applet;
|
BluetoothApplet *m_applet;
|
||||||
QPixmap m_iconPixmap;
|
QPixmap m_iconPixmap;
|
||||||
|
|
||||||
|
@ -85,14 +85,14 @@ QWidget *BluetoothPlugin::itemWidget(const QString &itemKey)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//QWidget *BluetoothPlugin::itemTipsWidget(const QString &itemKey)
|
QWidget *BluetoothPlugin::itemTipsWidget(const QString &itemKey)
|
||||||
//{
|
{
|
||||||
// if (itemKey == BLUETOOTH_KEY) {
|
if (itemKey == BLUETOOTH_KEY) {
|
||||||
// return m_bluetoothItem->tipsWidget();
|
return m_bluetoothItem->tipsWidget();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return nullptr;
|
return nullptr;
|
||||||
//}
|
}
|
||||||
|
|
||||||
QWidget *BluetoothPlugin::itemPopupApplet(const QString &itemKey)
|
QWidget *BluetoothPlugin::itemPopupApplet(const QString &itemKey)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
bool pluginIsAllowDisable() Q_DECL_OVERRIDE { return true; }
|
bool pluginIsAllowDisable() Q_DECL_OVERRIDE { return true; }
|
||||||
bool pluginIsDisable() Q_DECL_OVERRIDE;
|
bool pluginIsDisable() Q_DECL_OVERRIDE;
|
||||||
QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE;
|
QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE;
|
||||||
// QWidget *itemTipsWidget(const QString &itemKey) Q_DECL_OVERRIDE;
|
QWidget *itemTipsWidget(const QString &itemKey) Q_DECL_OVERRIDE;
|
||||||
QWidget *itemPopupApplet(const QString &itemKey) Q_DECL_OVERRIDE;
|
QWidget *itemPopupApplet(const QString &itemKey) Q_DECL_OVERRIDE;
|
||||||
const QString itemContextMenu(const QString &itemKey) Q_DECL_OVERRIDE;
|
const QString itemContextMenu(const QString &itemKey) Q_DECL_OVERRIDE;
|
||||||
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) Q_DECL_OVERRIDE;
|
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) Q_DECL_OVERRIDE;
|
||||||
|
@ -93,11 +93,15 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(m_switchItem, &SwitchItem::checkedChanged, this, &AdapterItem::showAndConnect);
|
connect(m_switchItem, &SwitchItem::checkedChanged, this, &AdapterItem::showAndConnect);
|
||||||
|
connect(m_switchItem, &SwitchItem::justUpdateView, [&](bool checked){
|
||||||
|
showDevices(checked);
|
||||||
|
emit powerChanged(checked);
|
||||||
|
});
|
||||||
connect(adapter, &Adapter::nameChanged, m_switchItem, &SwitchItem::setTitle);
|
connect(adapter, &Adapter::nameChanged, m_switchItem, &SwitchItem::setTitle);
|
||||||
connect(adapter, &Adapter::deviceAdded, this, &AdapterItem::addDeviceItem);
|
connect(adapter, &Adapter::deviceAdded, this, &AdapterItem::addDeviceItem);
|
||||||
connect(adapter, &Adapter::deviceRemoved, this, &AdapterItem::removeDeviceItem);
|
connect(adapter, &Adapter::deviceRemoved, this, &AdapterItem::removeDeviceItem);
|
||||||
connect(adapter, &Adapter::poweredChanged, m_switchItem, [=](const bool powered){
|
connect(adapter, &Adapter::poweredChanged, m_switchItem, [=](const bool powered){
|
||||||
m_switchItem->setChecked(powered,false);
|
m_switchItem->setChecked(powered, false);
|
||||||
});
|
});
|
||||||
connect(m_openControlCenter, &MenueItem::clicked, []{
|
connect(m_openControlCenter, &MenueItem::clicked, []{
|
||||||
DDBusSender()
|
DDBusSender()
|
||||||
@ -132,6 +136,18 @@ int AdapterItem::viewHeight()
|
|||||||
return m_openControlCenter->isVisible() ? CONTROLHEIGHT + ITEMHEIGHT : CONTROLHEIGHT;
|
return m_openControlCenter->isVisible() ? CONTROLHEIGHT + ITEMHEIGHT : CONTROLHEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList AdapterItem::connectedDevsName()
|
||||||
|
{
|
||||||
|
QStringList devsName;
|
||||||
|
for (DeviceItem *devItem : m_sortConnected) {
|
||||||
|
if (devItem) {
|
||||||
|
devsName << devItem->title();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return devsName;
|
||||||
|
}
|
||||||
|
|
||||||
void AdapterItem::deviceItemPaired(const bool paired)
|
void AdapterItem::deviceItemPaired(const bool paired)
|
||||||
{
|
{
|
||||||
auto device = qobject_cast<Device *>(sender());
|
auto device = qobject_cast<Device *>(sender());
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
int viewHeight();
|
int viewHeight();
|
||||||
inline Device::State initDeviceState() { return m_initDeviceState; }
|
inline Device::State initDeviceState() { return m_initDeviceState; }
|
||||||
inline Device::State currentDeviceState() { return m_currentDeviceState; }
|
inline Device::State currentDeviceState() { return m_currentDeviceState; }
|
||||||
|
QStringList connectedDevsName();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceStateChanged(const Device::State state);
|
void deviceStateChanged(const Device::State state);
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
bool operator <(const DeviceItem &item);
|
bool operator <(const DeviceItem &item);
|
||||||
|
|
||||||
inline void setTitle(const QString &name) { m_title->setText(name); }
|
inline void setTitle(const QString &name) { m_title->setText(name); }
|
||||||
|
inline QString title() { return m_title->text(); }
|
||||||
|
|
||||||
void setDevice(Device *device);
|
void setDevice(Device *device);
|
||||||
inline Device *device() { return m_device; }
|
inline Device *device() { return m_device; }
|
||||||
|
@ -59,17 +59,16 @@ SwitchItem::SwitchItem(QWidget *parent)
|
|||||||
|
|
||||||
void SwitchItem::setChecked(const bool checked,bool notify)
|
void SwitchItem::setChecked(const bool checked,bool notify)
|
||||||
{
|
{
|
||||||
if(!notify)// 防止收到蓝牙开启或关闭信号后再触发一次打开或关闭
|
m_checkState = checked;
|
||||||
{
|
if(!notify) { // 防止收到蓝牙开启或关闭信号后再触发一次打开或关闭
|
||||||
m_switchBtn->blockSignals(true);
|
m_switchBtn->blockSignals(true);
|
||||||
m_switchBtn->setChecked(checked);
|
m_switchBtn->setChecked(checked);
|
||||||
m_switchBtn->blockSignals(false);
|
m_switchBtn->blockSignals(false);
|
||||||
|
emit justUpdateView(checked);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_switchBtn->setChecked(checked);
|
m_switchBtn->setChecked(checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_checkState = checked;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchItem::setTitle(const QString &title)
|
void SwitchItem::setTitle(const QString &title)
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkedChanged(bool checked);
|
void checkedChanged(bool checked);
|
||||||
|
void justUpdateView(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *m_title;
|
QLabel *m_title;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>AdapterItem</name>
|
<name>AdapterItem</name>
|
||||||
<message>
|
<message>
|
||||||
<source>My Device</source>
|
<source>Bluetooth settings</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
@ -36,6 +36,18 @@
|
|||||||
<source>Bluetooth settings</source>
|
<source>Bluetooth settings</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>%1 connected</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Connecting...</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Bluetooth</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>BluetoothPlugin</name>
|
<name>BluetoothPlugin</name>
|
||||||
|
@ -16,21 +16,45 @@ void TipsWidget::setText(const QString &text)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TipsWidget::refreshFont()
|
void TipsWidget::setTextList(const QStringList &textList)
|
||||||
{
|
{
|
||||||
setFixedSize(fontMetrics().width(m_text) + 6, fontMetrics().height());
|
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();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TipsWidget::paintEvent(QPaintEvent *event)
|
void TipsWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QFrame::paintEvent(event);
|
QFrame::paintEvent(event);
|
||||||
refreshFont();
|
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setPen(QPen(palette().brightText(), 1));
|
painter.setPen(QPen(palette().brightText(), 1));
|
||||||
|
|
||||||
QTextOption option;
|
QTextOption option;
|
||||||
|
int fontHeight = fontMetrics().height();
|
||||||
option.setAlignment(Qt::AlignCenter);
|
option.setAlignment(Qt::AlignCenter);
|
||||||
painter.drawText(rect(), m_text, option);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,17 @@ public:
|
|||||||
explicit TipsWidget(QWidget *parent = nullptr);
|
explicit TipsWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
const QString& text(){return m_text;}
|
const QString& text(){return m_text;}
|
||||||
|
const QStringList &textList() { return m_textList; }
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
void refreshFont();
|
void setTextList(const QStringList &textList);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_text;
|
QString m_text;
|
||||||
|
QStringList m_textList;
|
||||||
|
int m_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TIPSWIDGET_H
|
#endif // TIPSWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user