This action will force synchronization from 梦起丶/HuskarUI, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#include "delsystemthemehelper.h"#include <QBasicTimer>#include <QWindow>#include <QSettings>#include <QLibrary>#ifdef QT_WIDGETS_LIB# include <QWidget>#endif //QT_WIDGETS_LIB#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)# include <QGuiApplication># include <QStyleHints>#endif#ifdef Q_OS_WIN#include <Windows.h>using DwmSetWindowAttributeFunc = HRESULT(WINAPI *)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);static DwmSetWindowAttributeFunc pDwmSetWindowAttribute = nullptr;static inline bool initializeFunctionPointers() {static bool initialized = false;if (!initialized) {HMODULE module = LoadLibraryW(L"dwmapi.dll");if (module) {if (!pDwmSetWindowAttribute) {pDwmSetWindowAttribute = reinterpret_cast<DwmSetWindowAttributeFunc>(GetProcAddress(module, "DwmSetWindowAttribute"));if (!pDwmSetWindowAttribute) {return false;}}initialized = true;}}return initialized;}#else //Q_OS_LINUX# include <QPalette>#endif //Q_OS_WINclass DelSystemThemeHelperPrivate{public:DelSystemThemeHelperPrivate(DelSystemThemeHelper *q) : q_ptr(q) { }Q_DECLARE_PUBLIC(DelSystemThemeHelper);void _updateThemeColor() {Q_Q(DelSystemThemeHelper);auto nowThemeColor = q->getThemeColor();if (nowThemeColor != m_themeColor) {m_themeColor = nowThemeColor;emit q->themeColorChanged(nowThemeColor);}}void _updateColorScheme() {Q_Q(DelSystemThemeHelper);auto nowColorScheme = q->getColorScheme() ;if (nowColorScheme != m_colorScheme) {m_colorScheme = nowColorScheme;emit q->colorSchemeChanged(nowColorScheme);}}DelSystemThemeHelper *q_ptr;QColor m_themeColor;DelSystemThemeHelper::ColorScheme m_colorScheme = DelSystemThemeHelper::ColorScheme::None;QBasicTimer m_timer;#ifdef Q_OS_WINQSettings m_themeColorSettings { QSettings::UserScope, "Microsoft", "Windows\\DWM" };QSettings m_colorSchemeSettings { QSettings::UserScope, "Microsoft", "Windows\\CurrentVersion\\Themes\\Personalize" };#endif};DelSystemThemeHelper::DelSystemThemeHelper(QObject *parent): QObject{ parent }, d_ptr(new DelSystemThemeHelperPrivate(this)){Q_D(DelSystemThemeHelper);d->m_themeColor = getThemeColor();d->m_colorScheme = getColorScheme();d->m_timer.start(200, this);#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, [this](Qt::ColorScheme scheme){emit colorSchemeChanged(scheme == Qt::ColorScheme::Dark ? ColorScheme::Dark : ColorScheme::Light);});#endif#ifdef Q_OS_WINinitializeFunctionPointers();#endif}DelSystemThemeHelper::~DelSystemThemeHelper(){}QColor DelSystemThemeHelper::getThemeColor() const{Q_D(const DelSystemThemeHelper);#ifdef Q_OS_WINreturn QColor::fromRgb(d->m_themeColorSettings.value("ColorizationColor").toUInt());#elsereturn QPalette().color(QPalette::Highlight);#endif}DelSystemThemeHelper::ColorScheme DelSystemThemeHelper::getColorScheme() const{Q_D(const DelSystemThemeHelper);#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)const auto scheme = QGuiApplication::styleHints()->colorScheme();return scheme == Qt::ColorScheme::Dark ? ColorScheme::Dark : ColorScheme::Light;#else#ifdef Q_OS_WIN/*! 0:深色 - 1:浅色 */return !d->m_colorSchemeSettings.value("AppsUseLightTheme").toBool() ? ColorScheme::Dark : ColorScheme::Light;#else //linuxconst QPalette defaultPalette;const auto text = defaultPalette.color(QPalette::WindowText);const auto window = defaultPalette.color(QPalette::Window);return text.lightness() > window.lightness() ? ColorScheme::Dark : ColorScheme::Light;#endif // Q_OS_WIN#endif // QT_VERSION}QColor DelSystemThemeHelper::themeColor(){Q_D(DelSystemThemeHelper);d->_updateThemeColor();return d->m_themeColor;}DelSystemThemeHelper::ColorScheme DelSystemThemeHelper::colorScheme(){Q_D(DelSystemThemeHelper);d->_updateColorScheme();return d->m_colorScheme;}bool DelSystemThemeHelper::setWindowTitleBarMode(QWindow *window, bool isDark){#ifdef Q_OS_WINreturn bool(pDwmSetWindowAttribute ? !pDwmSetWindowAttribute(HWND(window->winId()), 20, &isDark, sizeof(BOOL)) : false);#elsereturn false;#endif //Q_OS_WIN}#ifdef QT_WIDGETS_LIBbool DelSystemThemeHelper::setWindowTitleBarMode(QWidget *window, bool isDark){#ifdef Q_OS_WINreturn bool(pDwmSetWindowAttribute ? !pDwmSetWindowAttribute(HWND(window->winId()), 20, &isDark, sizeof(BOOL)) : false);#elsereturn false;#endif //Q_OS_WIN}#endif //QT_WIDGETS_LIBvoid DelSystemThemeHelper::timerEvent(QTimerEvent *){Q_D(DelSystemThemeHelper);d->_updateThemeColor();#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)d->_updateColorScheme();#endif}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。