Skip to content

Commit c6138fc

Browse files
authored
fix: brightness-popup's setting button no blur effect and txt color has error (#351)
fix brightness-popup's setting button no blur effect and txt color has error Log: fix brightness-popup's setting button no blur effect and txt color has error Issue: linuxdeepin/developer-center#8470 Influence: brightness-popup's setting button
1 parent 1f697a6 commit c6138fc

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed

panels/dock/tray/plugins/display/displaysettingwidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// SPDX-License-Identifier: LGPL-3.0-or-later
55

66
#include "displaysettingwidget.h"
7+
#include "settingbutton.h"
78

89
#include <QPushButton>
910
#include <QVBoxLayout>
@@ -15,10 +16,10 @@ const int ItemSpacing = 10;
1516
DisplaySettingWidget::DisplaySettingWidget(BrightnessModel *model, QWidget *parent)
1617
: QWidget(parent)
1718
, m_brightnessAdjWidget(new BrightnessAdjWidget(model, this))
18-
, m_settingBtn(new QPushButton(tr("Display Settings"), this))
19+
, m_settingBtn(new SettingButton(tr("Display Settings"), this))
1920
{
2021
initUI();
21-
connect(m_settingBtn, &QPushButton::clicked, this, [ this ](){
22+
connect(m_settingBtn, &SettingButton::clicked, this, [ this ](){
2223
DDBusSender().service("org.deepin.dde.ControlCenter1")
2324
.path("/org/deepin/dde/ControlCenter1")
2425
.interface("org.deepin.dde.ControlCenter1")

panels/dock/tray/plugins/display/displaysettingwidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <QWidget>
1212

13-
class QPushButton;
13+
class SettingButton;
1414
class BrightnessAdjWidget;
1515

1616
/*!
@@ -33,7 +33,7 @@ class DisplaySettingWidget : public QWidget
3333

3434
private:
3535
BrightnessAdjWidget *m_brightnessAdjWidget; // 亮度调整
36-
QPushButton *m_settingBtn; // 设置按钮
36+
SettingButton *m_settingBtn; // 设置按钮
3737
};
3838

3939

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
#include "settingbutton.h"
6+
7+
#include <QHBoxLayout>
8+
9+
#include <DFontSizeManager>
10+
#include <DPaletteHelper>
11+
12+
DWIDGET_USE_NAMESPACE
13+
DGUI_USE_NAMESPACE
14+
15+
SettingButton::SettingButton(const QString &txt, QWidget *parent)
16+
: QFrame(parent)
17+
, m_hover(false)
18+
, m_descriptionLabel(new DLabel(txt, this))
19+
{
20+
initUI();
21+
}
22+
23+
SettingButton::~SettingButton()
24+
{
25+
26+
}
27+
28+
void SettingButton::initUI()
29+
{
30+
setFixedHeight(36);
31+
setForegroundRole(QPalette::BrightText);
32+
33+
m_descriptionLabel->setElideMode(Qt::ElideRight);
34+
m_descriptionLabel->setForegroundRole(foregroundRole());
35+
DFontSizeManager::instance()->bind(m_descriptionLabel, DFontSizeManager::T6);
36+
37+
auto* layout = new QHBoxLayout(this);
38+
layout->setContentsMargins(20, 0, 10, 0);
39+
layout->addWidget(m_descriptionLabel);
40+
layout->addStretch();
41+
}
42+
43+
bool SettingButton::event(QEvent* e)
44+
{
45+
switch (e->type()) {
46+
case QEvent::Leave:
47+
case QEvent::Enter:
48+
m_hover = e->type() == QEvent::Enter;
49+
update();
50+
break;
51+
default:
52+
break;
53+
}
54+
return QWidget::event(e);
55+
}
56+
57+
void SettingButton::paintEvent(QPaintEvent* e)
58+
{
59+
Q_UNUSED(e)
60+
QPainter p(this);
61+
QPalette palette = this->palette();
62+
QColor bgColor, textColor;
63+
if (m_hover) {
64+
textColor = palette.highlightedText().color();
65+
bgColor = palette.color(QPalette::Active, QPalette::Highlight);
66+
} else {
67+
textColor = palette.brightText().color();
68+
bgColor = palette.brightText().color();
69+
bgColor.setAlphaF(0.05);
70+
}
71+
palette.setBrush(QPalette::BrightText, textColor);
72+
m_descriptionLabel->setPalette(palette);
73+
74+
p.setBrush(bgColor);
75+
p.setRenderHint(QPainter::Antialiasing);
76+
p.setPen(Qt::NoPen);
77+
p.drawRoundedRect(rect(), 8, 8);
78+
return QFrame::paintEvent(e);
79+
}
80+
81+
void SettingButton::mouseReleaseEvent(QMouseEvent* event)
82+
{
83+
if (underMouse()) {
84+
Q_EMIT clicked();
85+
}
86+
87+
return QWidget::mouseReleaseEvent(event);
88+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: LGPL-3.0-or-later
4+
5+
#ifndef SETTING_BUTTON_H
6+
#define SETTING_BUTTON_H
7+
8+
#include <QFrame>
9+
10+
#include <DLabel>
11+
12+
class SettingButton : public QFrame
13+
{
14+
Q_OBJECT
15+
public:
16+
explicit SettingButton(const QString &txt, QWidget *parent = nullptr);
17+
~SettingButton();
18+
19+
signals:
20+
void clicked();
21+
22+
protected:
23+
bool event(QEvent* e) override;
24+
void paintEvent(QPaintEvent* e) override;
25+
void mouseReleaseEvent(QMouseEvent* event) override;
26+
27+
private:
28+
void initUI();
29+
30+
private:
31+
bool m_hover;
32+
Dtk::Widget::DLabel *m_descriptionLabel;
33+
};
34+
35+
#endif

0 commit comments

Comments
 (0)