From f4f7d93e38456262c2684db2322969b507f93958 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Tue, 5 Aug 2025 00:06:05 +0800 Subject: [PATCH] chore: simplified long image mode code --- app/graphicsview.cpp | 45 +++++++------------------------------------- app/graphicsview.h | 5 +---- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index df6f0b5..d027770 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -280,33 +280,7 @@ bool GraphicsView::isLongImage() const return aspectRatio > 2.5 || aspectRatio < 0.4; } -bool GraphicsView::shouldEnterLongImageMode() const -{ - // Check if long image mode is enabled in settings - if (!Settings::instance()->autoLongImageMode()) return false; - - // Check if image is a long image - if (!isLongImage()) return false; - - // Check if transformed image size is larger than the size of the view - QSizeF imageSize = transform().mapRect(sceneRect()).size(); - QSizeF viewSize = viewport()->size(); - - return imageSize.width() > viewSize.width() || imageSize.height() > viewSize.height(); -} - -void GraphicsView::applyLongImageMode() -{ - if (!shouldEnterLongImageMode()) { - m_longImageMode = false; - return; - } - - m_longImageMode = true; - applyLongImageModeDirect(); -} - -void GraphicsView::applyLongImageModeDirect() +void GraphicsView::fitLongImage() { // Determine image orientation based on current transform QRectF transformedRect = transform().mapRect(sceneRect()); @@ -324,11 +298,6 @@ void GraphicsView::applyLongImageModeDirect() } } -bool GraphicsView::isInLongImageMode() const -{ - return m_longImageMode; -} - void GraphicsView::displayScene() { if (shouldAvoidTransform()) { @@ -337,16 +306,15 @@ void GraphicsView::displayScene() } // Check if should apply long image mode - if (shouldEnterLongImageMode()) { - applyLongImageMode(); + if (Settings::instance()->autoLongImageMode() && isLongImage()) { + m_longImageMode = true; m_firstUserMediaLoaded = true; + if (isSceneBiggerThanView()) fitLongImage(); return; } - // Not in long image mode - m_longImageMode = false; - if (isSceneBiggerThanView()) { + // Do fit-in-view fitInView(sceneRect(), Qt::KeepAspectRatio); // After fitInView, the image should fit the window, so hide navigator emit navigatorViewRequired(false, transform()); @@ -355,6 +323,7 @@ void GraphicsView::displayScene() emit navigatorViewRequired(false, transform()); } + m_longImageMode = false; m_enableFitInView = true; m_firstUserMediaLoaded = true; } @@ -455,7 +424,7 @@ void GraphicsView::resizeEvent(QResizeEvent *event) // In long image mode, reapply long image logic on resize // We directly apply the long image mode logic without rechecking // if we should enter long image mode, as the mode is already active - applyLongImageModeDirect(); + fitLongImage(); } else if (m_enableFitInView) { bool originalSizeSmallerThanWindow = isThingSmallerThanWindowWith(resetScale(transform())); if (originalSizeSmallerThanWindow && scaleFactor() >= 1) { diff --git a/app/graphicsview.h b/app/graphicsview.h index c098aa9..c2500ed 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -48,10 +48,7 @@ public: // Long image mode support bool isLongImage() const; - bool shouldEnterLongImageMode() const; - void applyLongImageMode(); - void applyLongImageModeDirect(); - bool isInLongImageMode() const; + void fitLongImage(); signals: void navigatorViewRequired(bool required, QTransform transform);