summaryrefslogtreecommitdiff
path: root/src/yuzu/configuration/configure_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/configuration/configure_ui.cpp')
-rw-r--r--src/yuzu/configuration/configure_ui.cpp100
1 files changed, 97 insertions, 3 deletions
diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp
index 2ebb80302..82f3b6e78 100644
--- a/src/yuzu/configuration/configure_ui.cpp
+++ b/src/yuzu/configuration/configure_ui.cpp
@@ -1,18 +1,32 @@
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
+#include "yuzu/configuration/configure_ui.h"
+
#include <array>
+#include <cstdlib>
+#include <set>
+#include <stdexcept>
+#include <string>
#include <utility>
-#include <QFileDialog>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QCoreApplication>
#include <QDirIterator>
+#include <QFileDialog>
+#include <QString>
+#include <QToolButton>
+#include <QVariant>
+
#include "common/common_types.h"
#include "common/fs/path_util.h"
#include "common/logging/log.h"
#include "common/settings.h"
+#include "common/settings_enums.h"
#include "core/core.h"
+#include "core/frontend/framebuffer_layout.h"
#include "ui_configure_ui.h"
-#include "yuzu/configuration/configure_ui.h"
#include "yuzu/uisettings.h"
namespace {
@@ -54,8 +68,40 @@ QString GetTranslatedRowTextName(size_t index) {
}
} // Anonymous namespace
+static float GetUpFactor(Settings::ResolutionSetup res_setup) {
+ Settings::ResolutionScalingInfo info{};
+ Settings::TranslateResolutionInfo(res_setup, info);
+ return info.up_factor;
+}
+
+static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* parent) {
+ screenshot_height->clear();
+
+ const auto& enumeration =
+ Settings::EnumMetadata<Settings::ResolutionSetup>::Canonicalizations();
+ std::set<u32> resolutions{};
+ for (const auto& [name, value] : enumeration) {
+ const float up_factor = GetUpFactor(value);
+ u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
+ u32 height_docked = Layout::ScreenDocked::Height * up_factor;
+ resolutions.emplace(height_undocked);
+ resolutions.emplace(height_docked);
+ }
+
+ screenshot_height->addItem(parent->tr("Auto", "Screenshot height option"));
+ for (const auto res : resolutions) {
+ screenshot_height->addItem(QString::fromStdString(std::to_string(res)));
+ }
+}
+
+static u32 ScreenshotDimensionToInt(const QString& height) {
+ return std::strtoul(height.toUtf8(), nullptr, 0);
+}
+
ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
- : QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()}, system{system_} {
+ : QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()},
+ ratio{Settings::values.aspect_ratio.GetValue()},
+ resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} {
ui->setupUi(this);
InitializeLanguageComboBox();
@@ -68,6 +114,8 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
InitializeIconSizeComboBox();
InitializeRowComboBoxes();
+ PopulateResolutionComboBox(ui->screenshot_height, this);
+
SetConfiguration();
// Force game list reload if any of the relevant settings are changed.
@@ -75,6 +123,8 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
connect(ui->show_compat, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_size, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
connect(ui->show_types, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
+ connect(ui->show_play_time, &QCheckBox::stateChanged, this,
+ &ConfigureUi::RequestGameListUpdate);
connect(ui->game_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ConfigureUi::RequestGameListUpdate);
connect(ui->folder_icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged),
@@ -104,6 +154,10 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
ui->screenshot_path_edit->setText(dir);
}
});
+
+ connect(ui->screenshot_height, &QComboBox::currentTextChanged, [this]() { UpdateWidthText(); });
+
+ UpdateWidthText();
}
ConfigureUi::~ConfigureUi() = default;
@@ -115,6 +169,7 @@ void ConfigureUi::ApplyConfiguration() {
UISettings::values.show_compat = ui->show_compat->isChecked();
UISettings::values.show_size = ui->show_size->isChecked();
UISettings::values.show_types = ui->show_types->isChecked();
+ UISettings::values.show_play_time = ui->show_play_time->isChecked();
UISettings::values.game_icon_size = ui->game_icon_size_combobox->currentData().toUInt();
UISettings::values.folder_icon_size = ui->folder_icon_size_combobox->currentData().toUInt();
UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt();
@@ -123,6 +178,11 @@ void ConfigureUi::ApplyConfiguration() {
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
+
+ const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
+ UISettings::values.screenshot_height.SetValue(height);
+
+ RequestGameListUpdate();
system.ApplySettings();
}
@@ -138,6 +198,7 @@ void ConfigureUi::SetConfiguration() {
ui->show_compat->setChecked(UISettings::values.show_compat.GetValue());
ui->show_size->setChecked(UISettings::values.show_size.GetValue());
ui->show_types->setChecked(UISettings::values.show_types.GetValue());
+ ui->show_play_time->setChecked(UISettings::values.show_play_time.GetValue());
ui->game_icon_size_combobox->setCurrentIndex(
ui->game_icon_size_combobox->findData(UISettings::values.game_icon_size.GetValue()));
ui->folder_icon_size_combobox->setCurrentIndex(
@@ -147,6 +208,13 @@ void ConfigureUi::SetConfiguration() {
UISettings::values.enable_screenshot_save_as.GetValue());
ui->screenshot_path_edit->setText(QString::fromStdString(
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir)));
+
+ const auto height = UISettings::values.screenshot_height.GetValue();
+ if (height == 0) {
+ ui->screenshot_height->setCurrentIndex(0);
+ } else {
+ ui->screenshot_height->setCurrentText(QStringLiteral("%1").arg(height));
+ }
}
void ConfigureUi::changeEvent(QEvent* event) {
@@ -317,3 +385,29 @@ void ConfigureUi::OnLanguageChanged(int index) {
emit LanguageChanged(ui->language_combobox->itemData(index).toString());
}
+
+void ConfigureUi::UpdateWidthText() {
+ const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText());
+ const u32 width = UISettings::CalculateWidth(height, ratio);
+ if (height == 0) {
+ const auto up_factor = GetUpFactor(resolution_setting);
+ const u32 height_docked = Layout::ScreenDocked::Height * up_factor;
+ const u32 width_docked = UISettings::CalculateWidth(height_docked, ratio);
+ const u32 height_undocked = Layout::ScreenUndocked::Height * up_factor;
+ const u32 width_undocked = UISettings::CalculateWidth(height_undocked, ratio);
+ ui->screenshot_width->setText(tr("Auto (%1 x %2, %3 x %4)", "Screenshot width value")
+ .arg(width_undocked)
+ .arg(height_undocked)
+ .arg(width_docked)
+ .arg(height_docked));
+ } else {
+ ui->screenshot_width->setText(QStringLiteral("%1 x").arg(width));
+ }
+}
+
+void ConfigureUi::UpdateScreenshotInfo(Settings::AspectRatio ratio_,
+ Settings::ResolutionSetup resolution_setting_) {
+ ratio = ratio_;
+ resolution_setting = resolution_setting_;
+ UpdateWidthText();
+}