fix(bluetooth):Fix bluetooth unavailable problem after standby recovery

21173 #TR4A#DTS2020042702663|CPM2020043000060#【HUAWEI】【Pangu】【短距+BT】S3功能验收出现待机恢复后BT功能不可用

(cherry picked from commit e743088f8bde9e8faccbead1809db9fa86fd2500)
This commit is contained in:
fpc_diesel 2020-05-04 14:24:07 +08:00
parent 4d82f59eaa
commit 0d835e0fec
5 changed files with 37 additions and 36 deletions

View File

@ -54,7 +54,7 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
: QScrollArea(parent)
, m_line(new HorizontalSeparator(this))
, m_appletName(new QLabel(this))
, m_centralWidget(new QWidget(this))
, m_centralWidget(new QWidget)
, m_centrealLayout(new QVBoxLayout)
, m_adaptersManager(new AdaptersManager(this))
{
@ -118,10 +118,10 @@ void BluetoothApplet::onPowerChanged(bool state)
Q_UNUSED(state)
bool powerState = false;
for (auto adapterItem : m_adapterItems) {
if (adapterItem->isPowered()) {
powerState = true;
break;
}
if (adapterItem->isPowered()) {
powerState = true;
break;
}
}
emit powerChanged(powerState);
}
@ -153,16 +153,16 @@ void BluetoothApplet::addAdapter(Adapter *adapter)
}
auto adapterId = adapter->id();
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter, this);
m_adapterItems[adapterId] = adatpterItem;
m_centrealLayout->addWidget(adatpterItem);
getDevieInitState(adatpterItem);
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter);
// m_adapterItems[adapterId] = adatpterItem;
// m_centrealLayout->addWidget(adatpterItem);
// getDevieInitState(adatpterItem);
connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
connect(adatpterItem, &AdapterItem::powerChanged, this, &BluetoothApplet::onPowerChanged);
connect(adatpterItem, &AdapterItem::sizeChange, this, &BluetoothApplet::updateView);
// connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
// connect(adatpterItem, &AdapterItem::powerChanged, this, &BluetoothApplet::onPowerChanged);
// connect(adatpterItem, &AdapterItem::sizeChange, this, &BluetoothApplet::updateView);
updateView();
// updateView();
}
void BluetoothApplet::removeAdapter(Adapter *adapter)
@ -171,6 +171,7 @@ void BluetoothApplet::removeAdapter(Adapter *adapter)
auto adapterId = adapter->id();
auto adapterItem = m_adapterItems.value(adapterId);
if (adapterItem) {
m_centrealLayout->removeWidget(adapterItem);
delete adapterItem;
m_adapterItems.remove(adapterId);
updateView();
@ -204,17 +205,10 @@ void BluetoothApplet::updateView()
if (adaptersCnt > 1)
contentHeight += m_appletName->height();
if (itemCount <= 10) {
contentHeight += itemCount * ITEMHEIGHT;
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(contentHeight);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} else {
contentHeight += itemCount * ITEMHEIGHT;
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(10 * ITEMHEIGHT);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
contentHeight += itemCount * ITEMHEIGHT;
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(qMin(10,itemCount) * ITEMHEIGHT);
setVerticalScrollBarPolicy(itemCount <= 10 ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn);
}
void BluetoothApplet::getDevieInitState(AdapterItem *item)

View File

@ -50,7 +50,7 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
m_openControlCenter->setFixedHeight(ITEMHEIGHT);
m_openControlCenter->setVisible(false);
m_switchItem->setTitle(adapter->name());
m_switchItem->setChecked(adapter->powered());
m_switchItem->setChecked(adapter->powered(),false);
m_deviceLayout->addWidget(m_switchItem);
m_deviceLayout->addWidget(m_line);
@ -93,7 +93,9 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
connect(adapter, &Adapter::nameChanged, m_switchItem, &SwitchItem::setTitle);
connect(adapter, &Adapter::deviceAdded, this, &AdapterItem::addDeviceItem);
connect(adapter, &Adapter::deviceRemoved, this, &AdapterItem::removeDeviceItem);
connect(adapter, &Adapter::poweredChanged, m_switchItem, &SwitchItem::setChecked);
connect(adapter, &Adapter::poweredChanged, m_switchItem, [=](const bool powered){
m_switchItem->setChecked(powered,false);
});
connect(m_openControlCenter, &MenueItem::clicked, []{
DDBusSender()
.service("com.deepin.dde.ControlCenter")
@ -114,7 +116,7 @@ int AdapterItem::deviceCount()
void AdapterItem::setPowered(bool powered)
{
m_switchItem->setChecked(powered);
m_switchItem->setChecked(powered,true);
}
bool AdapterItem::isPowered()

View File

@ -62,11 +62,11 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
m_loadingStat->setFixedSize(20, 20);
m_loadingStat->setVisible(false);
auto deviceLayout = new QVBoxLayout(this);
auto deviceLayout = new QVBoxLayout;
deviceLayout->setMargin(0);
deviceLayout->setSpacing(0);
deviceLayout->addWidget(m_line);
auto itemLayout = new QHBoxLayout(this);
auto itemLayout = new QHBoxLayout;
itemLayout->setMargin(0);
itemLayout->setSpacing(0);
itemLayout->addSpacing(MARGIN);

View File

@ -56,9 +56,18 @@ SwitchItem::SwitchItem(QWidget *parent)
});
}
void SwitchItem::setChecked(const bool checked)
void SwitchItem::setChecked(const bool checked,bool notify)
{
m_switchBtn->setChecked(checked);
if(!notify)// 防止收到蓝牙开启或关闭信号后再触发一次打开或关闭
{
m_switchBtn->blockSignals(true);
m_switchBtn->setChecked(checked);
m_switchBtn->blockSignals(false);
}
else {
m_switchBtn->setChecked(checked);
}
m_checkState = checked;
}

View File

@ -34,19 +34,15 @@ class SwitchItem : public QWidget
Q_OBJECT
public:
explicit SwitchItem(QWidget *parent = nullptr);
void setChecked(const bool checked = true);
void setChecked(const bool checked = true,bool notify = false);
void setTitle(const QString &title);
inline bool checkState() { return m_checkState; }
inline bool isdefault() { return m_default; }
inline void setDefault(bool def) { m_default = def; }
//protected:
// void mousePressEvent(QMouseEvent *event) override;
signals:
void checkedChanged(bool checked);
// void clicked(const QString &adapterId);
private:
QLabel *m_title;