DolphinQt/Settings: Split setting of the user style into two functions.
This makes it so that if you just want to reload the current style (eg. on program start, or in response to a system event), you don't need to know the name of the currently selected user style. It's also more consistent with the way the 'userstyle/enabled' flag works.
This commit is contained in:
parent
9d08c8a45d
commit
6d585b6eb6
|
@ -133,7 +133,7 @@ void BalloonTip::UpdateBoundsAndRedraw(const QPoint& pos, ShowArrow show_arrow)
|
|||
const QRect screen_rect = screen->geometry();
|
||||
|
||||
QSize sh = sizeHint();
|
||||
// The look should resemble the default tooltip style set in Settings::SetCurrentUserStyle()
|
||||
// The look should resemble the default tooltip style set in Settings::ApplyStyle()
|
||||
const int border = 1;
|
||||
const int arrow_height = 18;
|
||||
const int arrow_width = 18;
|
||||
|
|
|
@ -247,7 +247,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
Settings::Instance().InitDefaultPalette();
|
||||
Settings::Instance().UpdateSystemDark();
|
||||
Settings::Instance().SetCurrentUserStyle(Settings::Instance().GetCurrentUserStyle());
|
||||
Settings::Instance().ApplyStyle();
|
||||
|
||||
MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))};
|
||||
win.Show();
|
||||
|
|
|
@ -240,9 +240,7 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
|
|||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
|
||||
[](Qt::ColorScheme colorScheme) {
|
||||
Settings::Instance().SetCurrentUserStyle(Settings::Instance().GetCurrentUserStyle());
|
||||
});
|
||||
[](Qt::ColorScheme colorScheme) { Settings::Instance().ApplyStyle(); });
|
||||
#endif
|
||||
|
||||
connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this,
|
||||
|
@ -1739,7 +1737,7 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr
|
|||
settings.UpdateSystemDark();
|
||||
if (settings.IsSystemDark() != was_dark_before)
|
||||
{
|
||||
settings.SetCurrentUserStyle(settings.GetCurrentUserStyle());
|
||||
settings.ApplyStyle();
|
||||
|
||||
// force the colors in the Skylander window to update
|
||||
if (m_skylander_window)
|
||||
|
|
|
@ -123,7 +123,7 @@ void Settings::SetThemeName(const QString& theme_name)
|
|||
emit ThemeChanged();
|
||||
}
|
||||
|
||||
QString Settings::GetCurrentUserStyle() const
|
||||
QString Settings::GetUserStyleName() const
|
||||
{
|
||||
if (GetQSettings().contains(QStringLiteral("userstyle/name")))
|
||||
return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
|
||||
|
@ -132,6 +132,11 @@ QString Settings::GetCurrentUserStyle() const
|
|||
return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
|
||||
}
|
||||
|
||||
void Settings::SetUserStyleName(const QString& stylesheet_name)
|
||||
{
|
||||
GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
|
||||
}
|
||||
|
||||
void Settings::InitDefaultPalette()
|
||||
{
|
||||
s_default_palette = std::make_unique<QPalette>(qApp->palette());
|
||||
|
@ -169,8 +174,9 @@ bool Settings::IsThemeDark()
|
|||
}
|
||||
|
||||
// Calling this before the main window has been created breaks the style of some widgets.
|
||||
void Settings::SetCurrentUserStyle(const QString& stylesheet_name)
|
||||
void Settings::ApplyStyle()
|
||||
{
|
||||
const QString stylesheet_name = GetUserStyleName();
|
||||
QString stylesheet_contents;
|
||||
|
||||
// If we haven't found one, we continue with an empty (default) style
|
||||
|
@ -243,8 +249,6 @@ void Settings::SetCurrentUserStyle(const QString& stylesheet_name)
|
|||
}
|
||||
|
||||
qApp->setStyleSheet(stylesheet_contents);
|
||||
|
||||
GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
|
||||
}
|
||||
|
||||
bool Settings::AreUserStylesEnabled() const
|
||||
|
|
|
@ -57,12 +57,15 @@ public:
|
|||
void SetSystemDark(bool dark);
|
||||
bool IsSystemDark();
|
||||
bool IsThemeDark();
|
||||
void SetCurrentUserStyle(const QString& stylesheet_name);
|
||||
QString GetCurrentUserStyle() const;
|
||||
|
||||
void SetUserStyleName(const QString& stylesheet_name);
|
||||
QString GetUserStyleName() const;
|
||||
void SetUserStylesEnabled(bool enabled);
|
||||
bool AreUserStylesEnabled() const;
|
||||
|
||||
// this evaluates the current stylesheet settings and refreshes the GUI with them
|
||||
void ApplyStyle();
|
||||
|
||||
void GetToolTipStyle(QColor& window_color, QColor& text_color, QColor& emphasis_text_color,
|
||||
QColor& border_color, const QPalette& palette,
|
||||
const QPalette& high_contrast_palette) const;
|
||||
|
|
|
@ -254,7 +254,7 @@ void InterfacePane::LoadConfig()
|
|||
->setCurrentIndex(
|
||||
m_combobox_theme->findText(QString::fromStdString(Config::Get(Config::MAIN_THEME_NAME))));
|
||||
|
||||
const QString userstyle = Settings::Instance().GetCurrentUserStyle();
|
||||
const QString userstyle = Settings::Instance().GetUserStyleName();
|
||||
const int index = m_combobox_userstyle->findData(QFileInfo(userstyle).fileName());
|
||||
|
||||
if (index > 0)
|
||||
|
@ -298,7 +298,8 @@ void InterfacePane::OnSaveConfig()
|
|||
m_checkbox_use_builtin_title_database->isChecked());
|
||||
Settings::Instance().SetDebugModeEnabled(m_checkbox_show_debugging_ui->isChecked());
|
||||
Settings::Instance().SetUserStylesEnabled(m_checkbox_use_userstyle->isChecked());
|
||||
Settings::Instance().SetCurrentUserStyle(m_combobox_userstyle->currentData().toString());
|
||||
Settings::Instance().SetUserStyleName(m_combobox_userstyle->currentData().toString());
|
||||
Settings::Instance().ApplyStyle();
|
||||
|
||||
const bool visible = m_checkbox_use_userstyle->isChecked();
|
||||
|
||||
|
|
Loading…
Reference in New Issue