From 0cad4672e948b92b92e1aaf6e9bb5b144d8075ac Mon Sep 17 00:00:00 2001 From: Pipe530 <54341095+Pipe530@users.noreply.github.com> Date: Mon, 19 Oct 2026 16:06:00 +0200 Subject: [PATCH] launcher: add System/Dark/Light theme option --- src/launcher/CMakeLists.txt | 2 +- src/launcher/forms/main_dialog.ui | 43 +++++++++++++++++++++++++++++++ src/launcher/src/mainDialog.cpp | 29 ++++++++++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/launcher/CMakeLists.txt b/src/launcher/CMakeLists.txt index 35a8bc18a..0d4acdc9a 100644 --- a/src/launcher/CMakeLists.txt +++ b/src/launcher/CMakeLists.txt @@ -1,5 +1,5 @@ -find_package(Qt6 COMPONENTS Concurrent Network Widgets REQUIRED) +find_package(Qt6 6.8 COMPONENTS Concurrent Network Widgets REQUIRED) add_subdirectory("${KYTY_SOURCE_DIR}/updater" "${CMAKE_CURRENT_BINARY_DIR}/updater") set(CMAKE_AUTOUIC_SEARCH_PATHS forms) diff --git a/src/launcher/forms/main_dialog.ui b/src/launcher/forms/main_dialog.ui index 94f50252b..267e70a61 100644 --- a/src/launcher/forms/main_dialog.ui +++ b/src/launcher/forms/main_dialog.ui @@ -112,6 +112,49 @@ + + + + + + Theme: + + + + + + + + System + + + + + Dark + + + + + Light + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/launcher/src/mainDialog.cpp b/src/launcher/src/mainDialog.cpp index e33373166..2abd30f0b 100644 --- a/src/launcher/src/mainDialog.cpp +++ b/src/launcher/src/mainDialog.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +63,8 @@ constexpr DWORD CMD_Y_CHARS = 1000; #endif constexpr char SETTINGS_MAIN_DIALOG[] = "MainDialog"; constexpr char SETTINGS_MAIN_LAST_GEOMETRY[] = "geometry"; -constexpr char SETTINGS_CHECK_UPDATES[] = "check_updates_on_startup"; +constexpr char SETTINGS_CHECK_UPDATES[] = "check_updates_on_startup"; +constexpr char SETTINGS_THEME[] = "theme"; class MainDialogPrivate: public QObject { Q_OBJECT @@ -86,6 +89,17 @@ public: private: static QByteArray g_last_geometry; static bool g_check_updates_on_startup; + static int g_theme; + + static void ApplyTheme(int theme) { + auto scheme = Qt::ColorScheme::Unknown; + switch (theme) { + case 1: scheme = Qt::ColorScheme::Dark; break; + case 2: scheme = Qt::ColorScheme::Light; break; + default: break; + } + QApplication::styleHints()->setColorScheme(scheme); + } Ui::MainDialog* m_ui = {nullptr}; MainDialog* m_main_dialog = nullptr; @@ -101,6 +115,7 @@ private: QByteArray MainDialogPrivate::g_last_geometry; bool MainDialogPrivate::g_check_updates_on_startup = true; +int MainDialogPrivate::g_theme = 0; MainDialog::MainDialog(QWidget* parent): QDialog(parent), m_p(new MainDialogPrivate(this)) { m_p->Setup(this); @@ -119,6 +134,8 @@ void MainDialogPrivate::Setup(MainDialog* main_dialog) { m_main_dialog = main_dialog; m_update_checker = new UpdateChecker(main_dialog); m_ui->check_updates_on_startup->setChecked(g_check_updates_on_startup); + m_ui->theme_combo->setCurrentIndex(g_theme); + ApplyTheme(g_theme); m_ui->check_updates_link->setVisible(UpdateChecker::IsSupported()); m_ui->check_updates_on_startup->setVisible(UpdateChecker::IsSupported()); @@ -149,6 +166,11 @@ void MainDialogPrivate::Setup(MainDialog* main_dialog) { g_check_updates_on_startup = checked; m_ui->widget->WriteSettings(); }); + connect(m_ui->theme_combo, &QComboBox::currentIndexChanged, this, [this](int index) { + g_theme = index; + ApplyTheme(index); + m_ui->widget->WriteSettings(); + }); connect(main_dialog, &MainDialog::Resize, [this]() { g_last_geometry = m_main_dialog->saveGeometry(); m_ui->widget->WriteSettings(); @@ -516,6 +538,7 @@ void MainDialogPrivate::WriteSettings(QSettings& s) { s.setValue(SETTINGS_MAIN_LAST_GEOMETRY, g_last_geometry); } s.setValue(SETTINGS_CHECK_UPDATES, g_check_updates_on_startup); + s.setValue(SETTINGS_THEME, g_theme); s.endGroup(); } @@ -525,6 +548,10 @@ void MainDialogPrivate::ReadSettings(QSettings& s) { g_last_geometry = s.value(SETTINGS_MAIN_LAST_GEOMETRY, g_last_geometry).toByteArray(); g_check_updates_on_startup = s.value(SETTINGS_CHECK_UPDATES, true).toBool(); + g_theme = s.value(SETTINGS_THEME, 0).toInt(); + if (g_theme < 0 || g_theme > 2) { + g_theme = 0; + } s.endGroup(); }