From e341dcf238193995b7e61c8353f000d49aee7f33 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Mon, 7 Apr 2025 22:54:14 +0100 Subject: [PATCH] qt: For Qt 6.9.0 and above, use QImage::flipped over QImage::mirrored The latter has been deprecated, and is causing build failures where deprecations warnings are treated as errors. --- src/citra_qt/bootmanager.cpp | 3 ++- src/citra_qt/camera/camera_util.cpp | 7 ++++--- src/citra_qt/util/util.cpp | 18 +++++++++++++++++- src/citra_qt/util/util.h | 8 ++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index fcab2be0b..9fde08be4 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -10,6 +10,7 @@ #include #include "citra_qt/bootmanager.h" #include "citra_qt/citra_qt.h" +#include "citra_qt/util/util.h" #include "common/color.h" #include "common/microprofile.h" #include "common/scm_rev.h" @@ -714,7 +715,7 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p screenshot_image.bits(), [this, screenshot_path](bool invert_y) { const std::string std_screenshot_path = screenshot_path.toStdString(); - if (screenshot_image.mirrored(false, invert_y).save(screenshot_path)) { + if (GetMirroredImage(screenshot_image, false, invert_y).save(screenshot_path)) { LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path); } else { LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path); diff --git a/src/citra_qt/camera/camera_util.cpp b/src/citra_qt/camera/camera_util.cpp index 878ac910c..01d6369fe 100644 --- a/src/citra_qt/camera/camera_util.cpp +++ b/src/citra_qt/camera/camera_util.cpp @@ -7,6 +7,7 @@ #include #include #include "citra_qt/camera/camera_util.h" +#include "citra_qt/util/util.h" namespace CameraUtil { @@ -213,9 +214,9 @@ std::vector ProcessImage(const QImage& image, int width, int height, bool o } QImage scaled = image.scaled(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); - QImage transformed = - scaled.copy((scaled.width() - width) / 2, (scaled.height() - height) / 2, width, height) - .mirrored(flip_horizontal, flip_vertical); + QImage transformed = GetMirroredImage( + scaled.copy((scaled.width() - width) / 2, (scaled.height() - height) / 2, width, height), + flip_horizontal, flip_vertical); if (output_rgb) { QImage converted = transformed.convertToFormat(QImage::Format_RGB16); std::memcpy(buffer.data(), converted.bits(), width * height * sizeof(u16)); diff --git a/src/citra_qt/util/util.cpp b/src/citra_qt/util/util.cpp index 413e94abc..d63021fbc 100644 --- a/src/citra_qt/util/util.cpp +++ b/src/citra_qt/util/util.cpp @@ -174,4 +174,20 @@ const std::string GetApplicationsDirectory() { #else return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); #endif -} \ No newline at end of file +} + +QImage GetMirroredImage(QImage source_image, bool flip_horizontal, bool flip_vertical) { +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) // Fallback, uses deprecated method + return source_image.mirrored(flip_horizontal, flip_vertical); +#else // New method + auto orientation_horizontal = static_cast(0x0); + auto orientation_vertical = static_cast(0x0); + + if (flip_horizontal) + orientation_horizontal = Qt::Horizontal; + if (flip_vertical) + orientation_vertical = Qt::Vertical; + + return source_image.flipped(orientation_horizontal | orientation_vertical); +#endif +} diff --git a/src/citra_qt/util/util.h b/src/citra_qt/util/util.h index 428d69ffd..b855a4ad0 100644 --- a/src/citra_qt/util/util.h +++ b/src/citra_qt/util/util.h @@ -41,3 +41,11 @@ QPixmap GetQPixmapFromSMDH(const std::vector& smdh_data); * @return The user’s applications directory */ [[nodiscard]] const std::string GetApplicationsDirectory(); + +/** + * Imitates the deprecated `QImage::mirrored` function in a forwards-compatible manner + * @param flip_horizontal Whether the image should be flipped horizontally + * @param flip_vertical Whether the image should be flipped vertically + * @return QImage The mirrored image + */ +QImage GetMirroredImage(QImage source_image, bool flip_horizontal, bool flip_vertical);