diff --git a/plugins/bluetooth/bluetoothplugin.cpp b/plugins/bluetooth/bluetoothplugin.cpp index ca3ea7917..d41225505 100644 --- a/plugins/bluetooth/bluetoothplugin.cpp +++ b/plugins/bluetooth/bluetoothplugin.cpp @@ -21,7 +21,6 @@ */ #include "bluetoothplugin.h" -#include "bluetoothwidget.h" #include "adaptersmanager.h" #include @@ -34,7 +33,6 @@ BluetoothPlugin::BluetoothPlugin(QObject *parent) : QObject(parent) , m_adapterManager(new AdaptersManager(this)) , m_bluetoothItem(nullptr) - , m_bluetoothWidget(new BluetoothWidget(m_adapterManager)) { } diff --git a/plugins/bluetooth/bluetoothplugin.h b/plugins/bluetooth/bluetoothplugin.h index 35e1bdb21..83f907040 100644 --- a/plugins/bluetooth/bluetoothplugin.h +++ b/plugins/bluetooth/bluetoothplugin.h @@ -28,7 +28,6 @@ #include -class BluetoothWidget; class AdaptersManager; class BluetoothPlugin : public QObject, PluginsItemInterface @@ -66,7 +65,6 @@ private: private: AdaptersManager *m_adapterManager; QScopedPointer m_bluetoothItem; - QScopedPointer m_bluetoothWidget; bool m_enableState = true; }; diff --git a/plugins/bluetooth/bluetoothwidget.cpp b/plugins/bluetooth/bluetoothwidget.cpp deleted file mode 100644 index daf3f1408..000000000 --- a/plugins/bluetooth/bluetoothwidget.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd. - * - * Author: donghualin - * - * Maintainer: donghualin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "bluetoothwidget.h" -#include "adaptersmanager.h" -#include "bloothadapterwidget.h" -#include "adapter.h" -#include "device.h" - -#include -#include - -#include -#include - -BluetoothWidget::BluetoothWidget(AdaptersManager *adapterManager, QWidget *parent) - : QWidget(parent) - , m_switchButton(new DSwitchButton(this)) - , m_headerWidget(new QWidget(this)) - , m_adapterWidget(new QWidget(this)) - , m_adaptersManager(adapterManager) - , m_adapterLayout(new QVBoxLayout(m_adapterWidget)) -{ - initUi(); - initConnection(); -} - -BluetoothWidget::~BluetoothWidget() -{ -} - -void BluetoothWidget::onAdapterIncreased(Adapter *adapter) -{ - BloothAdapterWidget *adapterWidget = new BloothAdapterWidget(adapter, m_adapterWidget); - m_adapterLayout->addWidget(adapterWidget); - connect(adapterWidget, &BloothAdapterWidget::requestConnectDevice, this, [ this, adapter ](Device *device) { - m_adaptersManager->connectDevice(device, adapter); - }); - connect(adapterWidget, &BloothAdapterWidget::requestUpdate, this, [ this ] { - adjustHeight(); - }); - - updateCheckStatus(); - - QMetaObject::invokeMethod(this, &BluetoothWidget::adjustHeight, Qt::QueuedConnection); -} - -void BluetoothWidget::onAdapterDecreased(Adapter *adapter) -{ - for (int i = 0; i < m_adapterLayout->count(); i++) { - BloothAdapterWidget *adapterWidget = static_cast(m_adapterLayout->itemAt(i)->widget()); - if (adapterWidget && adapterWidget->adapter() == adapter) { - m_adapterLayout->removeWidget(adapterWidget); - - updateCheckStatus(); - QMetaObject::invokeMethod(this, &BluetoothWidget::adjustHeight, Qt::QueuedConnection); - break; - } - } -} - -void BluetoothWidget::onCheckedChanged(bool checked) -{ - QList adapters = m_adaptersManager->adapters(); - for (const Adapter *adapter : adapters) - m_adaptersManager->setAdapterPowered(adapter, checked); -} - -void BluetoothWidget::initUi() -{ - QHBoxLayout *headerLayout = new QHBoxLayout(m_headerWidget); - headerLayout->addStretch(); - headerLayout->addWidget(m_switchButton); - headerLayout->addStretch(); - QVBoxLayout *mainLayout = new QVBoxLayout(this); - mainLayout->setContentsMargins(0, 0, 0, 0); - mainLayout->setSpacing(0); - mainLayout->addWidget(m_headerWidget); - mainLayout->addSpacing(3); - mainLayout->addWidget(m_adapterWidget); - - m_adapterLayout->setContentsMargins(0, 0, 0, 0); - m_adapterLayout->setSpacing(0); - - QList adapters = m_adaptersManager->adapters(); - for (const Adapter *adapter : adapters) { - onAdapterIncreased(const_cast(adapter)); - } -} - -void BluetoothWidget::initConnection() -{ - connect(m_adaptersManager, &AdaptersManager::adapterIncreased, this, &BluetoothWidget::onAdapterIncreased); - connect(m_adaptersManager, &AdaptersManager::adapterDecreased, this, &BluetoothWidget::onAdapterDecreased); - connect(m_switchButton, &DSwitchButton::checkedChanged, this, &BluetoothWidget::onCheckedChanged); -} - -void BluetoothWidget::updateCheckStatus() -{ - bool checked = false; - QList adapters = m_adaptersManager->adapters(); - for (const Adapter *adapter : adapters) - checked = adapter->powered(); - - m_switchButton->setChecked(checked); -} - -void BluetoothWidget::adjustHeight() -{ - int height = m_switchButton->height() + m_headerWidget->height(); - for (int i = 0; i < m_adapterLayout->count(); i++) { - BloothAdapterWidget *adapterWidget = static_cast(m_adapterLayout->itemAt(i)->widget()); - if (!adapterWidget) - continue; - - height += adapterWidget->height(); - } - - setFixedHeight(height); -} diff --git a/plugins/bluetooth/bluetoothwidget.h b/plugins/bluetooth/bluetoothwidget.h deleted file mode 100644 index 109e65c38..000000000 --- a/plugins/bluetooth/bluetoothwidget.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd. - * - * Author: donghualin - * - * Maintainer: donghualin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef BLUETOOTHWIDGET_H -#define BLUETOOTHWIDGET_H - -#include - -class QLabel; -class AdaptersManager; -class Adapter; -class QVBoxLayout; - -namespace Dtk { namespace Widget { class DListView; class DSwitchButton; } } - -using namespace Dtk::Widget; - -class BluetoothWidget : public QWidget -{ - Q_OBJECT - -public: - explicit BluetoothWidget(AdaptersManager *adapterManager, QWidget *parent = nullptr); - ~BluetoothWidget() override; - -protected Q_SLOTS: - void onAdapterIncreased(Adapter *adapter); - void onAdapterDecreased(Adapter *adapter); - void onCheckedChanged(bool checked); - -private: - void initUi(); - void initConnection(); - void updateCheckStatus(); - void adjustHeight(); - -private: - DSwitchButton *m_switchButton; - QWidget *m_headerWidget; - QWidget *m_adapterWidget; - AdaptersManager *m_adaptersManager; - QVBoxLayout *m_adapterLayout; -}; - -#endif // BLUETOOTHWIDGET_H