mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-19 18:36:53 +02:00
launcher: add System/Dark/Light theme option
This commit is contained in:
@@ -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")
|
add_subdirectory("${KYTY_SOURCE_DIR}/updater" "${CMAKE_CURRENT_BINARY_DIR}/updater")
|
||||||
|
|
||||||
set(CMAKE_AUTOUIC_SEARCH_PATHS forms)
|
set(CMAKE_AUTOUIC_SEARCH_PATHS forms)
|
||||||
|
|||||||
@@ -112,6 +112,49 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="themeLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_theme">
|
||||||
|
<property name="text">
|
||||||
|
<string>Theme:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="theme_combo">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>System</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Dark</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Light</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="themeSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QStyleHints>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
@@ -61,7 +63,8 @@ constexpr DWORD CMD_Y_CHARS = 1000;
|
|||||||
#endif
|
#endif
|
||||||
constexpr char SETTINGS_MAIN_DIALOG[] = "MainDialog";
|
constexpr char SETTINGS_MAIN_DIALOG[] = "MainDialog";
|
||||||
constexpr char SETTINGS_MAIN_LAST_GEOMETRY[] = "geometry";
|
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 {
|
class MainDialogPrivate: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -86,6 +89,17 @@ public:
|
|||||||
private:
|
private:
|
||||||
static QByteArray g_last_geometry;
|
static QByteArray g_last_geometry;
|
||||||
static bool g_check_updates_on_startup;
|
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};
|
Ui::MainDialog* m_ui = {nullptr};
|
||||||
MainDialog* m_main_dialog = nullptr;
|
MainDialog* m_main_dialog = nullptr;
|
||||||
@@ -101,6 +115,7 @@ private:
|
|||||||
|
|
||||||
QByteArray MainDialogPrivate::g_last_geometry;
|
QByteArray MainDialogPrivate::g_last_geometry;
|
||||||
bool MainDialogPrivate::g_check_updates_on_startup = true;
|
bool MainDialogPrivate::g_check_updates_on_startup = true;
|
||||||
|
int MainDialogPrivate::g_theme = 0;
|
||||||
|
|
||||||
MainDialog::MainDialog(QWidget* parent): QDialog(parent), m_p(new MainDialogPrivate(this)) {
|
MainDialog::MainDialog(QWidget* parent): QDialog(parent), m_p(new MainDialogPrivate(this)) {
|
||||||
m_p->Setup(this);
|
m_p->Setup(this);
|
||||||
@@ -119,6 +134,8 @@ void MainDialogPrivate::Setup(MainDialog* main_dialog) {
|
|||||||
m_main_dialog = main_dialog;
|
m_main_dialog = main_dialog;
|
||||||
m_update_checker = new UpdateChecker(main_dialog);
|
m_update_checker = new UpdateChecker(main_dialog);
|
||||||
m_ui->check_updates_on_startup->setChecked(g_check_updates_on_startup);
|
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_link->setVisible(UpdateChecker::IsSupported());
|
||||||
m_ui->check_updates_on_startup->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;
|
g_check_updates_on_startup = checked;
|
||||||
m_ui->widget->WriteSettings();
|
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]() {
|
connect(main_dialog, &MainDialog::Resize, [this]() {
|
||||||
g_last_geometry = m_main_dialog->saveGeometry();
|
g_last_geometry = m_main_dialog->saveGeometry();
|
||||||
m_ui->widget->WriteSettings();
|
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_MAIN_LAST_GEOMETRY, g_last_geometry);
|
||||||
}
|
}
|
||||||
s.setValue(SETTINGS_CHECK_UPDATES, g_check_updates_on_startup);
|
s.setValue(SETTINGS_CHECK_UPDATES, g_check_updates_on_startup);
|
||||||
|
s.setValue(SETTINGS_THEME, g_theme);
|
||||||
|
|
||||||
s.endGroup();
|
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_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_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();
|
s.endGroup();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user