From 3cae22122234759aaa660b3d8eff6e8247b0c2f7 Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Tue, 4 Jul 2023 10:24:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=9B=91=E5=90=AC=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-vpn/frontend/single-pages/singlepage.cpp | 26 ++++++++++++++++++++ src-vpn/frontend/single-pages/singlepage.h | 4 +++ 2 files changed, 30 insertions(+) diff --git a/src-vpn/frontend/single-pages/singlepage.cpp b/src-vpn/frontend/single-pages/singlepage.cpp index b17b6658..53852166 100644 --- a/src-vpn/frontend/single-pages/singlepage.cpp +++ b/src-vpn/frontend/single-pages/singlepage.cpp @@ -26,11 +26,15 @@ #include #include +#define THEME_SCHAME "org.ukui.style" +#define COLOR_THEME "styleName" + SinglePage::SinglePage(QWidget *parent) : QWidget(parent) { initUI(); initWindowProperties(); initTransparency(); + initWindowTheme(); } SinglePage::~SinglePage() @@ -104,6 +108,20 @@ void SinglePage::initWindowProperties() } } +/** + * @brief SinglePage::initWindowTheme 初始化窗口主题并创建信号槽 + */ +void SinglePage::initWindowTheme() +{ + const QByteArray style_id(THEME_SCHAME); + if (QGSettings::isSchemaInstalled(style_id)) { + m_styleGsettings = new QGSettings(style_id, QByteArray(), this); + connect(m_styleGsettings, &QGSettings::changed, this, &SinglePage::onThemeChanged); + } else { + qWarning() << "Gsettings interface \"org.ukui.style\" is not exist!" << Q_FUNC_INFO << __LINE__; + } +} + void SinglePage::showDesktopNotify(const QString &message, QString soundName) { QDBusInterface iface("org.freedesktop.Notifications", @@ -165,6 +183,14 @@ void SinglePage::onTransChanged() paintWithTrans(); } +void SinglePage::onThemeChanged(const QString &key) +{ + if (key == COLOR_THEME) { + paintWithTrans(); + Q_EMIT qApp->paletteChanged(qApp->palette()); + } +} + void SinglePage::paintWithTrans() { QPalette pal = this->palette(); diff --git a/src-vpn/frontend/single-pages/singlepage.h b/src-vpn/frontend/single-pages/singlepage.h index 864e5930..2b9b0d8a 100644 --- a/src-vpn/frontend/single-pages/singlepage.h +++ b/src-vpn/frontend/single-pages/singlepage.h @@ -71,6 +71,7 @@ Q_SIGNALS: private Q_SLOTS: void onTransChanged(); + void onThemeChanged(const QString &key); protected: void paintEvent(QPaintEvent *event); @@ -84,6 +85,7 @@ protected: private: void initWindowProperties(); + void initWindowTheme(); protected: QVBoxLayout * m_mainLayout = nullptr; @@ -106,6 +108,8 @@ protected: QGSettings * m_transGsettings = nullptr; double m_transparency = 1.0; //透明度 + //监听主题的Gsettings + QGSettings * m_styleGsettings = nullptr; };