mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 15:45:42 +00:00
Qt: Don't reset theme when changing language
This commit is contained in:
parent
7e20a79719
commit
bc49e2f627
|
@ -55,6 +55,8 @@ static constexpr char DISC_IMAGE_FILTER[] = QT_TRANSLATE_NOOP(
|
|||
static const char* DEFAULT_THEME_NAME = "darkfusion";
|
||||
|
||||
MainWindow* g_main_window = nullptr;
|
||||
static QString s_unthemed_style_name;
|
||||
static bool s_unthemed_style_name_set;
|
||||
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
static const bool s_use_central_widget = false;
|
||||
|
@ -80,7 +82,7 @@ bool QtHost::IsSystemValid()
|
|||
return s_system_valid;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow() : QMainWindow(nullptr), m_unthemed_style_name(QApplication::style()->objectName())
|
||||
MainWindow::MainWindow() : QMainWindow(nullptr)
|
||||
{
|
||||
Assert(!g_main_window);
|
||||
g_main_window = this;
|
||||
|
@ -100,11 +102,20 @@ MainWindow::~MainWindow()
|
|||
g_main_window = nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::initialize()
|
||||
void MainWindow::updateApplicationTheme()
|
||||
{
|
||||
if (!s_unthemed_style_name_set)
|
||||
{
|
||||
s_unthemed_style_name_set = true;
|
||||
s_unthemed_style_name = QApplication::style()->objectName();
|
||||
}
|
||||
|
||||
setStyleFromSettings();
|
||||
setIconThemeFromSettings();
|
||||
}
|
||||
|
||||
void MainWindow::initialize()
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
setupAdditionalUi();
|
||||
connectSignals();
|
||||
|
@ -1945,9 +1956,9 @@ void MainWindow::addThemeToMenu(const QString& name, const QString& key)
|
|||
void MainWindow::setTheme(const QString& theme)
|
||||
{
|
||||
Host::SetBaseStringSettingValue("UI", "Theme", theme.toUtf8().constData());
|
||||
setStyleFromSettings();
|
||||
setIconThemeFromSettings();
|
||||
updateMenuSelectedTheme();
|
||||
updateApplicationTheme();
|
||||
|
||||
// Sadly we need to recreate here, because otherwise the icon theme doesn't update.
|
||||
recreate();
|
||||
}
|
||||
|
||||
|
@ -1957,7 +1968,7 @@ void MainWindow::setStyleFromSettings()
|
|||
|
||||
if (theme == "qdarkstyle")
|
||||
{
|
||||
qApp->setStyle(m_unthemed_style_name);
|
||||
qApp->setStyle(s_unthemed_style_name);
|
||||
qApp->setPalette(QApplication::style()->standardPalette());
|
||||
|
||||
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
|
||||
|
@ -2047,7 +2058,7 @@ void MainWindow::setStyleFromSettings()
|
|||
{
|
||||
qApp->setPalette(QApplication::style()->standardPalette());
|
||||
qApp->setStyleSheet(QString());
|
||||
qApp->setStyle(m_unthemed_style_name);
|
||||
qApp->setStyle(s_unthemed_style_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,9 @@ public:
|
|||
explicit MainWindow();
|
||||
~MainWindow();
|
||||
|
||||
/// Sets application theme according to settings.
|
||||
static void updateApplicationTheme();
|
||||
|
||||
/// Initializes the window. Call once at startup.
|
||||
void initialize();
|
||||
|
||||
|
@ -166,9 +169,8 @@ protected:
|
|||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
void setTheme(const QString& theme);
|
||||
void setStyleFromSettings();
|
||||
void setIconThemeFromSettings();
|
||||
static void setStyleFromSettings();
|
||||
static void setIconThemeFromSettings();
|
||||
void setupAdditionalUi();
|
||||
void connectSignals();
|
||||
void addThemeToMenu(const QString& name, const QString& key);
|
||||
|
@ -212,6 +214,7 @@ private:
|
|||
void updateMenuSelectedTheme();
|
||||
std::string getDeviceDiscPath(const QString& title);
|
||||
void setGameListEntryCoverImage(const GameList::Entry* entry);
|
||||
void setTheme(const QString& theme);
|
||||
void recreate();
|
||||
|
||||
/// Fills menu with save state info and handlers.
|
||||
|
@ -233,8 +236,6 @@ private:
|
|||
|
||||
Ui::MainWindow m_ui;
|
||||
|
||||
QString m_unthemed_style_name;
|
||||
|
||||
GameListWidget* m_game_list_widget = nullptr;
|
||||
|
||||
DisplayWidget* m_display_widget = nullptr;
|
||||
|
|
|
@ -2241,6 +2241,9 @@ int main(int argc, char* argv[])
|
|||
if (!QtHost::ParseCommandLineParametersAndInitializeConfig(app, autoboot))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Set theme before creating any windows.
|
||||
MainWindow::updateApplicationTheme();
|
||||
|
||||
// Start up the CPU thread.
|
||||
MainWindow* main_window = new MainWindow();
|
||||
QtHost::HookSignals();
|
||||
|
|
Loading…
Reference in a new issue