From 0cfa24b8b0d587ff54194b2a6673f8d36805be31 Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Mon, 4 Dec 2023 09:42:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=8F=92=E4=BB=B6=E4=B8=AD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8QApplication=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...e-use-of-QApplication-class-for-plat.patch | 153 ++++++++++++++++++ kiran-qt5-integration.spec | 6 +- 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 0011-fix-theme-Fix-the-use-of-QApplication-class-for-plat.patch diff --git a/0011-fix-theme-Fix-the-use-of-QApplication-class-for-plat.patch b/0011-fix-theme-Fix-the-use-of-QApplication-class-for-plat.patch new file mode 100644 index 0000000..7197a00 --- /dev/null +++ b/0011-fix-theme-Fix-the-use-of-QApplication-class-for-plat.patch @@ -0,0 +1,153 @@ +From 09c229bb81e3fc77c4d80ed309ae4135b1ff7410 Mon Sep 17 00:00:00 2001 +From: liuxinhao +Date: Fri, 1 Dec 2023 15:48:32 +0800 +Subject: [PATCH] fix(theme): Fix the use of QApplication class for platform + theme plugin errors +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 修复在平台主题插件中错误的使用QApplication类 +--- + platformtheme/kiran-theme.cpp | 50 +++++++++++++++++++++++++---------- + platformtheme/kiran-theme.h | 1 + + 2 files changed, 37 insertions(+), 14 deletions(-) + +diff --git a/platformtheme/kiran-theme.cpp b/platformtheme/kiran-theme.cpp +index 86eb2e1..c1ca81f 100644 +--- a/platformtheme/kiran-theme.cpp ++++ b/platformtheme/kiran-theme.cpp +@@ -14,8 +14,8 @@ + + #include "kiran-theme.h" + #include "kiran-appearance-monitor.h" +-#include "logging-category.h" + #include "kiran-integration-settings.h" ++#include "logging-category.h" + + #include + #include +@@ -27,6 +27,8 @@ + #undef private + + #include ++#include ++ + #include + #include + #include +@@ -38,6 +40,10 @@ + + using namespace Kiran; + ++// NOTE: QPlatformTheme插件是QGuiApplication中init_platform将会进行加载的 ++// 1. 关于Application的调用,QPlatformTheme中只能使用QGuiApplication。 ++// 2. 若一定需要使用QApplication的相关方法,得先判断Qt应用代码中是否使用的是QApplication ++ + KiranTheme::KiranTheme(const QStringList& paramList) + : QGenericUnixTheme() + { +@@ -86,7 +92,7 @@ QVariant KiranTheme::themeHint(QPlatformTheme::ThemeHint hint) const + << "/usr/share/icons" + << "/usr/local/share/icons"; + case StyleNames: +- return QStringList{"kiran","fusion"}; ++ return QStringList{"kiran", "fusion"}; + default: + break; + } +@@ -101,7 +107,7 @@ const QPalette* KiranTheme::palette(QPlatformTheme::Palette type) const + } + + bool enable = KiranIntegrationSettings::appKiranStyleAvailable(qAppName()); +- if( !enable ) ++ if (!enable) + { + return QGenericUnixTheme::palette(type); + } +@@ -119,9 +125,9 @@ void KiranTheme::init() + m_scaleFactor = m_settingsMonitor->scaleFactor(); + qDebug(kiranPlatformTheme) << "\tscale factor:" << m_scaleFactor; + +- m_systemFont.setFamily(m_settingsMonitor->appFont().family()); +- m_systemFont.setPointSize(m_settingsMonitor->appFont().pointSize()); +- QApplication::setFont(m_systemFont); ++ updateAppFont(m_settingsMonitor->appFont().family(), ++ m_settingsMonitor->appFont().pointSize()); ++ + qDebug(kiranPlatformTheme) << "\tapplication font:" << m_settingsMonitor->appFont().family() << m_settingsMonitor->appFont().pointSize(); + + m_titleBarFont.setFamily(m_settingsMonitor->titleBarFont().family()); +@@ -135,14 +141,31 @@ void KiranTheme::init() + QObject::connect(m_settingsMonitor, &KiranAppearanceMonitor::cursorThemeChanged, this, &KiranTheme::handleCursorThemeChanged); + + // 不从KiranAppearanceMonitor接受主题变更事件,修改为接受KiranPalette的主题变更信号,能监听到系统主题变更以及应用程序手动指定主题 +- //QObject::connect(m_settingsMonitor, &KiranAppearanceMonitor::gtkThemeChanged, this, &KiranTheme::handleThemeChanged); +- QObject::connect(StylePalette::instance(),&StylePalette::themeChanged,this,&KiranTheme::handleThemeChanged); ++ // QObject::connect(m_settingsMonitor, &KiranAppearanceMonitor::gtkThemeChanged, this, &KiranTheme::handleThemeChanged); ++ QObject::connect(StylePalette::instance(), &StylePalette::themeChanged, this, &KiranTheme::handleThemeChanged); + +- QObject::connect(qApp, &QApplication::screenAdded, this, &KiranTheme::handleScreenAdded); ++ QObject::connect(qApp, &QGuiApplication::screenAdded, this, &KiranTheme::handleScreenAdded); + + handleScaleFactorChanged(m_scaleFactor); + } + ++void KiranTheme::updateAppFont(const QString& fontFamily, int pointSize) ++{ ++ m_systemFont.setFamily(fontFamily); ++ m_systemFont.setPointSize(pointSize); ++ ++ auto coreApp = QGuiApplication::instance(); ++ if (!qobject_cast(coreApp)) ++ { ++ // FIXME: 使用QGuiApplication更新字体不全 ++ QGuiApplication::setFont(m_systemFont); ++ } ++ else ++ { ++ QApplication::setFont(m_systemFont); ++ } ++} ++ + const QFont* KiranTheme::font(QPlatformTheme::Font type) const + { + switch (type) +@@ -177,9 +200,8 @@ void KiranTheme::handleAppFontChanged() + << m_settingsMonitor->appFont().family() + << m_settingsMonitor->appFont().pointSize(); + +- m_systemFont.setFamily(m_settingsMonitor->appFont().family()); +- m_systemFont.setPointSize(m_settingsMonitor->appFont().pointSize()); +- QApplication::setFont(m_systemFont); ++ updateAppFont(m_settingsMonitor->appFont().family(), ++ m_settingsMonitor->appFont().pointSize()); + } + + void KiranTheme::handleTitleBarFontChanged() +@@ -295,8 +317,8 @@ void KiranTheme::handleScaleFactorChanged(int factor) + void KiranTheme::handleCursorThemeChanged() + { + // 强制让窗口更新光标 +- QApplication::setOverrideCursor(QCursor()); +- QApplication::restoreOverrideCursor(); ++ QGuiApplication::setOverrideCursor(QCursor()); ++ QGuiApplication::restoreOverrideCursor(); + } + + bool KiranTheme::enableRealTimeScaling() +diff --git a/platformtheme/kiran-theme.h b/platformtheme/kiran-theme.h +index 243789c..4ef9c49 100644 +--- a/platformtheme/kiran-theme.h ++++ b/platformtheme/kiran-theme.h +@@ -41,6 +41,7 @@ public: + + private: + void init(); ++ void updateAppFont(const QString& fontFamily,int pointSize); + static bool enableRealTimeScaling(); + + private slots: +-- +2.33.0 + diff --git a/kiran-qt5-integration.spec b/kiran-qt5-integration.spec index 26e7552..962eb16 100644 --- a/kiran-qt5-integration.spec +++ b/kiran-qt5-integration.spec @@ -1,6 +1,6 @@ Name: kiran-qt5-integration Version: 2.4.0 -Release: 13 +Release: 14 Summary: Kiran desktop platform integration plugin. License: MulanPSL-2.0 @@ -16,6 +16,7 @@ Patch0007: 0007-fix-style-add-ksl-server-gui-and-ks-scmc-gui-to-kira.patch Patch0008: 0008-fix-cmake-target-change-cmake-target-name.patch Patch0009: 0009-fix-qt5.9.7-fits-the-Qt5.9.7-interface.patch Patch0010: 0010-fix-style-add-ks-ssr-gui-to-white-list.patch +Patch0011: 0011-fix-theme-Fix-the-use-of-QApplication-class-for-plat.patch BuildRequires: cmake >= 3.2 BuildRequires: gcc-c++ @@ -71,6 +72,9 @@ make %{?_smp_mflags} %{_libdir}/pkgconfig/kiran-style-helper.pc %changelog +* Mon Dec 04 2023 liuxinhao - 2.4.0-14 +- KYOS-F: Fix the use of QApplication class for platform theme plugin errors + * Thu Nov 02 2023 liuxinhao - 2.4.0-13 - KYOS-B: add ks-ssr-gui to white list -- Gitee