mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
refactor(bluetooth):adjust poupop window view
调整弹窗外观主要是字号,字体颜色,对齐等 task:20299 (cherry picked from commit e294281bef7a8e4d8960604965cad20e0be852c1)
This commit is contained in:
parent
5a4a76bd0c
commit
028ee46568
@ -28,10 +28,31 @@
|
||||
#include "componments/adaptersmanager.h"
|
||||
#include "componments/adapteritem.h"
|
||||
|
||||
#include <DApplicationHelper>
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
extern int ControlHeight;
|
||||
extern int ItemHeight;
|
||||
const int Width = 200;
|
||||
|
||||
extern void initFontColor(QWidget *widget)
|
||||
{
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
auto fontChange = [&](QWidget *widget){
|
||||
QPalette defaultPalette = widget->palette();
|
||||
defaultPalette.setBrush(QPalette::WindowText, defaultPalette.brightText());
|
||||
widget->setPalette(defaultPalette);
|
||||
};
|
||||
|
||||
fontChange(widget);
|
||||
|
||||
QObject::connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, widget, [=]{
|
||||
fontChange(widget);
|
||||
});
|
||||
}
|
||||
|
||||
BluetoothApplet::BluetoothApplet(QWidget *parent)
|
||||
: QScrollArea(parent)
|
||||
, m_line(new HorizontalSeparator(this))
|
||||
@ -42,7 +63,12 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
||||
{
|
||||
m_line->setVisible(false);
|
||||
|
||||
auto defaultFont = font();
|
||||
auto titlefont = QFont(defaultFont.family(), defaultFont.pointSize() + 2);
|
||||
|
||||
m_appletName->setText(tr("Bluetooth"));
|
||||
m_appletName->setFont(titlefont);
|
||||
initFontColor(m_appletName);
|
||||
m_appletName->setVisible(false);
|
||||
|
||||
auto appletNameLayout = new QHBoxLayout;
|
||||
|
@ -39,7 +39,6 @@
|
||||
DWIDGET_USE_NAMESPACE
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
|
||||
BluetoothItem::BluetoothItem(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_applet(new BluetoothApplet(this))
|
||||
@ -59,6 +58,7 @@ BluetoothItem::BluetoothItem(QWidget *parent)
|
||||
m_devState = state;
|
||||
refreshIcon();
|
||||
});
|
||||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &BluetoothItem::refreshIcon);
|
||||
connect(m_applet, SIGNAL(noAdapter()), this, SIGNAL(noAdapter()));
|
||||
connect(m_applet, SIGNAL(justHasAdapter()), this, SIGNAL(justHasAdapter()));
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
const QString id = deviceObj["Path"].toString();
|
||||
const QString name = deviceObj["Alias"].toString();
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
|
||||
removeDevice(id);
|
||||
@ -60,6 +61,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
device->setName(name);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setRssi(rssi);
|
||||
device->setAdapterId(m_id);
|
||||
|
||||
m_devices[id] = device;
|
||||
@ -85,6 +87,7 @@ void Adapter::updateDevice(const QJsonObject &json)
|
||||
const QString id = json["Path"].toString();
|
||||
const QString name = json["Alias"].toString();
|
||||
const bool paired = json["Paired"].toBool();
|
||||
const int rssi = json["RSSI"].toInt();
|
||||
const Device::State state = Device::State(json["State"].toInt());
|
||||
|
||||
auto constdevice = m_devices.value(id);
|
||||
@ -93,6 +96,7 @@ void Adapter::updateDevice(const QJsonObject &json)
|
||||
device->setId(id);
|
||||
device->setName(name);
|
||||
device->setPaired(paired);
|
||||
device->setRssi(rssi);
|
||||
device->setState(state);
|
||||
}
|
||||
}
|
||||
@ -145,6 +149,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
const QString id = deviceObj["Path"].toString();
|
||||
const QString name = deviceObj["Alias"].toString();
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
|
||||
auto device = new Device(this);
|
||||
@ -152,6 +157,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
device->setName(name);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setRssi(rssi);
|
||||
device->setAdapterId(adapterId);
|
||||
|
||||
m_devices[id] = device;
|
||||
|
@ -31,6 +31,7 @@
|
||||
extern const int ItemHeight;
|
||||
extern const int ControlHeight;
|
||||
const int Width = 200;
|
||||
extern void initFontColor(QWidget *widget);
|
||||
|
||||
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
|
||||
: QScrollArea(parent)
|
||||
@ -46,7 +47,8 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
m_line->setVisible(true);
|
||||
m_deviceLayout->setMargin(0);
|
||||
m_deviceLayout->setSpacing(0);
|
||||
m_openControlCenter->setText("Bluetooth settings");
|
||||
m_openControlCenter->setText(tr("Bluetooth settings"));
|
||||
initFontColor(m_openControlCenter);
|
||||
m_openControlCenter->setFixedHeight(ItemHeight);
|
||||
m_openControlCenter->setVisible(false);
|
||||
m_switchItem->setTitle(adapter->name());
|
||||
@ -71,7 +73,11 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
for (auto constDevice : myDevices) {
|
||||
auto device = const_cast<Device *>(constDevice);
|
||||
if (device) {
|
||||
createDeviceItem(device);
|
||||
DeviceItem *deviceItem = createDeviceItem(device);
|
||||
if (device->state() == Device::StateConnected)
|
||||
m_sortConnected << deviceItem;
|
||||
else
|
||||
m_sortUnConnect << deviceItem;
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,6 +163,8 @@ void AdapterItem::removeDeviceItem(const Device *device)
|
||||
auto deviceItem = m_deviceItems.value(device->id());
|
||||
if (deviceItem) {
|
||||
m_deviceItems.remove(device->id());
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
if (device->paired()) {
|
||||
// m_pairedDeviceItems.remove(device->id());
|
||||
}
|
||||
@ -192,11 +200,26 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
||||
auto device = qobject_cast<Device *>(sender());
|
||||
if (device) {
|
||||
auto deviceItem = m_deviceItems.value(device->id());
|
||||
if (deviceItem && Device::StateConnected == state) {
|
||||
auto fromWidget = m_deviceLayout->itemAt(2)->widget();
|
||||
if (fromWidget) {
|
||||
m_deviceLayout->replaceWidget(fromWidget, deviceItem);
|
||||
m_deviceLayout->addWidget(fromWidget);
|
||||
if (deviceItem) {
|
||||
switch (state) {
|
||||
case Device::StateUnavailable:
|
||||
case Device::StateAvailable: {
|
||||
int index = m_sortConnected.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect << deviceItem;
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
m_sortConnected << deviceItem;
|
||||
qSort(m_sortConnected);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,10 +228,31 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
||||
emit deviceStateChanged(state);
|
||||
}
|
||||
|
||||
void AdapterItem::createDeviceItem(Device *device)
|
||||
void AdapterItem::moveDeviceItem(Device::State state, DeviceItem *item)
|
||||
{
|
||||
int size = m_sortConnected.size();
|
||||
int index = 0;
|
||||
switch (state) {
|
||||
case Device::StateUnavailable:
|
||||
case Device::StateAvailable: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
index += size;
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
index = m_sortUnConnect.indexOf(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
index += 2;
|
||||
m_deviceLayout->removeWidget(item);
|
||||
m_deviceLayout->insertWidget(index, item);
|
||||
}
|
||||
|
||||
DeviceItem *AdapterItem::createDeviceItem(Device *device)
|
||||
{
|
||||
if (!device)
|
||||
return;
|
||||
return nullptr;
|
||||
|
||||
// auto paired = device->paired();
|
||||
auto deviceId = device->id();
|
||||
@ -223,11 +267,25 @@ void AdapterItem::createDeviceItem(Device *device)
|
||||
connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle);
|
||||
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::changeState);
|
||||
connect(device, &Device::stateChanged, this, &AdapterItem::deviceChangeState);
|
||||
connect(device, &Device::rssiChanged, [&]{
|
||||
auto device = qobject_cast<Device *>(sender());
|
||||
if (device) {
|
||||
auto deviceItem = m_deviceItems.value(device->id());
|
||||
auto state = device->state();
|
||||
if (deviceItem && Device::StateConnected == state)
|
||||
qSort(m_sortConnected);
|
||||
else
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
});
|
||||
connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice);
|
||||
|
||||
return deviceItem;
|
||||
}
|
||||
|
||||
void AdapterItem::updateView()
|
||||
{
|
||||
{
|
||||
auto contentHeight = m_switchItem->height();
|
||||
contentHeight += (m_deviceLayout->count() - 3) * ItemHeight;
|
||||
m_centralWidget->setFixedHeight(contentHeight);
|
||||
@ -237,16 +295,22 @@ void AdapterItem::updateView()
|
||||
|
||||
void AdapterItem::showDevices(bool change)
|
||||
{
|
||||
// for (auto deviceItem : m_pairedDeviceItems) {
|
||||
for (auto deviceItem : m_deviceItems) {
|
||||
if (m_sortConnected.size())
|
||||
qSort(m_sortConnected);
|
||||
if (m_sortUnConnect.size())
|
||||
qSort(m_sortUnConnect);
|
||||
|
||||
QList<DeviceItem *> deviceItems;
|
||||
deviceItems << m_sortConnected << m_sortUnConnect;
|
||||
|
||||
for (DeviceItem *deviceItem : deviceItems) {
|
||||
if (change)
|
||||
m_deviceLayout->addWidget(deviceItem);
|
||||
else {
|
||||
else
|
||||
m_deviceLayout->removeWidget(deviceItem);
|
||||
}
|
||||
deviceItem->setVisible(change);
|
||||
}
|
||||
// auto itemCount = m_pairedDeviceItems.size();
|
||||
|
||||
auto itemCount = m_deviceItems.size();
|
||||
m_line->setVisible(change);
|
||||
m_openControlCenter->setVisible(!itemCount);
|
||||
|
@ -60,9 +60,10 @@ private slots:
|
||||
void showAndConnect(bool change);
|
||||
void addDeviceItem(const Device *constDevice);
|
||||
void deviceChangeState(const Device::State state);
|
||||
void moveDeviceItem(Device::State state, DeviceItem *item);
|
||||
|
||||
private:
|
||||
void createDeviceItem(Device *device);
|
||||
DeviceItem *createDeviceItem(Device *device);
|
||||
void updateView();
|
||||
void showDevices(bool change);
|
||||
|
||||
@ -79,6 +80,8 @@ private:
|
||||
QMap<QString, DeviceItem*> m_deviceItems;
|
||||
Device::State m_initDeviceState;
|
||||
Device::State m_currentDeviceState;
|
||||
QList<DeviceItem *> m_sortConnected;
|
||||
QList<DeviceItem *> m_sortUnConnect;
|
||||
// QMap<QString, DeviceItem*> m_pairedDeviceItems;
|
||||
};
|
||||
|
||||
|
@ -29,6 +29,7 @@ Device::Device(QObject *parent) :
|
||||
m_paired(false),
|
||||
m_trusted(false),
|
||||
m_connecting(false),
|
||||
m_rssi(0),
|
||||
m_state(StateUnavailable),
|
||||
m_adapterId(QString())
|
||||
{
|
||||
@ -79,6 +80,14 @@ void Device::setConnecting(bool connecting)
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setRssi(int rssi)
|
||||
{
|
||||
if (m_rssi != rssi) {
|
||||
m_rssi = rssi;
|
||||
Q_EMIT rssiChanged(rssi);
|
||||
}
|
||||
}
|
||||
|
||||
QDebug &operator<<(QDebug &stream, const Device *device)
|
||||
{
|
||||
stream << "Device name:" << device->name()
|
||||
|
@ -59,6 +59,9 @@ public:
|
||||
inline bool connecting() const { return m_connecting; }
|
||||
void setConnecting(bool connecting);
|
||||
|
||||
inline int rssi() const { return m_rssi; }
|
||||
void setRssi(int rssi);
|
||||
|
||||
inline void setAdapterId(const QString &id) { m_adapterId = id; }
|
||||
inline const QString &getAdapterId() const { return m_adapterId; }
|
||||
|
||||
@ -68,6 +71,7 @@ Q_SIGNALS:
|
||||
void stateChanged(const State state) const;
|
||||
void trustedChanged(const bool trusted) const;
|
||||
void connectingChanged(const bool &connecting) const;
|
||||
void rssiChanged(const int rssi) const;
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
@ -75,6 +79,7 @@ private:
|
||||
bool m_paired;
|
||||
bool m_trusted;
|
||||
bool m_connecting;
|
||||
int m_rssi;
|
||||
State m_state;
|
||||
QString m_adapterId;
|
||||
};
|
||||
|
@ -22,12 +22,18 @@
|
||||
|
||||
#include "deviceitem.h"
|
||||
|
||||
#include <DApplicationHelper>
|
||||
#include <DStyle>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
extern const int ItemHeight = 30;
|
||||
const QString LightSuffix = "_dark.svg";
|
||||
const QString DarkSuffix = ".svg";
|
||||
extern void initFontColor(QWidget *widget);
|
||||
|
||||
DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@ -37,8 +43,16 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||
, m_line(new HorizontalSeparator(this))
|
||||
{
|
||||
setFixedHeight(ItemHeight);
|
||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
||||
m_state->setPixmap(QPixmap(":/select_dark.svg"));
|
||||
auto themeChanged = [&](DApplicationHelper::ColorType themeType){
|
||||
switch (themeType) {
|
||||
case DApplicationHelper::UnknownType:
|
||||
case DApplicationHelper::LightType: m_statSuffix = LightSuffix; break;
|
||||
case DApplicationHelper::DarkType: m_statSuffix = DarkSuffix; break;
|
||||
}
|
||||
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
||||
};
|
||||
|
||||
themeChanged(DApplicationHelper::instance()->themeType());
|
||||
|
||||
auto strTitle = title;
|
||||
m_title->setText(strTitle);
|
||||
@ -48,6 +62,7 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||
strTitle = QFontMetrics(m_title->font()).elidedText(strTitle, Qt::ElideRight, m_title->width());
|
||||
}
|
||||
m_title->setText(strTitle);
|
||||
initFontColor(m_title);
|
||||
|
||||
m_line->setVisible(true);
|
||||
m_state->setVisible(false);
|
||||
@ -69,6 +84,21 @@ DeviceItem::DeviceItem(const QString &title, QWidget *parent)
|
||||
itemLayout->addSpacing(12);
|
||||
deviceLayout->addLayout(itemLayout);
|
||||
setLayout(deviceLayout);
|
||||
|
||||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, themeChanged);
|
||||
}
|
||||
|
||||
bool DeviceItem::operator <(const DeviceItem &item)
|
||||
{
|
||||
return this->device()->rssi() < item.device()->rssi();
|
||||
}
|
||||
|
||||
void DeviceItem::setDevice(Device *d)
|
||||
{
|
||||
if (d) {
|
||||
m_device = d;
|
||||
changeState(d->state());
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceItem::mousePressEvent(QMouseEvent *event)
|
||||
@ -83,7 +113,7 @@ void DeviceItem::enterEvent(QEvent *event)
|
||||
if (m_device) {
|
||||
if (Device::StateConnected == m_device->state()) {
|
||||
// m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
|
||||
m_state->setPixmap(QPixmap(":/disconnect_dark.svg"));
|
||||
m_state->setPixmap(QPixmap(":/disconnect" + m_statSuffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,7 +124,7 @@ void DeviceItem::leaveEvent(QEvent *event)
|
||||
if (m_device) {
|
||||
if (Device::StateConnected == m_device->state()) {
|
||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
||||
m_state->setPixmap(QPixmap(":/select_dark.svg"));
|
||||
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,13 @@ class DeviceItem : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DeviceItem(const QString &title, QWidget *parent = nullptr);
|
||||
bool operator <(const DeviceItem &item);
|
||||
|
||||
inline void setTitle(const QString &name) { m_title->setText(name); }
|
||||
|
||||
inline void setDevice(Device *d) { m_device = d; }
|
||||
void setDevice(Device *d);
|
||||
inline Device *device() { return m_device; }
|
||||
inline const Device *device() const { return m_device; }
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
@ -60,6 +62,7 @@ private:
|
||||
DSpinner *m_loadingStat;
|
||||
Device *m_device = nullptr;
|
||||
HorizontalSeparator *m_line;
|
||||
QString m_statSuffix;
|
||||
};
|
||||
|
||||
class HorizontalSeparator : public QWidget
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "QHBoxLayout"
|
||||
|
||||
extern const int ControlHeight = 35;
|
||||
extern void initFontColor(QWidget *widget);
|
||||
|
||||
SwitchItem::SwitchItem(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@ -32,6 +33,8 @@ SwitchItem::SwitchItem(QWidget *parent)
|
||||
, m_switchBtn(new DSwitchButton(this))
|
||||
, m_default(false)
|
||||
{
|
||||
initFontColor(m_title);
|
||||
|
||||
setFixedHeight(ControlHeight);
|
||||
auto switchLayout = new QHBoxLayout(this);
|
||||
switchLayout->setSpacing(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user