mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-12-25 01:11:48 +01:00
citra_qt: use enum classes for the settings
This commit is contained in:
parent
90f9d32f13
commit
8ecd31db41
@ -220,26 +220,23 @@ void Config::ReadValues() {
|
|||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
qt_config->beginGroup("GameList");
|
qt_config->beginGroup("GameList");
|
||||||
UISettings::values.game_list_icon_size = ReadSetting("iconSize", 2).toInt();
|
int icon_size = ReadSetting("iconSize", 2).toInt();
|
||||||
if (UISettings::values.game_list_icon_size < 0 || UISettings::values.game_list_icon_size > 2) {
|
if (icon_size < 0 || icon_size > 2) {
|
||||||
LOG_ERROR(Config, "Invalid value for game_list_icon_size: {}",
|
icon_size = 2;
|
||||||
UISettings::values.game_list_icon_size);
|
|
||||||
UISettings::values.game_list_icon_size = 2;
|
|
||||||
}
|
}
|
||||||
|
UISettings::values.game_list_icon_size = UISettings::GameListIconSize{icon_size};
|
||||||
|
|
||||||
UISettings::values.game_list_row_1 = ReadSetting("row1", 2).toInt();
|
int row_1 = ReadSetting("row1", 2).toInt();
|
||||||
if (UISettings::values.game_list_row_1 < 0 || UISettings::values.game_list_row_1 > 3) {
|
if (row_1 < 0 || row_1 > 3) {
|
||||||
LOG_ERROR(Config, "Invalid value for game_list_row_1: {}",
|
row_1 = 2;
|
||||||
UISettings::values.game_list_row_1);
|
|
||||||
UISettings::values.game_list_row_1 = 2;
|
|
||||||
}
|
}
|
||||||
|
UISettings::values.game_list_row_1 = UISettings::GameListText{row_1};
|
||||||
|
|
||||||
UISettings::values.game_list_row_2 = ReadSetting("row2", 0).toInt();
|
int row_2 = ReadSetting("row2", 0).toInt();
|
||||||
if (UISettings::values.game_list_row_2 < -1 || UISettings::values.game_list_row_2 > 3) {
|
if (row_2 < -1 || row_2 > 3) {
|
||||||
LOG_ERROR(Config, "Invalid value for game_list_row_2: {}",
|
row_2 = 0;
|
||||||
UISettings::values.game_list_row_2);
|
|
||||||
UISettings::values.game_list_row_2 = 0;
|
|
||||||
}
|
}
|
||||||
|
UISettings::values.game_list_row_2 = UISettings::GameListText{row_2};
|
||||||
|
|
||||||
UISettings::values.game_list_hide_no_icon = ReadSetting("hideNoIcon", false).toBool();
|
UISettings::values.game_list_hide_no_icon = ReadSetting("hideNoIcon", false).toBool();
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
@ -474,9 +471,9 @@ void Config::SaveValues() {
|
|||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
qt_config->beginGroup("GameList");
|
qt_config->beginGroup("GameList");
|
||||||
WriteSetting("iconSize", UISettings::values.game_list_icon_size, 2);
|
WriteSetting("iconSize", static_cast<int>(UISettings::values.game_list_icon_size), 2);
|
||||||
WriteSetting("row1", UISettings::values.game_list_row_1, 2);
|
WriteSetting("row1", static_cast<int>(UISettings::values.game_list_row_1), 2);
|
||||||
WriteSetting("row2", UISettings::values.game_list_row_2, 0);
|
WriteSetting("row2", static_cast<int>(UISettings::values.game_list_row_2), 0);
|
||||||
WriteSetting("hideNoIcon", UISettings::values.game_list_hide_no_icon, false);
|
WriteSetting("hideNoIcon", UISettings::values.game_list_hide_no_icon, false);
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
|
@ -40,18 +40,23 @@ void ConfigureUi::setConfiguration() {
|
|||||||
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
|
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
|
||||||
ui->language_combobox->setCurrentIndex(
|
ui->language_combobox->setCurrentIndex(
|
||||||
ui->language_combobox->findData(UISettings::values.language));
|
ui->language_combobox->findData(UISettings::values.language));
|
||||||
ui->icon_size_combobox->setCurrentIndex(UISettings::values.game_list_icon_size);
|
ui->icon_size_combobox->setCurrentIndex(
|
||||||
ui->row_1_text_combobox->setCurrentIndex(UISettings::values.game_list_row_1);
|
static_cast<int>(UISettings::values.game_list_icon_size));
|
||||||
ui->row_2_text_combobox->setCurrentIndex(UISettings::values.game_list_row_2 + 1);
|
ui->row_1_text_combobox->setCurrentIndex(static_cast<int>(UISettings::values.game_list_row_1));
|
||||||
|
ui->row_2_text_combobox->setCurrentIndex(static_cast<int>(UISettings::values.game_list_row_2) +
|
||||||
|
1);
|
||||||
ui->toggle_hide_no_icon->setChecked(UISettings::values.game_list_hide_no_icon);
|
ui->toggle_hide_no_icon->setChecked(UISettings::values.game_list_hide_no_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureUi::applyConfiguration() {
|
void ConfigureUi::applyConfiguration() {
|
||||||
UISettings::values.theme =
|
UISettings::values.theme =
|
||||||
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString();
|
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString();
|
||||||
UISettings::values.game_list_icon_size = ui->icon_size_combobox->currentIndex();
|
UISettings::values.game_list_icon_size =
|
||||||
UISettings::values.game_list_row_1 = ui->row_1_text_combobox->currentIndex();
|
static_cast<UISettings::GameListIconSize>(ui->icon_size_combobox->currentIndex());
|
||||||
UISettings::values.game_list_row_2 = ui->row_2_text_combobox->currentIndex() - 1;
|
UISettings::values.game_list_row_1 =
|
||||||
|
static_cast<UISettings::GameListText>(ui->row_1_text_combobox->currentIndex());
|
||||||
|
UISettings::values.game_list_row_2 =
|
||||||
|
static_cast<UISettings::GameListText>(ui->row_2_text_combobox->currentIndex() - 1);
|
||||||
UISettings::values.game_list_hide_no_icon = ui->toggle_hide_no_icon->isChecked();
|
UISettings::values.game_list_hide_no_icon = ui->toggle_hide_no_icon->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +124,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Game list icon sizes (in px)
|
||||||
|
static const std::unordered_map<UISettings::GameListIconSize, int> IconSizes{
|
||||||
|
{UISettings::GameListIconSize::NoIcon, 0},
|
||||||
|
{UISettings::GameListIconSize::SmallIcon, 24},
|
||||||
|
{UISettings::GameListIconSize::LargeIcon, 48},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialization of GameListItem for path values.
|
* A specialization of GameListItem for path values.
|
||||||
* This class ensures that for every full path value it holds, a correct string representation
|
* This class ensures that for every full path value it holds, a correct string representation
|
||||||
@ -145,16 +152,17 @@ public:
|
|||||||
setData(qulonglong(program_id), ProgramIdRole);
|
setData(qulonglong(program_id), ProgramIdRole);
|
||||||
setData(qulonglong(extdata_id), ExtdataIdRole);
|
setData(qulonglong(extdata_id), ExtdataIdRole);
|
||||||
|
|
||||||
if (!UISettings::values.game_list_icon_size) {
|
if (UISettings::values.game_list_icon_size == UISettings::GameListIconSize::NoIcon) {
|
||||||
// Do not display icons
|
// Do not display icons
|
||||||
setData(QPixmap(), Qt::DecorationRole);
|
setData(QPixmap(), Qt::DecorationRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large = UISettings::values.game_list_icon_size == 2;
|
bool large =
|
||||||
|
UISettings::values.game_list_icon_size == UISettings::GameListIconSize::LargeIcon;
|
||||||
|
|
||||||
if (!Loader::IsValidSMDH(smdh_data)) {
|
if (!Loader::IsValidSMDH(smdh_data)) {
|
||||||
// SMDH is not valid, set a default icon
|
// SMDH is not valid, set a default icon
|
||||||
if (UISettings::values.game_list_icon_size)
|
if (UISettings::values.game_list_icon_size != UISettings::GameListIconSize::NoIcon)
|
||||||
setData(GetDefaultIcon(large), Qt::DecorationRole);
|
setData(GetDefaultIcon(large), Qt::DecorationRole);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,7 +171,7 @@ public:
|
|||||||
memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH));
|
memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH));
|
||||||
|
|
||||||
// Get icon from SMDH
|
// Get icon from SMDH
|
||||||
if (UISettings::values.game_list_icon_size)
|
if (UISettings::values.game_list_icon_size != UISettings::GameListIconSize::NoIcon)
|
||||||
setData(GetQPixmapFromSMDH(smdh, large), Qt::DecorationRole);
|
setData(GetQPixmapFromSMDH(smdh, large), Qt::DecorationRole);
|
||||||
|
|
||||||
// Get title from SMDH
|
// Get title from SMDH
|
||||||
@ -181,19 +189,19 @@ public:
|
|||||||
Common::SplitPath(data(FullPathRole).toString().toStdString(), &path, &filename,
|
Common::SplitPath(data(FullPathRole).toString().toStdString(), &path, &filename,
|
||||||
&extension);
|
&extension);
|
||||||
|
|
||||||
const std::array<QString, 4> display_texts{{
|
const std::unordered_map<UISettings::GameListText, QString> display_texts{
|
||||||
QString::fromStdString(filename + extension), // file name
|
{UISettings::GameListText::FileName, QString::fromStdString(filename + extension)},
|
||||||
data(FullPathRole).toString(), // full path
|
{UISettings::GameListText::FullPath, data(FullPathRole).toString()},
|
||||||
data(TitleRole).toString(), // title name
|
{UISettings::GameListText::TitleName, data(TitleRole).toString()},
|
||||||
QString::fromStdString(
|
{UISettings::GameListText::TitleID,
|
||||||
fmt::format("{:016X}", data(ProgramIdRole).toULongLong())), // title id
|
QString::fromStdString(fmt::format("{:016X}", data(ProgramIdRole).toULongLong()))},
|
||||||
}};
|
};
|
||||||
|
|
||||||
const QString& row1 = display_texts.at(UISettings::values.game_list_row_1);
|
const QString& row1 = display_texts.at(UISettings::values.game_list_row_1);
|
||||||
|
|
||||||
QString row2;
|
QString row2;
|
||||||
int row_2_id = UISettings::values.game_list_row_2;
|
auto row_2_id = UISettings::values.game_list_row_2;
|
||||||
if (row_2_id != -1) {
|
if (row_2_id != UISettings::GameListText::NoText) {
|
||||||
row2 = (row1.isEmpty() ? "" : "\n ") + display_texts.at(row_2_id);
|
row2 = (row1.isEmpty() ? "" : "\n ") + display_texts.at(row_2_id);
|
||||||
}
|
}
|
||||||
return row1 + row2;
|
return row1 + row2;
|
||||||
@ -324,9 +332,7 @@ public:
|
|||||||
UISettings::GameDir* game_dir = &directory;
|
UISettings::GameDir* game_dir = &directory;
|
||||||
setData(QVariant::fromValue(game_dir), GameDirRole);
|
setData(QVariant::fromValue(game_dir), GameDirRole);
|
||||||
|
|
||||||
constexpr std::array<int, 3> icon_sizes{{0, 24, 48}};
|
int icon_size = IconSizes.at(UISettings::values.game_list_icon_size);
|
||||||
|
|
||||||
int icon_size = icon_sizes[UISettings::values.game_list_icon_size];
|
|
||||||
switch (dir_type) {
|
switch (dir_type) {
|
||||||
case GameListItemType::InstalledDir:
|
case GameListItemType::InstalledDir:
|
||||||
setData(QIcon::fromTheme("sd_card").pixmap(icon_size), Qt::DecorationRole);
|
setData(QIcon::fromTheme("sd_card").pixmap(icon_size), Qt::DecorationRole);
|
||||||
@ -357,8 +363,7 @@ public:
|
|||||||
explicit GameListAddDir() {
|
explicit GameListAddDir() {
|
||||||
setData(type(), TypeRole);
|
setData(type(), TypeRole);
|
||||||
|
|
||||||
constexpr std::array<int, 3> icon_sizes{{0, 24, 48}};
|
int icon_size = IconSizes.at(UISettings::values.game_list_icon_size);
|
||||||
int icon_size = icon_sizes[UISettings::values.game_list_icon_size];
|
|
||||||
setData(QIcon::fromTheme("plus").pixmap(icon_size), Qt::DecorationRole);
|
setData(QIcon::fromTheme("plus").pixmap(icon_size), Qt::DecorationRole);
|
||||||
setData("Add New Game Directory", Qt::DisplayRole);
|
setData("Add New Game Directory", Qt::DisplayRole);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,20 @@ struct GameDir {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class GameListIconSize {
|
||||||
|
NoIcon, ///< Do not display icons
|
||||||
|
SmallIcon, ///< Display a small (24x24) icon
|
||||||
|
LargeIcon, ///< Display a large (48x48) icon
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class GameListText {
|
||||||
|
NoText = -1, ///< No text
|
||||||
|
FileName, ///< Display the file name of the entry
|
||||||
|
FullPath, ///< Display the full path of the entry
|
||||||
|
TitleName, ///< Display the name of the title
|
||||||
|
TitleID, ///< Display the title ID
|
||||||
|
};
|
||||||
|
|
||||||
struct Values {
|
struct Values {
|
||||||
QByteArray geometry;
|
QByteArray geometry;
|
||||||
QByteArray state;
|
QByteArray state;
|
||||||
@ -59,9 +73,9 @@ struct Values {
|
|||||||
bool enable_discord_presence;
|
bool enable_discord_presence;
|
||||||
|
|
||||||
// Game List
|
// Game List
|
||||||
int game_list_icon_size;
|
GameListIconSize game_list_icon_size;
|
||||||
int game_list_row_1;
|
GameListText game_list_row_1;
|
||||||
int game_list_row_2;
|
GameListText game_list_row_2;
|
||||||
bool game_list_hide_no_icon;
|
bool game_list_hide_no_icon;
|
||||||
|
|
||||||
QString roms_path;
|
QString roms_path;
|
||||||
|
Loading…
Reference in New Issue
Block a user