mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 11:38:50 -07:00
parent
4805afc1a2
commit
a47e1cdb48
8 changed files with 163 additions and 4 deletions
|
@ -80,6 +80,9 @@ void UIThemeManager::initInstance()
|
|||
|
||||
UIThemeManager::UIThemeManager()
|
||||
: m_useCustomTheme {Preferences::instance()->useCustomUITheme()}
|
||||
#ifdef QBT_HAS_COLORSCHEME_OPTION
|
||||
, m_colorSchemeSetting {u"Appearance/ColorScheme"_s}
|
||||
#endif
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
|
||||
, m_useSystemIcons {Preferences::instance()->useSystemIcons()}
|
||||
#endif
|
||||
|
@ -90,6 +93,10 @@ UIThemeManager::UIThemeManager()
|
|||
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
|
||||
#endif
|
||||
|
||||
#ifdef QBT_HAS_COLORSCHEME_OPTION
|
||||
applyColorScheme();
|
||||
#endif
|
||||
|
||||
// NOTE: Qt::QueuedConnection can be omitted as soon as support for Qt 6.5 is dropped
|
||||
connect(QApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, &UIThemeManager::onColorSchemeChanged, Qt::QueuedConnection);
|
||||
|
||||
|
@ -125,6 +132,38 @@ UIThemeManager *UIThemeManager::instance()
|
|||
return m_instance;
|
||||
}
|
||||
|
||||
#ifdef QBT_HAS_COLORSCHEME_OPTION
|
||||
ColorScheme UIThemeManager::colorScheme() const
|
||||
{
|
||||
return m_colorSchemeSetting.get(ColorScheme::System);
|
||||
}
|
||||
|
||||
void UIThemeManager::setColorScheme(const ColorScheme value)
|
||||
{
|
||||
if (value == colorScheme())
|
||||
return;
|
||||
|
||||
m_colorSchemeSetting = value;
|
||||
}
|
||||
|
||||
void UIThemeManager::applyColorScheme() const
|
||||
{
|
||||
switch (colorScheme())
|
||||
{
|
||||
case ColorScheme::System:
|
||||
default:
|
||||
qApp->styleHints()->unsetColorScheme();
|
||||
break;
|
||||
case ColorScheme::Light:
|
||||
qApp->styleHints()->setColorScheme(Qt::ColorScheme::Light);
|
||||
break;
|
||||
case ColorScheme::Dark:
|
||||
qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void UIThemeManager::applyStyleSheet() const
|
||||
{
|
||||
qApp->setStyleSheet(QString::fromUtf8(m_themeSource->readStyleSheet()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue