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