From 19d97e4180e6a11e9f67a5adb5f315a1725f8218 Mon Sep 17 00:00:00 2001 From: Z11-V <103266186+Z11-V@users.noreply.github.com> Date: Thu, 7 Jul 2022 08:21:01 +0530 Subject: [PATCH] added quick screenshot (#6025) Modified Capture screenshot to save screenshots with a timestamped name in the user directory. --- .../configuration/configure_general.cpp | 24 +++++++++++++++ .../configuration/configure_general.ui | 29 +++++++++++++++++++ src/citra_qt/main.cpp | 25 +++++++++------- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index edab11299..8fd404c80 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -2,7 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include #include +#include #include "citra_qt/configuration/configure_general.h" #include "citra_qt/uisettings.h" #include "core/core.h" @@ -56,6 +59,15 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) .rightJustified(tr("unthrottled").size())); } }); + + connect(ui->change_screenshot_dir, &QToolButton::clicked, this, [this] { + const QString dir_path = QFileDialog::getExistingDirectory( + this, tr("Select Screenshot Directory"), ui->screenshot_dir_path->text(), + QFileDialog::ShowDirsOnly); + if (!dir_path.isEmpty()) { + ui->screenshot_dir_path->setText(dir_path); + } + }); } ConfigureGeneral::~ConfigureGeneral() = default; @@ -101,6 +113,16 @@ void ConfigureGeneral::SetConfiguration() { .arg(SliderToSettings(ui->frame_limit_alternate->value())) .rightJustified(tr("unthrottled").size())); } + + QString screenshot_path = UISettings::values.screenshot_path; + if (screenshot_path.isEmpty()) { + screenshot_path = + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir)); + screenshot_path.append(QStringLiteral("screenshots/")); + FileUtil::CreateFullPath(screenshot_path.toStdString()); + UISettings::values.screenshot_path = screenshot_path; + } + ui->screenshot_dir_path->setText(screenshot_path); } void ConfigureGeneral::ResetDefaults() { @@ -124,6 +146,8 @@ void ConfigureGeneral::ApplyConfiguration() { UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked(); UISettings::values.update_on_close = ui->toggle_auto_update->isChecked(); + UISettings::values.screenshot_path = ui->screenshot_dir_path->text(); + Settings::values.region_value = ui->region_combobox->currentIndex() - 1; if (ui->frame_limit->value() == ui->frame_limit->maximum()) { diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 9c3827fee..5cb817e1d 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -213,6 +213,33 @@ + + + + Screenshots + + + + + + Save Screenshots To + + + + + + + + + + + ... + + + + + + @@ -247,6 +274,8 @@ frame_limit toggle_alternate_speed frame_limit_alternate + screenshot_dir_path + change_screenshot_dir button_reset_defaults diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 1c14da3d3..29cdc15a9 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1959,17 +1959,22 @@ void GMainWindow::OnSaveMovie() { void GMainWindow::OnCaptureScreenshot() { OnPauseGame(); - QFileDialog png_dialog(this, tr("Capture Screenshot"), UISettings::values.screenshot_path, - tr("PNG Image (*.png)")); - png_dialog.setAcceptMode(QFileDialog::AcceptSave); - png_dialog.setDefaultSuffix(QStringLiteral("png")); - if (png_dialog.exec()) { - const QString path = png_dialog.selectedFiles().first(); - if (!path.isEmpty()) { - UISettings::values.screenshot_path = QFileInfo(path).path(); - render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, path); - } + QString path = UISettings::values.screenshot_path; + if (!FileUtil::IsDirectory(path.toStdString())) { + if (!FileUtil::CreateFullPath(path.toStdString())) { + QMessageBox::information(this, tr("Invalid Screenshot Directory"), + tr("Cannot create specified screenshot directory. Screenshot " + "path is set back to its default value.")); + path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir)); + path.append(QStringLiteral("screenshots/")); + UISettings::values.screenshot_path = path; + }; } + const QString filename = game_title.remove(QRegularExpression(QStringLiteral("[\\/:?\"<>|]"))); + const QString timestamp = + QDateTime::currentDateTime().toString(QStringLiteral("dd.MM.yy_hh.mm.ss.z")); + path.append(QStringLiteral("/%1_%2.png").arg(filename).arg(timestamp)); + render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, path); OnStartGame(); }