From 0a45cd7c22e0089a70115d39ccb49f516d303bfd Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Tue, 8 Apr 2025 23:19:02 +0800 Subject: [PATCH] chore: add the ability to know if it's the first loaded user media MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This could make it easier to allow set “Keep Transform” mode at start-up. This change is sponsored by @EdgarHartel. Related: https://github.com/BLumia/pineapple-pictures/issues/146#issuecomment-2778192785 --- app/graphicsview.cpp | 10 ++++++++-- app/graphicsview.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 91fb50b..f5b7555 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -118,7 +118,7 @@ qreal GraphicsView::scaleFactor() const void GraphicsView::resetTransform() { - if (!m_avoidResetTransform) { + if (!shouldAvoidTransform()) { QGraphicsView::resetTransform(); } } @@ -196,7 +196,7 @@ void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly) void GraphicsView::displayScene() { - if (m_avoidResetTransform) { + if (shouldAvoidTransform()) { emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); return; } @@ -206,6 +206,7 @@ void GraphicsView::displayScene() } m_enableFitInView = true; + m_firstUserMediaLoaded = true; } bool GraphicsView::isSceneBiggerThanView() const @@ -365,3 +366,8 @@ void GraphicsView::applyTransformationModeByScaleFactor() scene()->trySetTransformationMode(Qt::FastTransformation, this->scaleFactor()); } } + +bool GraphicsView::shouldAvoidTransform() const +{ + return m_firstUserMediaLoaded && m_avoidResetTransform; +} diff --git a/app/graphicsview.h b/app/graphicsview.h index 87fed81..c03f1a2 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -64,6 +64,8 @@ private: void setCheckerboardEnabled(bool enabled, bool invertColor = false); void applyTransformationModeByScaleFactor(); + inline bool shouldAvoidTransform() const; + // Consider switch to 3 state for "no fit", "always fit" and "fit when view is smaller"? // ... or even more? e.g. "fit/snap width" things... // Currently it's "no fit" when it's false and "fit when view is smaller" when it's true. @@ -71,6 +73,7 @@ private: bool m_avoidResetTransform = false; bool m_checkerboardEnabled = false; bool m_useLightCheckerboard = false; + bool m_firstUserMediaLoaded = false; }; #endif // GRAPHICSVIEW_H