Skip to content

Commit 6252b26

Browse files
add-uosdeepin-bot[bot]
authored andcommitted
fix(license-dialog): optimize window blur effect and theme adaptation
Replace DAbstractDialog with DBlurEffectWidget to implement window blur effect. Add dynamic theme adaptation for button styling. Optimize window size and layout for better visual consistency. 使用DBlurEffectWidget替代DAbstractDialog实现窗口模糊效果。添加按钮 样式的动态主题适配功能。优化窗口尺寸和布局以提升视觉一致性。 Log: 优化许可协议对话框的模糊效果和主题适配 PMS: BUG-349395 Influence: 许可协议对话框现在支持模糊背景效果,按钮样式会根据主题 自动调整,提供更好的视觉体验和主题一致性。
1 parent e80b14c commit 6252b26

6 files changed

Lines changed: 58 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ global_util/dbus/*.cpp
4242
global_util/dbus/*.h
4343

4444
.cache
45+
obj-x86_64-linux-gnu/*

dde-license-dialog/src/content.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -8,6 +8,7 @@
88
#include <DSuggestButton>
99
#include <DFontSizeManager>
1010
#include <DPalette>
11+
#include <DGuiApplicationHelper>
1112

1213
#include <QScrollArea>
1314
#include <QPushButton>
@@ -67,13 +68,15 @@ Content::Content(QWidget *parent)
6768

6869
layout->addWidget(m_languageBtn, 0, Qt::AlignHCenter);
6970

70-
m_scrollArea->setMinimumSize(468, 300);
71+
m_scrollArea->setMinimumSize(390, 300);
7172
m_scrollArea->setWidgetResizable(true);
7273
m_scrollArea->setFrameStyle(QFrame::NoFrame);
7374
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
7475
m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
7576
m_scrollArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
7677
m_scrollArea->setContentsMargins(0, 0, 0, 0);
78+
m_scrollArea->setStyleSheet("QScrollArea { background: transparent; }"
79+
"QScrollArea > QWidget > QWidget { background: transparent; }");
7780
QScroller::grabGesture(m_scrollArea->viewport(), QScroller::LeftMouseButtonGesture);
7881

7982
QWidget *sourceWidget = new QWidget(this);
@@ -85,9 +88,8 @@ Content::Content(QWidget *parent)
8588
m_cancelBtn->setFixedHeight(36);
8689
m_acceptBtn->setFixedHeight(36);
8790

88-
DPalette pa = m_acceptBtn->palette();
89-
pa.setColor(QPalette::ButtonText, pa.highlight().color());
90-
m_acceptBtn->setPalette(pa);
91+
updateAcceptBtnPalette();
92+
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &Content::updateAcceptBtnPalette);
9193

9294
m_source->setTextFormat(Qt::MarkdownText);
9395
m_source->setWordWrap(true);
@@ -287,3 +289,23 @@ void Content::updateWindowHeight()
287289
int minHeight = qBound(100, contentHeight, 491);
288290
m_scrollArea->setMinimumHeight(minHeight);
289291
}
292+
293+
void Content::updateAcceptBtnPalette()
294+
{
295+
const QString btnStyle = "QPushButton { background-color: rgba(0, 0, 0, 0.15); border: none; border-radius: 6px; }"
296+
"QPushButton:hover { background-color: rgba(0, 0, 0, 0.2); }"
297+
"QPushButton:pressed { background-color: rgba(0, 0, 0, 0.25); }";
298+
m_cancelBtn->setStyleSheet(btnStyle);
299+
m_acceptBtn->setStyleSheet(btnStyle);
300+
301+
DPalette pa = m_acceptBtn->palette();
302+
QColor highlightColor = pa.highlight().color();
303+
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) {
304+
highlightColor.setAlphaF(0.7);
305+
} else {
306+
highlightColor.setAlphaF(0.6);
307+
}
308+
pa.setColor(QPalette::Disabled, QPalette::ButtonText, highlightColor);
309+
pa.setColor(QPalette::Normal, QPalette::ButtonText, pa.highlight().color());
310+
m_acceptBtn->setPalette(pa);
311+
}

dde-license-dialog/src/content.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -44,6 +44,7 @@ public slots:
4444
void updateLanguageBtn();
4545
void updateContent();
4646
void updateWindowHeight();
47+
void updateAcceptBtnPalette();
4748

4849
private:
4950
QScrollArea* m_scrollArea;

dde-license-dialog/src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -9,6 +9,7 @@
99

1010
#include <DApplication>
1111
#include <DGuiApplicationHelper>
12+
#include <DWidgetUtil>
1213

1314
#include <QTranslator>
1415
#include <QCommandLineOption>
@@ -117,7 +118,7 @@ int main(int argc, char *argv[])
117118
checker.setOutputFormat(DAccessibilityChecker::FullFormat);
118119
checker.start();
119120
#endif
120-
w.moveToCenter();
121+
Dtk::Widget::moveToCenter(&w);
121122
w.show();
122123

123124

dde-license-dialog/src/mainwindow.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -13,10 +13,13 @@
1313
#include <DFontSizeManager>
1414
DTK_USE_NAMESPACE
1515

16+
const int DefaultRadius = 8;
17+
1618
MainWindow::MainWindow(QWidget *parent)
17-
: DAbstractDialog(false, parent)
19+
: DBlurEffectWidget(parent)
1820
, m_title(new QLabel)
1921
, m_content(new Content)
22+
, m_handle(new DPlatformWindowHandle(this))
2023
{
2124
auto envType = qEnvironmentVariable("XDG_SESSION_TYPE");
2225
bool bWayland = envType.contains("wayland");
@@ -27,11 +30,23 @@ MainWindow::MainWindow(QWidget *parent)
2730
}
2831

2932
setAccessibleName("MainWindow");
33+
34+
setAttribute(Qt::WA_TranslucentBackground);
35+
36+
setBlendMode(DBlurEffectWidget::BehindWindowBlend);
37+
setMaskColor(DBlurEffectWidget::AutoColor);
38+
39+
m_handle->setEnableBlurWindow(true);
40+
m_handle->setTranslucentBackground(true);
41+
m_handle->setShadowOffset(QPoint(0, 0));
42+
m_handle->setBorderWidth(0);
43+
m_handle->setWindowRadius(DefaultRadius);
44+
3045
m_title->setObjectName("TitleLabel");
3146
m_title->setAccessibleName("TitleLabel");
3247
QWidget *widget = new QWidget(this);
3348
widget->setAccessibleName("MainWidget");
34-
widget->setFixedSize(500, 40);
49+
widget->setFixedSize(430, 40);
3550

3651
btnclose = new DIconButton(QStyle::SP_TitleBarCloseButton, this);
3752
btnclose->setAccessibleName("CloseBtn");
@@ -91,7 +106,7 @@ MainWindow::MainWindow(QWidget *parent)
91106

92107
void MainWindow::resizeEvent(QResizeEvent *event)
93108
{
94-
DAbstractDialog::resizeEvent(event);
109+
DBlurEffectWidget::resizeEvent(event);
95110
if (btnclose) {
96111
const QSize sz = btnclose->sizeHint();
97112
btnclose->move(width() - sz.width(), 0);

dde-license-dialog/src/mainwindow.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
#ifndef MAINWINDOW_H
66
#define MAINWINDOW_H
77

8-
#include <dabstractdialog.h>
8+
#include <DBlurEffectWidget>
99
#include <DIconButton>
10+
#include <DPlatformWindowHandle>
1011

1112
DWIDGET_USE_NAMESPACE
1213

1314
class Content;
1415
class QLabel;
15-
class MainWindow : public DAbstractDialog
16+
class MainWindow : public DBlurEffectWidget
1617
{
1718
Q_OBJECT
1819

@@ -43,7 +44,8 @@ class MainWindow : public DAbstractDialog
4344

4445
DIconButton *btnclose;
4546
DIconButton *m_leftIconBtn;
46-
const int windowFixedWidth = 520;
47+
DPlatformWindowHandle *m_handle;
48+
const int windowFixedWidth = 430;
4749
};
4850

4951
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)