Skip to content

Commit 32cab67

Browse files
committed
fix: improve theme compatibility for bluetooth label
Changed QLabel to DLabel for better theme integration and added dynamic text color handling Added DPaletteHelper and DGuiApplicationHelper includes for theme management Implemented theme change handler to update text color when system theme changes Adjusted text alpha values from 0.75 to 0.6 for better readability across themes Modified bottom margin from 2 to 6 for better spacing These changes ensure consistent text appearance in both light and dark themes and improve the overall visual experience in the bluetooth dock plugin fix: 改进蓝牙标签的主题兼容性 将 QLabel 改为 DLabel 以实现更好的主题集成并添加动态文本颜色处理 添加 DPaletteHelper 和 DGuiApplicationHelper 包含以进行主题管理 实现主题变更处理程序,在系统主题更改时更新文本颜色 将文本透明度值从 0.75 调整为 0.6,以在不同主题下获得更好的可读性 将底部边距从 2 修改为 6 以获得更好的间距 这些更改确保在浅色和深色主题下文本外观一致 并改善蓝牙坞站插件的整体视觉体验 Pms: BUG-332553
1 parent 603d709 commit 32cab67

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <DSwitchButton>
1717
#include <DListView>
1818
#include <DSpinner>
19+
#include <DPaletteHelper>
20+
#include <DGuiApplicationHelper>
1921

2022
#include <QBoxLayout>
2123
#include <QStandardItemModel>
@@ -68,7 +70,7 @@ BluetoothAdapterItem::BluetoothAdapterItem(Adapter *adapter, QWidget *parent)
6870
, m_adapterLayout(new QVBoxLayout)
6971
, m_adapterStateBtn(new DSwitchButton(this))
7072
, m_myDeviceWidget(new QWidget(this))
71-
, m_myDeviceLabel(new QLabel(tr("My Devices"), this))
73+
, m_myDeviceLabel(new DLabel(tr("My Devices"), this))
7274
, m_myDeviceListView(new PluginListView(this))
7375
, m_myDeviceModel(new QStandardItemModel(m_myDeviceListView))
7476
, m_otherDeviceControlWidget(new DeviceControlWidget(this))
@@ -361,8 +363,9 @@ void BluetoothAdapterItem::initUi()
361363
QVBoxLayout *myDeviceLayout = new QVBoxLayout(m_myDeviceWidget);
362364
myDeviceLayout->setSpacing(0);
363365
myDeviceLayout->setContentsMargins(0, 0, 0, 0);
364-
m_myDeviceLabel->setContentsMargins(10, 0, 0, 2);
366+
m_myDeviceLabel->setContentsMargins(10, 0, 0, 6);
365367
DFontSizeManager::instance()->bind(m_myDeviceLabel, DFontSizeManager::T10);
368+
updateMyDeviceLabelTheme();
366369
myDeviceLayout->addWidget(m_myDeviceLabel);
367370
myDeviceLayout->addWidget(m_myDeviceListView);
368371

@@ -462,6 +465,10 @@ void BluetoothAdapterItem::initConnect()
462465
connect(m_otherDeviceControlWidget, &DeviceControlWidget::clicked, this, [this] {
463466
m_autoFold = false;
464467
});
468+
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [this]{
469+
updateMyDeviceLabelTheme();
470+
update();
471+
});
465472
}
466473

467474
void BluetoothAdapterItem::setUnnamedDevicesVisible(bool isShow)
@@ -536,3 +543,17 @@ void BluetoothAdapterItem::hideEvent(QHideEvent *event)
536543
m_otherDeviceControlWidget->setExpandState(false);
537544
QWidget::hideEvent(event);
538545
}
546+
547+
void BluetoothAdapterItem::updateMyDeviceLabelTheme()
548+
{
549+
DPalette palette = DPaletteHelper::instance()->palette(m_myDeviceLabel);
550+
QColor textColor;
551+
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
552+
textColor = Qt::black;
553+
} else {
554+
textColor = Qt::white;
555+
}
556+
textColor.setAlphaF(0.60);
557+
palette.setColor(QPalette::WindowText, textColor);
558+
DPaletteHelper::instance()->setPalette(m_myDeviceLabel, palette);
559+
}

plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class DeviceControlWidget : public QPushButton
110110
// 绘制文字
111111
QRect textRect = rect().marginsRemoved(QMargins(10, 0, 0, 0));
112112
QColor textNomal = palette().brightText().color();
113-
textNomal.setAlphaF(0.75);
113+
textNomal.setAlphaF(0.6);
114114
QColor textColor = underMouse() ? palette().color(QPalette::HighlightedText) : textNomal;
115115
painter.setPen(textColor);
116116
auto pFont = painter.font();
@@ -180,13 +180,14 @@ public slots:
180180
void initUi();
181181
void initConnect();
182182
void setUnnamedDevicesVisible(bool isShow);
183+
void updateMyDeviceLabelTheme();
183184

184185
Adapter *m_adapter;
185186
SettingLabel *m_adapterLabel;
186187
QVBoxLayout *m_adapterLayout;
187188
DSwitchButton *m_adapterStateBtn;
188189
QWidget *m_myDeviceWidget;
189-
QLabel *m_myDeviceLabel;
190+
DLabel *m_myDeviceLabel;
190191
PluginListView *m_myDeviceListView;
191192
QStandardItemModel *m_myDeviceModel;
192193

0 commit comments

Comments
 (0)