Allow to configure style and color scheme on all platforms

PR #23522.
This commit is contained in:
Vladimir Golovnev
2025-11-24 09:04:28 +03:00
committed by GitHub
parent 4a3922d152
commit a77b17e6da
5 changed files with 18 additions and 26 deletions

View File

@@ -494,10 +494,17 @@ void Preferences::setWinStartup(const bool b)
settings.remove(profileID);
}
}
#endif // Q_OS_WIN
QString Preferences::getStyle() const
{
return value<QString>(u"Appearance/Style"_s);
#ifdef Q_OS_WIN
const QString defaultStyleName = u"Fusion"_s;
#else
const QString defaultStyleName = u"system"_s;
#endif
const auto styleName = value<QString>(u"Appearance/Style"_s);
return styleName.isEmpty() ? defaultStyleName : styleName;
}
void Preferences::setStyle(const QString &styleName)
@@ -507,7 +514,6 @@ void Preferences::setStyle(const QString &styleName)
setValue(u"Appearance/Style"_s, styleName);
}
#endif // Q_OS_WIN
// Downloads
Path Preferences::getScanDirsLastPath() const

View File

@@ -137,11 +137,11 @@ public:
void setPreventFromSuspendWhenDownloading(bool b);
bool preventFromSuspendWhenSeeding() const;
void setPreventFromSuspendWhenSeeding(bool b);
QString getStyle() const;
void setStyle(const QString &styleName);
#ifdef Q_OS_WIN
bool WinStartup() const;
void setWinStartup(bool b);
QString getStyle() const;
void setStyle(const QString &styleName);
#endif
// Downloads

View File

@@ -43,13 +43,10 @@
#include <QEvent>
#include <QFileDialog>
#include <QMessageBox>
#include <QStyleFactory>
#include <QSystemTrayIcon>
#include <QTranslator>
#ifdef Q_OS_WIN
#include <QStyleFactory>
#endif
#include "base/bittorrent/session.h"
#include "base/bittorrent/sharelimitaction.h"
#include "base/exceptions.h"
@@ -376,11 +373,7 @@ void OptionsDialog::loadBehaviorTabOptions()
m_ui->checkBoxPerformanceWarning->setChecked(session->isPerformanceWarningEnabled());
connect(m_ui->comboLanguage, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
#ifdef Q_OS_WIN
connect(m_ui->comboStyle, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
#endif
#ifdef QBT_HAS_COLORSCHEME_OPTION
connect(m_ui->comboColorScheme, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
#endif
@@ -488,9 +481,7 @@ void OptionsDialog::saveBehaviorTabOptions() const
}
pref->setLocale(locale);
#ifdef Q_OS_WIN
pref->setStyle(m_ui->comboStyle->currentData().toString());
#endif
#ifdef QBT_HAS_COLORSCHEME_OPTION
UIThemeManager::instance()->setColorScheme(m_ui->comboColorScheme->currentData().value<ColorScheme>());
@@ -1846,6 +1837,11 @@ void OptionsDialog::initializeStyleCombo()
#ifdef Q_OS_WIN
m_ui->labelStyleHint->setText(tr("%1 is recommended for best compatibility with Windows dark mode"
, "Fusion is recommended for best compatibility with Windows dark mode").arg(u"Fusion"_s));
#else
m_ui->labelStyleHint->hide();
m_ui->layoutStyle->removeWidget(m_ui->labelStyleHint);
#endif
m_ui->comboStyle->addItem(tr("System", "System default Qt style"), u"system"_s);
m_ui->comboStyle->setItemData(0, tr("Let Qt decide the style for this system"), Qt::ToolTipRole);
m_ui->comboStyle->insertSeparator(1);
@@ -1859,14 +1855,6 @@ void OptionsDialog::initializeStyleCombo()
const QString selectedStyleName = prefStyleName.isEmpty() ? QApplication::style()->name() : prefStyleName;
const int styleIndex = m_ui->comboStyle->findData(selectedStyleName, Qt::UserRole, Qt::MatchFixedString);
m_ui->comboStyle->setCurrentIndex(std::max(0, styleIndex));
#else
m_ui->labelStyle->hide();
m_ui->comboStyle->hide();
m_ui->labelStyleHint->hide();
m_ui->layoutStyle->removeWidget(m_ui->labelStyle);
m_ui->layoutStyle->removeWidget(m_ui->comboStyle);
m_ui->layoutStyle->removeWidget(m_ui->labelStyleHint);
#endif
}
void OptionsDialog::initializeColorSchemeOptions()

View File

@@ -76,13 +76,11 @@ UIThemeManager::UIThemeManager()
, m_useSystemIcons {Preferences::instance()->useSystemIcons()}
#endif
{
#ifdef Q_OS_WIN
if (const QString styleName = Preferences::instance()->getStyle(); styleName.compare(u"system", Qt::CaseInsensitive) != 0)
{
if (!QApplication::setStyle(styleName.isEmpty() ? u"Fusion"_s : styleName))
if (!QApplication::setStyle(styleName))
LogMsg(tr("Set app style failed. Unknown style: \"%1\"").arg(styleName), Log::WARNING);
}
#endif
#ifdef QBT_HAS_COLORSCHEME_OPTION
applyColorScheme();

View File

@@ -41,7 +41,7 @@
#include "uithemesource.h"
#if (QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)) && defined(Q_OS_WIN)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 8, 0))
#define QBT_HAS_COLORSCHEME_OPTION
#endif