From 55b3625c3a90d9ae51cd0fbbdd3d8442c0d43101 Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Thu, 6 Mar 2025 21:21:52 +0800 Subject: [PATCH 1/2] fix: fix build on Qt 6.8 Maybe start from 6.8.1 --- src/util/private/xdgiconproxyengine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/private/xdgiconproxyengine.cpp b/src/util/private/xdgiconproxyengine.cpp index 534fafcd..6f13987b 100644 --- a/src/util/private/xdgiconproxyengine.cpp +++ b/src/util/private/xdgiconproxyengine.cpp @@ -189,7 +189,11 @@ QPixmap XdgIconProxyEngine::pixmapByEntry(QIconLoaderEngineEntry *entry, const Q if (!XdgIconFollowColorScheme()) { DEEPIN_XDG_THEME::colorScheme.setLocalData(DEEPIN_XDG_THEME::PALETTE_MAP()); - return entry->pixmap(size, mode, state); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 1) + return entry->pixmap(size, mode, state, 1.0); +#else + return entry->pixmap(size, mode, state); +#endif } QPixmap pixmap; @@ -206,7 +210,11 @@ QPixmap XdgIconProxyEngine::pixmapByEntry(QIconLoaderEngineEntry *entry, const Q pixmap = followColorPixmap(static_cast(entry), size, mode, state); } else { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 1) + pixmap = entry->pixmap(size, mode, state, 1.0); +#else pixmap = entry->pixmap(size, mode, state); +#endif } free(type_name); From 5980ec4b0089e92358fa3f1b65c8adc0c5f180e0 Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Thu, 6 Mar 2025 21:17:08 +0800 Subject: [PATCH 2/2] feat: use dconfig2cpp for read/write the DConfig The org.deepin.dtk.preference.json file is not in this project, so we can't generated codes by cmake. --- .reuse/dep5 | 3 + src/kernel/dguiapplicationhelper.cpp | 22 +- src/kernel/dplatformtheme.cpp | 33 +- src/kernel/kernel.cmake | 1 + src/kernel/orgdeepindtkpreference.hpp | 742 ++++++++++++++++++++++++++ src/private/dplatformtheme_p.h | 8 +- 6 files changed, 771 insertions(+), 38 deletions(-) create mode 100644 src/kernel/orgdeepindtkpreference.hpp diff --git a/.reuse/dep5 b/.reuse/dep5 index 29142afa..ac7495ab 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -63,3 +63,6 @@ Files: toolGenerate/**/* Copyright: None License: CC0-1.0 +Files: src/kernel/orgdeepindtkpreference.hpp +Copyright: None +License: CC0-1.0 diff --git a/src/kernel/dguiapplicationhelper.cpp b/src/kernel/dguiapplicationhelper.cpp index 578b316b..014b76ed 100644 --- a/src/kernel/dguiapplicationhelper.cpp +++ b/src/kernel/dguiapplicationhelper.cpp @@ -5,8 +5,10 @@ #include "dguiapplicationhelper.h" #include "private/dguiapplicationhelper_p.h" #include "dplatformhandle.h" + #include #include +#include #include #include @@ -34,7 +36,6 @@ #include #include #include -#include #endif #include #include @@ -61,6 +62,8 @@ #include #endif +#include "orgdeepindtkpreference.hpp" + #ifdef Q_OS_UNIX class EnvReplaceGuard { @@ -115,10 +118,9 @@ Q_GLOBAL_STATIC(DFontManager, _globalFM) #define WINDOW_THEME_KEY "_d_platform_theme" -#define APP_THEME_TYPE "themeType" -#define DTK_ENABLE_ANIMATIONS "enableDtkAnimations" #define DTK_ANIMATIONS_ENV "D_DTK_DISABLE_ANIMATIONS" -Q_GLOBAL_STATIC_WITH_ARGS(DTK_CORE_NAMESPACE::DConfig, _d_dconfig, ("org.deepin.dtk.preference")); +Q_GLOBAL_STATIC(OrgDeepinDTKPreference, _d_dconfig, DTK_CORE_NAMESPACE::DConfig::globalThread(), nullptr, + "org.deepin.dtk.preference", DTK_CORE_NAMESPACE::DSGApplication::id(), {}, false, nullptr) /*! @private @@ -445,7 +447,7 @@ void DGuiApplicationHelperPrivate::initPaletteType() const return; auto applyThemeType = [this](bool emitSignal){ - int ct = _d_dconfig->value(APP_THEME_TYPE, DGuiApplicationHelper::UnknownType).toInt(); + int ct = _d_dconfig->themeType(); if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType) ct = DGuiApplicationHelper::UnknownType; @@ -454,10 +456,7 @@ void DGuiApplicationHelperPrivate::initPaletteType() const applyThemeType(false); - QObject::connect(_d_dconfig, &DConfig::valueChanged, _d_dconfig, [applyThemeType](const QString &key){ - if (key != APP_THEME_TYPE) - return; - + QObject::connect(_d_dconfig.operator ()(), &OrgDeepinDTKPreference::themeTypeChanged, _d_dconfig, [applyThemeType] { applyThemeType(true); }); } @@ -1781,8 +1780,7 @@ bool DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::Attribute attri if (isDisable) return false; - static bool shouldEnable = _d_dconfig->value(DTK_ENABLE_ANIMATIONS, false).toBool(); - return shouldEnable; + return _d_dconfig->enableDtkAnimations(); } default: return DGuiApplicationHelperPrivate::attributes.testFlag(attribute); @@ -1823,7 +1821,7 @@ void DGuiApplicationHelper::setPaletteType(DGuiApplicationHelper::ColorType pale d->initPaletteType(); d->setPaletteType(paletteType, true); - _d_dconfig->setValue(APP_THEME_TYPE, paletteType); + _d_dconfig->setThemeType(static_cast(paletteType)); } /*! diff --git a/src/kernel/dplatformtheme.cpp b/src/kernel/dplatformtheme.cpp index 059519bd..275093f4 100644 --- a/src/kernel/dplatformtheme.cpp +++ b/src/kernel/dplatformtheme.cpp @@ -13,18 +13,15 @@ #include "plugins/platform/treeland/dtreelandplatforminterface.h" #endif #include "private/dplatforminterface_p.h" +#include "orgdeepindtkpreference.hpp" #include #include #include #include #include -#include DGUI_BEGIN_NAMESPACE -#define DTK_PREFERENCE_NAME "org.deepin.dtk.preference" -#define DTK_SIZE_MODE_KEY "sizeMode" -#define DTK_SCROLLBAR_POLICY_KEY "scrollBarPolicy" static DPlatformInterfaceFactory::HelperCreator OutsideInterfaceCreator = nullptr; @@ -78,18 +75,6 @@ void DPlatformThemePrivate::notifyPaletteChanged() notifyPaletteChangeTimer->start(300); } -void DPlatformThemePrivate::onDtkPreferenceDConfigChanged(const QString &key) -{ - D_Q(DPlatformTheme); - if (key == DTK_SIZE_MODE_KEY) { - sizeMode = static_cast(dtkPreferenceConfig->value(key).toInt()); - Q_EMIT q->sizeModeChanged(sizeMode); - } else if (key == DTK_SCROLLBAR_POLICY_KEY) { - scrollBarPolicy = static_cast(dtkPreferenceConfig->value(key).toInt()); - Q_EMIT q->scrollBarPolicyChanged(scrollBarPolicy); - } -} - /*! \class Dtk::Gui::DPlatformTheme \inmodule dtkgui @@ -125,12 +110,18 @@ DPlatformTheme::DPlatformTheme(quint32 window, QObject *parent) d->theme = new DNativeSettings(window, QByteArray(), this); - d->dtkPreferenceConfig = DConfig::createGeneric(DTK_PREFERENCE_NAME, "", this); - d->sizeMode = static_cast(d->dtkPreferenceConfig->value(DTK_SIZE_MODE_KEY).toInt()); - d->scrollBarPolicy = static_cast(d->dtkPreferenceConfig->value(DTK_SCROLLBAR_POLICY_KEY).toInt()); - connect(d->dtkPreferenceConfig, &DConfig::valueChanged, this, [this](const QString &key) -> void{ + d->dtkPreferenceConfig = OrgDeepinDTKPreference::createGeneric("", this); + d->sizeMode = static_cast(d->dtkPreferenceConfig->sizeMode()); + d->scrollBarPolicy = static_cast(d->dtkPreferenceConfig->scrollBarPolicy()); + connect(d->dtkPreferenceConfig, &OrgDeepinDTKPreference::sizeModeChanged, this, [this] { + D_D(DPlatformTheme); + d->sizeMode = static_cast(d->dtkPreferenceConfig->sizeMode()); + Q_EMIT sizeModeChanged(d->sizeMode); + }); + connect(d->dtkPreferenceConfig, &OrgDeepinDTKPreference::scrollBarPolicyChanged, this, [this] { D_D(DPlatformTheme); - d->onDtkPreferenceDConfigChanged(key); + d->scrollBarPolicy = static_cast(d->dtkPreferenceConfig->scrollBarPolicy()); + Q_EMIT scrollBarPolicyChanged(d->scrollBarPolicy); }); #if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) diff --git a/src/kernel/kernel.cmake b/src/kernel/kernel.cmake index 976ea65f..5cb4cc32 100644 --- a/src/kernel/kernel.cmake +++ b/src/kernel/kernel.cmake @@ -7,4 +7,5 @@ file(GLOB KERNEL_SOURCE set(kernel_SRC ${KERNEL_HEADER} ${KERNEL_SOURCE} + ${CMAKE_CURRENT_LIST_DIR}/orgdeepindtkpreference.hpp ) diff --git a/src/kernel/orgdeepindtkpreference.hpp b/src/kernel/orgdeepindtkpreference.hpp new file mode 100644 index 00000000..126e5f66 --- /dev/null +++ b/src/kernel/orgdeepindtkpreference.hpp @@ -0,0 +1,742 @@ +/** + * This file is generated by dconfig2cpp. + * Command line arguments: /home/zccrs/projects/dtkcore/build/unknown-Debug/tools/dconfig2cpp/dconfig2cpp -c OrgDeepinDTKPreference /usr/share/dsg/configs/org.deepin.dtk.preference.json + * Generation time: 2025-03-06T20:56:26 + * JSON file version: 1.0 + * + * WARNING: DO NOT MODIFY THIS FILE MANUALLY. + * If you need to change the content, please modify the dconfig2cpp tool. + */ + +#ifndef ORGDEEPINDTKPREFERENCE_H +#define ORGDEEPINDTKPREFERENCE_H + +#include +#include +#include +#include +#include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif +#include +#include + +class OrgDeepinDTKPreference : public QObject { + Q_OBJECT + + Q_PROPERTY(bool autoDisplayFeature READ autoDisplayFeature WRITE setAutoDisplayFeature NOTIFY autoDisplayFeatureChanged RESET resetAutoDisplayFeature) + Q_PROPERTY(bool enableDtkAnimations READ enableDtkAnimations WRITE setEnableDtkAnimations NOTIFY enableDtkAnimationsChanged RESET resetEnableDtkAnimations) + Q_PROPERTY(bool featureUpdated READ featureUpdated WRITE setFeatureUpdated NOTIFY featureUpdatedChanged RESET resetFeatureUpdated) + Q_PROPERTY(bool keyboardsearchDisabled READ keyboardsearchDisabled WRITE setKeyboardsearchDisabled NOTIFY keyboardsearchDisabledChanged RESET resetKeyboardsearchDisabled) + Q_PROPERTY(QString rules READ rules WRITE setRules NOTIFY rulesChanged RESET resetRules) + Q_PROPERTY(qlonglong scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy NOTIFY scrollBarPolicyChanged RESET resetScrollBarPolicy) + Q_PROPERTY(qlonglong sizeMode READ sizeMode WRITE setSizeMode NOTIFY sizeModeChanged RESET resetSizeMode) + Q_PROPERTY(qlonglong themeType READ themeType WRITE setThemeType NOTIFY themeTypeChanged RESET resetThemeType) + Q_PROPERTY(qlonglong titlebarHeight READ titlebarHeight WRITE setTitlebarHeight NOTIFY titlebarHeightChanged RESET resetTitlebarHeight) + Q_PROPERTY(bool underlineShortcut READ underlineShortcut WRITE setUnderlineShortcut NOTIFY underlineShortcutChanged RESET resetUnderlineShortcut) + Q_CLASSINFO("DConfigKeyList", "autoDisplayFeature;enableDtkAnimations;featureUpdated;keyboardsearchDisabled;rules;scrollBarPolicy;sizeMode;themeType;titlebarHeight;underlineShortcut") + Q_CLASSINFO("DConfigFileName", "org.deepin.dtk.preference") + Q_CLASSINFO("DConfigFileVersion", "1.0") + +public: + explicit OrgDeepinDTKPreference(QThread *thread, DTK_CORE_NAMESPACE::DConfigBackend *backend, + const QString &name, const QString &appId, const QString &subpath, + bool isGeneric, QObject *parent) + : QObject(parent) { + if (!thread->isRunning()) { + qWarning() << QLatin1String("Warning: The provided thread is not running."); + } + Q_ASSERT(QThread::currentThread() != thread); + auto worker = new QObject(); + worker->moveToThread(thread); + QMetaObject::invokeMethod(worker, [=, this]() { + DTK_CORE_NAMESPACE::DConfig *config = nullptr; + if (isGeneric) { + if (backend) { + config = DTK_CORE_NAMESPACE::DConfig::createGeneric(backend, name, subpath, nullptr); + } else { + config = DTK_CORE_NAMESPACE::DConfig::createGeneric(name, subpath, nullptr); + } + } else { + if (backend) { + if (appId.isNull()) { + config = DTK_CORE_NAMESPACE::DConfig::create(backend, DTK_CORE_NAMESPACE::DSGApplication::id(), + name, subpath, nullptr); + } else { + config = DTK_CORE_NAMESPACE::DConfig::create(backend, appId, name, subpath, nullptr); + } + } else { + if (appId.isNull()) { + config = DTK_CORE_NAMESPACE::DConfig::create(DTK_CORE_NAMESPACE::DSGApplication::id(), + name, subpath, nullptr); + } else { + config = DTK_CORE_NAMESPACE::DConfig::create(appId, name, subpath, nullptr); + } + } + } + if (!config) { + qWarning() << QLatin1String("Failed to create DConfig instance."); + worker->deleteLater(); + return; + } + config->moveToThread(QThread::currentThread()); + initializeInConfigThread(config); + worker->deleteLater(); + }); + } + static OrgDeepinDTKPreference* create(const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); } + static OrgDeepinDTKPreference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), appId, subpath, false, parent); } + static OrgDeepinDTKPreference* createByName(const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, nullptr, name, appId, subpath, false, parent); } + static OrgDeepinDTKPreference* createByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &appId = {}, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, backend, name, appId, subpath, false, parent); } + static OrgDeepinDTKPreference* createGeneric(const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, nullptr, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); } + static OrgDeepinDTKPreference* create(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, backend, QStringLiteral(u"\u006f\u0072\u0067\u002e\u0064\u0065\u0065\u0070\u0069\u006e\u002e\u0064\u0074\u006b\u002e\u0070\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065"), {}, subpath, true, parent); } + static OrgDeepinDTKPreference* createGenericByName(const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, nullptr, name, {}, subpath, true, parent); } + static OrgDeepinDTKPreference* createGenericByName(DTK_CORE_NAMESPACE::DConfigBackend *backend, const QString &name, const QString &subpath = {}, QObject *parent = nullptr, QThread *thread = DTK_CORE_NAMESPACE::DConfig::globalThread()) + { return new OrgDeepinDTKPreference(thread, backend, name, {}, subpath, true, parent); } + ~OrgDeepinDTKPreference() { + if (m_config.loadRelaxed()) { + m_config.loadRelaxed()->deleteLater(); + } + } + + Q_INVOKABLE DTK_CORE_NAMESPACE::DConfig *config() const { + return m_config.loadRelaxed(); + } + + Q_INVOKABLE bool isInitializeSucceed() const { + return m_status.loadRelaxed() == static_cast(Status::Succeed); + } + + Q_INVOKABLE bool isInitializeFailed() const { + return m_status.loadRelaxed() == static_cast(Status::Failed); + } + + Q_INVOKABLE bool isInitializing() const { + return m_status.loadRelaxed() == static_cast(Status::Invalid); + } + + Q_INVOKABLE QStringList keyList() const { + return { QStringLiteral("autoDisplayFeature"), + QStringLiteral("enableDtkAnimations"), + QStringLiteral("featureUpdated"), + QStringLiteral("keyboardsearchDisabled"), + QStringLiteral("rules"), + QStringLiteral("scrollBarPolicy"), + QStringLiteral("sizeMode"), + QStringLiteral("themeType"), + QStringLiteral("titlebarHeight"), + QStringLiteral("underlineShortcut")}; + } + + Q_INVOKABLE bool isDefaultValue(const QString &key) const { + if (key == QStringLiteral("autoDisplayFeature")) + return autoDisplayFeatureIsDefaultValue(); + if (key == QStringLiteral("enableDtkAnimations")) + return enableDtkAnimationsIsDefaultValue(); + if (key == QStringLiteral("featureUpdated")) + return featureUpdatedIsDefaultValue(); + if (key == QStringLiteral("keyboardsearchDisabled")) + return keyboardsearchDisabledIsDefaultValue(); + if (key == QStringLiteral("rules")) + return rulesIsDefaultValue(); + if (key == QStringLiteral("scrollBarPolicy")) + return scrollBarPolicyIsDefaultValue(); + if (key == QStringLiteral("sizeMode")) + return sizeModeIsDefaultValue(); + if (key == QStringLiteral("themeType")) + return themeTypeIsDefaultValue(); + if (key == QStringLiteral("titlebarHeight")) + return titlebarHeightIsDefaultValue(); + if (key == QStringLiteral("underlineShortcut")) + return underlineShortcutIsDefaultValue(); + return false; + } + + bool autoDisplayFeature() const { + return p_autoDisplayFeature; + } + void setAutoDisplayFeature(const bool &value) { + auto oldValue = p_autoDisplayFeature; + p_autoDisplayFeature = value; + markPropertySet(0); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("autoDisplayFeature"), value); + }); + } + if (p_autoDisplayFeature != oldValue) { + Q_EMIT autoDisplayFeatureChanged(); + Q_EMIT valueChanged(QStringLiteral("autoDisplayFeature"), value); + } + } + void resetAutoDisplayFeature() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("autoDisplayFeature")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableAutoDisplayFeature() { + return QBindable(this, "autoDisplayFeature"); + } +#endif + Q_INVOKABLE bool autoDisplayFeatureIsDefaultValue() const { + return !testPropertySet(0); + } + bool enableDtkAnimations() const { + return p_enableDtkAnimations; + } + void setEnableDtkAnimations(const bool &value) { + auto oldValue = p_enableDtkAnimations; + p_enableDtkAnimations = value; + markPropertySet(1); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("enableDtkAnimations"), value); + }); + } + if (p_enableDtkAnimations != oldValue) { + Q_EMIT enableDtkAnimationsChanged(); + Q_EMIT valueChanged(QStringLiteral("enableDtkAnimations"), value); + } + } + void resetEnableDtkAnimations() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("enableDtkAnimations")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableEnableDtkAnimations() { + return QBindable(this, "enableDtkAnimations"); + } +#endif + Q_INVOKABLE bool enableDtkAnimationsIsDefaultValue() const { + return !testPropertySet(1); + } + bool featureUpdated() const { + return p_featureUpdated; + } + void setFeatureUpdated(const bool &value) { + auto oldValue = p_featureUpdated; + p_featureUpdated = value; + markPropertySet(2); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("featureUpdated"), value); + }); + } + if (p_featureUpdated != oldValue) { + Q_EMIT featureUpdatedChanged(); + Q_EMIT valueChanged(QStringLiteral("featureUpdated"), value); + } + } + void resetFeatureUpdated() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("featureUpdated")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableFeatureUpdated() { + return QBindable(this, "featureUpdated"); + } +#endif + Q_INVOKABLE bool featureUpdatedIsDefaultValue() const { + return !testPropertySet(2); + } + bool keyboardsearchDisabled() const { + return p_keyboardsearchDisabled; + } + void setKeyboardsearchDisabled(const bool &value) { + auto oldValue = p_keyboardsearchDisabled; + p_keyboardsearchDisabled = value; + markPropertySet(3); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("keyboardsearchDisabled"), value); + }); + } + if (p_keyboardsearchDisabled != oldValue) { + Q_EMIT keyboardsearchDisabledChanged(); + Q_EMIT valueChanged(QStringLiteral("keyboardsearchDisabled"), value); + } + } + void resetKeyboardsearchDisabled() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("keyboardsearchDisabled")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableKeyboardsearchDisabled() { + return QBindable(this, "keyboardsearchDisabled"); + } +#endif + Q_INVOKABLE bool keyboardsearchDisabledIsDefaultValue() const { + return !testPropertySet(3); + } + QString rules() const { + return p_rules; + } + void setRules(const QString &value) { + auto oldValue = p_rules; + p_rules = value; + markPropertySet(4); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("rules"), value); + }); + } + if (p_rules != oldValue) { + Q_EMIT rulesChanged(); + Q_EMIT valueChanged(QStringLiteral("rules"), value); + } + } + void resetRules() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("rules")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableRules() { + return QBindable(this, "rules"); + } +#endif + Q_INVOKABLE bool rulesIsDefaultValue() const { + return !testPropertySet(4); + } + qlonglong scrollBarPolicy() const { + return p_scrollBarPolicy; + } + void setScrollBarPolicy(const qlonglong &value) { + auto oldValue = p_scrollBarPolicy; + p_scrollBarPolicy = value; + markPropertySet(5); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("scrollBarPolicy"), value); + }); + } + if (p_scrollBarPolicy != oldValue) { + Q_EMIT scrollBarPolicyChanged(); + Q_EMIT valueChanged(QStringLiteral("scrollBarPolicy"), value); + } + } + void resetScrollBarPolicy() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("scrollBarPolicy")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableScrollBarPolicy() { + return QBindable(this, "scrollBarPolicy"); + } +#endif + Q_INVOKABLE bool scrollBarPolicyIsDefaultValue() const { + return !testPropertySet(5); + } + qlonglong sizeMode() const { + return p_sizeMode; + } + void setSizeMode(const qlonglong &value) { + auto oldValue = p_sizeMode; + p_sizeMode = value; + markPropertySet(6); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("sizeMode"), value); + }); + } + if (p_sizeMode != oldValue) { + Q_EMIT sizeModeChanged(); + Q_EMIT valueChanged(QStringLiteral("sizeMode"), value); + } + } + void resetSizeMode() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("sizeMode")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableSizeMode() { + return QBindable(this, "sizeMode"); + } +#endif + Q_INVOKABLE bool sizeModeIsDefaultValue() const { + return !testPropertySet(6); + } + qlonglong themeType() const { + return p_themeType; + } + void setThemeType(const qlonglong &value) { + auto oldValue = p_themeType; + p_themeType = value; + markPropertySet(7); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("themeType"), value); + }); + } + if (p_themeType != oldValue) { + Q_EMIT themeTypeChanged(); + Q_EMIT valueChanged(QStringLiteral("themeType"), value); + } + } + void resetThemeType() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("themeType")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableThemeType() { + return QBindable(this, "themeType"); + } +#endif + Q_INVOKABLE bool themeTypeIsDefaultValue() const { + return !testPropertySet(7); + } + qlonglong titlebarHeight() const { + return p_titlebarHeight; + } + void setTitlebarHeight(const qlonglong &value) { + auto oldValue = p_titlebarHeight; + p_titlebarHeight = value; + markPropertySet(8); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("titlebarHeight"), value); + }); + } + if (p_titlebarHeight != oldValue) { + Q_EMIT titlebarHeightChanged(); + Q_EMIT valueChanged(QStringLiteral("titlebarHeight"), value); + } + } + void resetTitlebarHeight() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("titlebarHeight")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableTitlebarHeight() { + return QBindable(this, "titlebarHeight"); + } +#endif + Q_INVOKABLE bool titlebarHeightIsDefaultValue() const { + return !testPropertySet(8); + } + bool underlineShortcut() const { + return p_underlineShortcut; + } + void setUnderlineShortcut(const bool &value) { + auto oldValue = p_underlineShortcut; + p_underlineShortcut = value; + markPropertySet(9); + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this, value]() { + m_config.loadRelaxed()->setValue(QStringLiteral("underlineShortcut"), value); + }); + } + if (p_underlineShortcut != oldValue) { + Q_EMIT underlineShortcutChanged(); + Q_EMIT valueChanged(QStringLiteral("underlineShortcut"), value); + } + } + void resetUnderlineShortcut() { + if (auto config = m_config.loadRelaxed()) { + QMetaObject::invokeMethod(config, [this]() { + m_config.loadRelaxed()->reset(QStringLiteral("underlineShortcut")); + }); + } + } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QBindable bindableUnderlineShortcut() { + return QBindable(this, "underlineShortcut"); + } +#endif + Q_INVOKABLE bool underlineShortcutIsDefaultValue() const { + return !testPropertySet(9); + } +Q_SIGNALS: + void configInitializeFailed(DTK_CORE_NAMESPACE::DConfig *config); + void configInitializeSucceed(DTK_CORE_NAMESPACE::DConfig *config); + void valueChanged(const QString &key, const QVariant &value); + + void autoDisplayFeatureChanged(); + void enableDtkAnimationsChanged(); + void featureUpdatedChanged(); + void keyboardsearchDisabledChanged(); + void rulesChanged(); + void scrollBarPolicyChanged(); + void sizeModeChanged(); + void themeTypeChanged(); + void titlebarHeightChanged(); + void underlineShortcutChanged(); +private: + void initializeInConfigThread(DTK_CORE_NAMESPACE::DConfig *config) { + Q_ASSERT(!m_config.loadRelaxed()); + m_config.storeRelaxed(config); + if (!config->isValid()) { + m_status.storeRelaxed(static_cast(Status::Failed)); + Q_EMIT configInitializeFailed(config); + return; + } + + if (testPropertySet(0)) { + config->setValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature)); + } else { + updateValue(QStringLiteral("autoDisplayFeature"), QVariant::fromValue(p_autoDisplayFeature)); + } + if (testPropertySet(1)) { + config->setValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations)); + } else { + updateValue(QStringLiteral("enableDtkAnimations"), QVariant::fromValue(p_enableDtkAnimations)); + } + if (testPropertySet(2)) { + config->setValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated)); + } else { + updateValue(QStringLiteral("featureUpdated"), QVariant::fromValue(p_featureUpdated)); + } + if (testPropertySet(3)) { + config->setValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled)); + } else { + updateValue(QStringLiteral("keyboardsearchDisabled"), QVariant::fromValue(p_keyboardsearchDisabled)); + } + if (testPropertySet(4)) { + config->setValue(QStringLiteral("rules"), QVariant::fromValue(p_rules)); + } else { + updateValue(QStringLiteral("rules"), QVariant::fromValue(p_rules)); + } + if (testPropertySet(5)) { + config->setValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy)); + } else { + updateValue(QStringLiteral("scrollBarPolicy"), QVariant::fromValue(p_scrollBarPolicy)); + } + if (testPropertySet(6)) { + config->setValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode)); + } else { + updateValue(QStringLiteral("sizeMode"), QVariant::fromValue(p_sizeMode)); + } + if (testPropertySet(7)) { + config->setValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType)); + } else { + updateValue(QStringLiteral("themeType"), QVariant::fromValue(p_themeType)); + } + if (testPropertySet(8)) { + config->setValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight)); + } else { + updateValue(QStringLiteral("titlebarHeight"), QVariant::fromValue(p_titlebarHeight)); + } + if (testPropertySet(9)) { + config->setValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut)); + } else { + updateValue(QStringLiteral("underlineShortcut"), QVariant::fromValue(p_underlineShortcut)); + } + + connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) { + updateValue(key); + }, Qt::DirectConnection); + + m_status.storeRelaxed(static_cast(Status::Succeed)); + Q_EMIT configInitializeSucceed(config); + } + void updateValue(const QString &key, const QVariant &fallback = QVariant()) { + Q_ASSERT(QThread::currentThread() == m_config.loadRelaxed()->thread()); + const QVariant &value = m_config.loadRelaxed()->value(key, fallback); + if (key == QStringLiteral("autoDisplayFeature")) { + markPropertySet(0, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_autoDisplayFeature != newValue) { + p_autoDisplayFeature = newValue; + Q_EMIT autoDisplayFeatureChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("enableDtkAnimations")) { + markPropertySet(1, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_enableDtkAnimations != newValue) { + p_enableDtkAnimations = newValue; + Q_EMIT enableDtkAnimationsChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("featureUpdated")) { + markPropertySet(2, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_featureUpdated != newValue) { + p_featureUpdated = newValue; + Q_EMIT featureUpdatedChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("keyboardsearchDisabled")) { + markPropertySet(3, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_keyboardsearchDisabled != newValue) { + p_keyboardsearchDisabled = newValue; + Q_EMIT keyboardsearchDisabledChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("rules")) { + markPropertySet(4, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_rules != newValue) { + p_rules = newValue; + Q_EMIT rulesChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("scrollBarPolicy")) { + markPropertySet(5, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_scrollBarPolicy != newValue) { + p_scrollBarPolicy = newValue; + Q_EMIT scrollBarPolicyChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("sizeMode")) { + markPropertySet(6, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_sizeMode != newValue) { + p_sizeMode = newValue; + Q_EMIT sizeModeChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("themeType")) { + markPropertySet(7, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_themeType != newValue) { + p_themeType = newValue; + Q_EMIT themeTypeChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("titlebarHeight")) { + markPropertySet(8, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_titlebarHeight != newValue) { + p_titlebarHeight = newValue; + Q_EMIT titlebarHeightChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + if (key == QStringLiteral("underlineShortcut")) { + markPropertySet(9, !m_config.loadRelaxed()->isDefaultValue(key)); + auto newValue = qvariant_cast(value); + QMetaObject::invokeMethod(this, [this, newValue, key, value]() { + Q_ASSERT(QThread::currentThread() == this->thread()); + if (p_underlineShortcut != newValue) { + p_underlineShortcut = newValue; + Q_EMIT underlineShortcutChanged(); + Q_EMIT valueChanged(key, value); + } + }); + return; + } + } + inline void markPropertySet(const int index, bool on = true) { + if (index < 32) { + if (on) + m_propertySetStatus0.fetchAndOrOrdered(1 << (index - 0)); + else + m_propertySetStatus0.fetchAndAndOrdered(1 << (index - 0)); + return; + } + Q_UNREACHABLE(); + } + inline bool testPropertySet(const int index) const { + if (index < 32) { + return (m_propertySetStatus0.loadRelaxed() & (1 << (index - 0))); + } + Q_UNREACHABLE(); + } + + QAtomicPointer m_config = nullptr; + +public: + enum class Status { + Invalid = 0, + Succeed = 1, + Failed = 2 + }; +private: + QAtomicInteger m_status = static_cast(Status::Invalid); + + bool p_autoDisplayFeature { false }; + bool p_enableDtkAnimations { false }; + bool p_featureUpdated { false }; + bool p_keyboardsearchDisabled { false }; + // Default value: "" + QString p_rules { QLatin1String("") }; + qlonglong p_scrollBarPolicy { 0 }; + qlonglong p_sizeMode { 0 }; + qlonglong p_themeType { 0 }; + qlonglong p_titlebarHeight { -1 }; + bool p_underlineShortcut { false }; + QAtomicInteger m_propertySetStatus0 = 0; +}; + +#endif // ORGDEEPINDTKPREFERENCE_H diff --git a/src/private/dplatformtheme_p.h b/src/private/dplatformtheme_p.h index 658c4359..cdf0a80e 100644 --- a/src/private/dplatformtheme_p.h +++ b/src/private/dplatformtheme_p.h @@ -9,9 +9,10 @@ #include "dplatformtheme.h" #include "dnativesettings_p.h" -#include #include +class OrgDeepinDTKPreference; + DCORE_USE_NAMESPACE DGUI_BEGIN_NAMESPACE @@ -38,15 +39,12 @@ class DPlatformThemePrivate : public DNativeSettingsPrivate DPalette *palette = nullptr; // 减少调色板changed信号的通知频率 QTimer *notifyPaletteChangeTimer = nullptr; - DConfig *dtkPreferenceConfig = nullptr; + OrgDeepinDTKPreference *dtkPreferenceConfig = nullptr; DPlatformInterface *platformInterface = nullptr; DGuiApplicationHelper::SizeMode sizeMode = DGuiApplicationHelper::NormalMode; Qt::ScrollBarPolicy scrollBarPolicy = Qt::ScrollBarAsNeeded; - -public slots: - void onDtkPreferenceDConfigChanged(const QString &key); }; DGUI_END_NAMESPACE