chore: add the ability to know if it's the first loaded user media

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
This commit is contained in:
Gary Wang 2025-04-08 23:19:02 +08:00
parent fc417b30e5
commit 0a45cd7c22
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
2 changed files with 11 additions and 2 deletions

View File

@ -118,7 +118,7 @@ qreal GraphicsView::scaleFactor() const
void GraphicsView::resetTransform() void GraphicsView::resetTransform()
{ {
if (!m_avoidResetTransform) { if (!shouldAvoidTransform()) {
QGraphicsView::resetTransform(); QGraphicsView::resetTransform();
} }
} }
@ -196,7 +196,7 @@ void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly)
void GraphicsView::displayScene() void GraphicsView::displayScene()
{ {
if (m_avoidResetTransform) { if (shouldAvoidTransform()) {
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform());
return; return;
} }
@ -206,6 +206,7 @@ void GraphicsView::displayScene()
} }
m_enableFitInView = true; m_enableFitInView = true;
m_firstUserMediaLoaded = true;
} }
bool GraphicsView::isSceneBiggerThanView() const bool GraphicsView::isSceneBiggerThanView() const
@ -365,3 +366,8 @@ void GraphicsView::applyTransformationModeByScaleFactor()
scene()->trySetTransformationMode(Qt::FastTransformation, this->scaleFactor()); scene()->trySetTransformationMode(Qt::FastTransformation, this->scaleFactor());
} }
} }
bool GraphicsView::shouldAvoidTransform() const
{
return m_firstUserMediaLoaded && m_avoidResetTransform;
}

View File

@ -64,6 +64,8 @@ private:
void setCheckerboardEnabled(bool enabled, bool invertColor = false); void setCheckerboardEnabled(bool enabled, bool invertColor = false);
void applyTransformationModeByScaleFactor(); void applyTransformationModeByScaleFactor();
inline bool shouldAvoidTransform() const;
// Consider switch to 3 state for "no fit", "always fit" and "fit when view is smaller"? // 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... // ... 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. // 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_avoidResetTransform = false;
bool m_checkerboardEnabled = false; bool m_checkerboardEnabled = false;
bool m_useLightCheckerboard = false; bool m_useLightCheckerboard = false;
bool m_firstUserMediaLoaded = false;
}; };
#endif // GRAPHICSVIEW_H #endif // GRAPHICSVIEW_H