mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 任务栏蓝牙插件无刷新按钮
蓝牙插件刷新按钮未添加,按照之前的蓝牙插件界面刷新按钮位置添加刷新按钮 Log: 蓝牙插件刷新按钮去掉了无法刷新列表 Bug: https://pms.uniontech.com/zentao/bug-view-60828.html Change-Id: I9c6813e1d57e4b83db2f8e224e107c06215e802f
This commit is contained in:
parent
4c85face8b
commit
26248213bf
@ -24,6 +24,7 @@
|
||||
#include "componments/adapter.h"
|
||||
#include "bluetoothapplet.h"
|
||||
#include "bluetoothconstants.h"
|
||||
#include "refreshbutton.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QStandardItemModel>
|
||||
@ -121,6 +122,7 @@ BluetoothAdapterItem::BluetoothAdapterItem(Adapter *adapter, QWidget *parent)
|
||||
, m_adapterStateBtn(new DSwitchButton(this))
|
||||
, m_deviceListview(new DListView(this))
|
||||
, m_deviceModel(new QStandardItemModel(m_deviceListview))
|
||||
, m_refreshBtn(new RefreshButton(this))
|
||||
{
|
||||
initData();
|
||||
initUi();
|
||||
@ -162,6 +164,15 @@ void BluetoothAdapterItem::onAdapterNameChanged(const QString name)
|
||||
m_adapterLabel->label()->setText(name);
|
||||
}
|
||||
|
||||
void BluetoothAdapterItem::updateIconTheme(DGuiApplicationHelper::ColorType type)
|
||||
{
|
||||
if (type == DGuiApplicationHelper::LightType) {
|
||||
m_refreshBtn->setRotateIcon(":/wireless/resources/wireless/refresh_dark.svg");
|
||||
} else {
|
||||
m_refreshBtn->setRotateIcon(":/wireless/resources/wireless/refresh.svg");
|
||||
}
|
||||
}
|
||||
|
||||
int BluetoothAdapterItem::currentDeviceCount()
|
||||
{
|
||||
return m_deviceItems.size();
|
||||
@ -222,10 +233,14 @@ void BluetoothAdapterItem::onDeviceRemoved(const Device *device)
|
||||
|
||||
void BluetoothAdapterItem::initUi()
|
||||
{
|
||||
m_refreshBtn->setFixedSize(24, 24);
|
||||
m_refreshBtn->setVisible(m_adapter->powered());
|
||||
|
||||
setAccessibleName(m_adapter->name());
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
m_adapterLabel->setFixedSize(ItemWidth, TitleHeight);
|
||||
m_adapterLabel->addSwichButton(m_adapterStateBtn);
|
||||
m_adapterLabel->addButton(m_refreshBtn, 0);
|
||||
m_adapterLabel->addButton(m_adapterStateBtn, 10);
|
||||
DFontSizeManager::instance()->bind(m_adapterLabel->label(), DFontSizeManager::T4);
|
||||
|
||||
m_adapterStateBtn->setChecked(m_adapter->powered());
|
||||
@ -250,14 +265,32 @@ void BluetoothAdapterItem::initUi()
|
||||
mainLayout->addWidget(m_adapterLabel);
|
||||
mainLayout->addSpacing(2);
|
||||
mainLayout->addWidget(m_deviceListview);
|
||||
|
||||
updateIconTheme(DGuiApplicationHelper::instance()->themeType());
|
||||
if (m_adapter->discover()) {
|
||||
m_refreshBtn->startRotate();
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothAdapterItem::initConnect()
|
||||
{
|
||||
connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &BluetoothAdapterItem::updateIconTheme);
|
||||
connect(m_adapter, &Adapter::deviceAdded, this, &BluetoothAdapterItem::onDeviceAdded);
|
||||
connect(m_adapter, &Adapter::deviceRemoved, this, &BluetoothAdapterItem::onDeviceRemoved);
|
||||
connect(m_adapter, &Adapter::nameChanged, this, &BluetoothAdapterItem::onAdapterNameChanged);
|
||||
connect(m_deviceListview, &DListView::clicked, this, &BluetoothAdapterItem::onConnectDevice);
|
||||
connect(m_adapter, &Adapter::discoveringChanged, this, [ = ] (bool state) {
|
||||
if (state) {
|
||||
m_refreshBtn->startRotate();
|
||||
} else {
|
||||
m_refreshBtn->stopRotate();
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_refreshBtn, &RefreshButton::clicked, this, [ = ] {
|
||||
emit requestRefreshAdapter(m_adapter);
|
||||
});
|
||||
|
||||
connect(m_adapter, &Adapter::poweredChanged, this, [ = ] (bool state) {
|
||||
initData();
|
||||
m_deviceListview->setVisible(state);
|
||||
@ -271,6 +304,7 @@ void BluetoothAdapterItem::initConnect()
|
||||
m_deviceModel->clear();
|
||||
m_deviceListview->setVisible(false);
|
||||
m_adapterStateBtn->setEnabled(false);
|
||||
m_refreshBtn->setVisible(state);
|
||||
emit requestSetAdapterPower(m_adapter, state);
|
||||
});
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ DWIDGET_END_NAMESPACE
|
||||
class Adapter;
|
||||
class SettingLabel;
|
||||
class QStandardItemModel;
|
||||
class RefreshButton;
|
||||
|
||||
const QString LightString = QString(":/light/buletooth_%1_light.svg");
|
||||
const QString DarkString = QString(":/dark/buletooth_%1_dark.svg");
|
||||
@ -101,10 +102,12 @@ public slots:
|
||||
void onTopDeviceItem(DStandardItem* item);
|
||||
// 设置蓝牙适配器名称
|
||||
void onAdapterNameChanged(const QString name);
|
||||
void updateIconTheme(DGuiApplicationHelper::ColorType type);
|
||||
|
||||
signals:
|
||||
void adapterPowerChanged();
|
||||
void requestSetAdapterPower(Adapter *adapter, bool state);
|
||||
void requestRefreshAdapter(Adapter *adapter);
|
||||
void connectDevice(const Device *device, Adapter *adapter);
|
||||
void deviceCountChanged();
|
||||
void deviceStateChanged(const Device* device);
|
||||
@ -119,6 +122,7 @@ private:
|
||||
DSwitchButton *m_adapterStateBtn = nullptr;
|
||||
DListView *m_deviceListview = nullptr;
|
||||
QStandardItemModel *m_deviceModel = nullptr;
|
||||
RefreshButton *m_refreshBtn = nullptr;
|
||||
|
||||
QMap<QString, BluetoothDeviceItem *> m_deviceItems;
|
||||
};
|
||||
|
@ -50,12 +50,13 @@ SettingLabel::SettingLabel(QString text, QWidget *parent)
|
||||
m_layout->setMargin(0);
|
||||
m_layout->addSpacing(20);
|
||||
m_layout->addWidget(m_label, 0, Qt::AlignLeft | Qt::AlignHCenter);
|
||||
m_layout->addStretch();
|
||||
}
|
||||
|
||||
void SettingLabel::addSwichButton(DSwitchButton *button)
|
||||
void SettingLabel::addButton(QWidget *button, int space)
|
||||
{
|
||||
m_layout->addWidget(button, 0, Qt::AlignRight | Qt::AlignHCenter);
|
||||
m_layout->addSpacing(10);
|
||||
m_layout->addSpacing(space);
|
||||
}
|
||||
|
||||
void SettingLabel::mousePressEvent(QMouseEvent *ev)
|
||||
@ -153,6 +154,7 @@ void BluetoothApplet::onAdapterAdded(Adapter *adapter)
|
||||
connect(adapterItem, &BluetoothAdapterItem::deviceCountChanged, this, &BluetoothApplet::updateSize);
|
||||
connect(adapterItem, &BluetoothAdapterItem::adapterPowerChanged, this, &BluetoothApplet::updateBluetoothPowerState);
|
||||
connect(adapterItem, &BluetoothAdapterItem::deviceStateChanged, this, &BluetoothApplet::deviceStateChanged);
|
||||
connect(adapterItem, &BluetoothAdapterItem::requestRefreshAdapter, m_adaptersManager, &AdaptersManager::adapterRefresh);
|
||||
|
||||
m_adapterItems.insert(adapter->id(), adapterItem);
|
||||
m_contentLayout->insertWidget(0, adapterItem, Qt::AlignTop | Qt::AlignVCenter);
|
||||
|
@ -49,7 +49,7 @@ class SettingLabel : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingLabel(QString text, QWidget *parent = nullptr);
|
||||
void addSwichButton(DSwitchButton *button);
|
||||
void addButton(QWidget *button, int space);
|
||||
DLabel *label() { return m_label; }
|
||||
signals:
|
||||
void clicked();
|
||||
|
73
plugins/bluetooth/componments/refreshbutton.cpp
Normal file
73
plugins/bluetooth/componments/refreshbutton.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "refreshbutton.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QMouseEvent>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDebug>
|
||||
|
||||
RefreshButton::RefreshButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_refreshTimer(new QTimer(this))
|
||||
, m_rotateAngle(0)
|
||||
{
|
||||
setAccessibleName("RefreshButton");
|
||||
m_refreshTimer->setInterval(500 / 60);
|
||||
initConnect();
|
||||
}
|
||||
|
||||
void RefreshButton::setRotateIcon(QString path)
|
||||
{
|
||||
m_pixmap = QIcon(path).pixmap(size());
|
||||
}
|
||||
|
||||
void RefreshButton::startRotate()
|
||||
{
|
||||
m_refreshTimer->start();
|
||||
if (m_rotateAngle == 360) {
|
||||
m_rotateAngle = 0;
|
||||
}
|
||||
m_rotateAngle += 360 / 60;
|
||||
update();
|
||||
}
|
||||
|
||||
void RefreshButton::stopRotate()
|
||||
{
|
||||
m_refreshTimer->stop();
|
||||
m_rotateAngle = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void RefreshButton::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
painter.translate(this->width() / 2, this->height() / 2);
|
||||
painter.rotate(m_rotateAngle);
|
||||
painter.translate(-(this->width() / 2), -(this->height() / 2));
|
||||
painter.drawPixmap(this->rect(), m_pixmap);
|
||||
|
||||
QWidget::paintEvent(e);
|
||||
}
|
||||
|
||||
void RefreshButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_pressPos = event->pos();
|
||||
return QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void RefreshButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (rect().contains(m_pressPos) && rect().contains(event->pos()) && !m_refreshTimer->isActive())
|
||||
Q_EMIT clicked();
|
||||
return QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void RefreshButton::initConnect()
|
||||
{
|
||||
connect(m_refreshTimer, &QTimer::timeout, this, &RefreshButton::startRotate);
|
||||
}
|
34
plugins/bluetooth/componments/refreshbutton.h
Normal file
34
plugins/bluetooth/componments/refreshbutton.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef REFRESHBUTTON_H
|
||||
#define REFRESHBUTTON_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class RefreshButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RefreshButton(QWidget *parent = nullptr);
|
||||
void setRotateIcon(QString path);
|
||||
void startRotate();
|
||||
void stopRotate();
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
void initConnect();
|
||||
|
||||
QTimer *m_refreshTimer;
|
||||
QPixmap m_pixmap;
|
||||
QPoint m_pressPos;
|
||||
int m_rotateAngle;
|
||||
};
|
||||
|
||||
#endif // REFRESHBUTTON_H
|
Loading…
x
Reference in New Issue
Block a user