From 2af79235bed73efa9568cd974a485a9aa54a023c Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Tue, 16 Nov 2021 16:42:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E8=93=9D=E7=89=99=E5=88=97=E8=A1=A8=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=B7=B2=E8=BF=9E=E6=8E=A5=E4=B8=8A=E7=9A=84=E8=93=9D=E7=89=99?= =?UTF-8?q?=E4=BC=9A=E6=96=AD=E5=BC=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 鼠标移动至“√”会变成“x”,点击“x”断开连接; 点击已连接上的蓝牙无反应,点击非StateUnavailable状态的蓝牙会触发连接动作。 Log: Bug: https://pms.uniontech.com/zentao/bug-view-102537.html Influence: 任务栏的蓝牙模块断开连接操作上有变化。 鼠标移动至“√”会变成“x”,点击“x”断开连接; 点击已连接上的蓝牙无反应,点击非StateUnavailable状态的蓝牙会触发连接动作。 Change-Id: Ie63fc655f38cbe33a84d2bb5a8ca5becdba46507 --- .../bluetooth/componments/bluetoothadapteritem.cpp | 13 ++++++++++++- .../bluetooth/componments/bluetoothadapteritem.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.cpp b/plugins/bluetooth/componments/bluetoothadapteritem.cpp index f59381e19..da68c422e 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.cpp +++ b/plugins/bluetooth/componments/bluetoothadapteritem.cpp @@ -72,8 +72,9 @@ void BluetoothDeviceItem::initActionList() m_connAction = new DViewItemAction(Qt::AlignRight | Qt::AlignVCenter, QSize(16, 16), QSize(16, 16), false); m_connButton->setType(StateButton::Check); - m_connButton->setSwitchFork(false); + m_connButton->setSwitchFork(true); m_connButton->setFixedSize(16, 16); + connect(m_connButton, &StateButton::click, this, &BluetoothDeviceItem::disconnectDevice); m_iconWidget->setFixedSize(18, 16); QHBoxLayout *layout = new QHBoxLayout(m_iconWidget); layout->setContentsMargins(0, 0, 0, 0); @@ -171,6 +172,10 @@ void BluetoothAdapterItem::onConnectDevice(const QModelIndex &index) DStandardItem *deviceitem = dynamic_cast(deviceModel->item(index.row())); foreach (const auto item, m_deviceItems) { + // 只有非连接状态才发送connectDevice信号(connectDevice信号连接的槽为取反操作,而非仅仅连接) + if (!(item->device()->state() == Device::StateUnavailable)) + continue; + if (item->standardItem() == deviceitem) { emit connectDevice(item->device(), m_adapter); } @@ -252,6 +257,12 @@ void BluetoothAdapterItem::onDeviceAdded(const Device *device) BluetoothDeviceItem *item = new BluetoothDeviceItem(style(), device, m_deviceListview); connect(item, &BluetoothDeviceItem::requestTopDeviceItem, this, &BluetoothAdapterItem::onTopDeviceItem); connect(item, &BluetoothDeviceItem::deviceStateChanged, this, &BluetoothAdapterItem::deviceStateChanged); + connect(item, &BluetoothDeviceItem::disconnectDevice, this, [this, item](){ + // 只有已连接状态才发送connectDevice信号(connectDevice信号连接的槽为取反操作,而非仅仅连接) + if (item->device()->state() == Device::StateConnected) { + emit connectDevice(item->device(), m_adapter); + } + }); m_deviceItems.insert(device->id(), item); if (!m_showUnnamedDevices && device->name().isEmpty() && Device::StateConnected != device->state()) diff --git a/plugins/bluetooth/componments/bluetoothadapteritem.h b/plugins/bluetooth/componments/bluetoothadapteritem.h index 8374882c6..628dfe31e 100644 --- a/plugins/bluetooth/componments/bluetoothadapteritem.h +++ b/plugins/bluetooth/componments/bluetoothadapteritem.h @@ -74,6 +74,7 @@ public slots: signals: void requestTopDeviceItem(DStandardItem *item); void deviceStateChanged(const Device *device); + void disconnectDevice(); private: void initActionList();