Qt: add option to automatically resize the game window

This commit is contained in:
Megamouse 2022-11-17 19:37:12 +01:00
parent 2eef3ab645
commit 8199f97e7a
4 changed files with 35 additions and 6 deletions

View File

@ -281,8 +281,17 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
if (m_gui_settings->GetValue(gui::gs_resize).toBool())
{
w = m_gui_settings->GetValue(gui::gs_width).toInt();
h = m_gui_settings->GetValue(gui::gs_height).toInt();
if (m_gui_settings->GetValue(gui::gs_resize_manual).toBool())
{
w = m_gui_settings->GetValue(gui::gs_width).toInt();
h = m_gui_settings->GetValue(gui::gs_height).toInt();
}
else
{
const qreal device_pixel_ratio = devicePixelRatio();
w /= device_pixel_ratio;
h /= device_pixel_ratio;
}
}
const auto screen = m_main_window ? m_main_window->screen() : primaryScreen();

View File

@ -212,6 +212,7 @@ namespace gui
const gui_save gs_showMouseFs = gui_save(gs_frame, "showMouseInFullscreen", false);
const gui_save gs_lockMouseFs = gui_save(gs_frame, "lockMouseInFullscreen", true);
const gui_save gs_resize = gui_save(gs_frame, "resize", false);
const gui_save gs_resize_manual = gui_save(gs_frame, "resizeManual", true);
const gui_save gs_width = gui_save(gs_frame, "width", 1280);
const gui_save gs_height = gui_save(gs_frame, "height", 720);
const gui_save gs_hideMouseIdle = gui_save(gs_frame, "hideMouseOnIdle", false);

View File

@ -1754,9 +1754,12 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
});
const bool enable_buttons = m_gui_settings->GetValue(gui::gs_resize).toBool();
const bool use_manual_resize = m_gui_settings->GetValue(gui::gs_resize_manual).toBool();
ui->gs_resizeOnBoot->setChecked(enable_buttons);
ui->gs_width->setEnabled(enable_buttons);
ui->gs_height->setEnabled(enable_buttons);
ui->gs_resizeOnBootManual->setChecked(use_manual_resize);
ui->gs_resizeOnBootManual->setEnabled(enable_buttons);
ui->gs_width->setEnabled(enable_buttons && use_manual_resize);
ui->gs_height->setEnabled(enable_buttons && use_manual_resize);
const QRect screen = QGuiApplication::primaryScreen()->geometry();
const int width = m_gui_settings->GetValue(gui::gs_width).toInt();
@ -1766,9 +1769,18 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
connect(ui->gs_resizeOnBoot, &QCheckBox::toggled, [this](bool checked)
{
const bool enabled = checked && ui->gs_resizeOnBootManual->isChecked();
m_gui_settings->SetValue(gui::gs_resize, checked);
ui->gs_width->setEnabled(checked);
ui->gs_height->setEnabled(checked);
ui->gs_resizeOnBootManual->setEnabled(checked);
ui->gs_width->setEnabled(enabled);
ui->gs_height->setEnabled(enabled);
});
connect(ui->gs_resizeOnBootManual, &QCheckBox::toggled, [this](bool checked)
{
const bool enabled = checked && ui->gs_resizeOnBoot->isChecked();
m_gui_settings->SetValue(gui::gs_resize_manual, checked);
ui->gs_width->setEnabled(enabled);
ui->gs_height->setEnabled(enabled);
});
connect(ui->gs_width, &QSpinBox::editingFinished, [this]()
{

View File

@ -2991,6 +2991,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="gs_resizeOnBootManual">
<property name="text">
<string>Resize manually</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="gs_resolution_layout">
<item>