Skip to content

Commit

Permalink
Put back some existing behavior
Browse files Browse the repository at this point in the history
* Original size can toggle between 100% and zoom-to-fit.
* Minimum window size just requires one dimension to be over the minimum.
  • Loading branch information
jdpurcell committed Dec 15, 2024
1 parent 01e55d6 commit 6aacb3c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,21 +576,25 @@ void MainWindow::setWindowSize()
const QSize hardLimitSize = currentScreen->availableSize() - windowFrameSize - extraWidgetsSize;
const QSize screenSize = currentScreen->size();
const QSize minWindowSize = (screenSize * minWindowResizedPercentage).boundedTo(hardLimitSize);
const QSize maxWindowSize = (screenSize * maxWindowResizedPercentage).boundedTo(hardLimitSize);
const QSize maxWindowSize = (screenSize * qMax(maxWindowResizedPercentage, minWindowResizedPercentage)).boundedTo(hardLimitSize);
const QSizeF imageSize = graphicsView->getEffectiveOriginalSize();
const int fitOverscan = graphicsView->getFitOverscan();
const QSize fitOverscanSize = QSize(fitOverscan * 2, fitOverscan * 2);
const bool enforceMinSizeBothDimensions = false;

QSize targetSize = imageSize.toSize() - fitOverscanSize;

if (targetSize.width() > maxWindowSize.width() || targetSize.height() > maxWindowSize.height())
const bool limitToMin = targetSize.width() < minWindowSize.width() && targetSize.height() < minWindowSize.height();
const bool limitToMax = targetSize.width() > maxWindowSize.width() || targetSize.height() > maxWindowSize.height();
if (limitToMin || limitToMax)
{
const QSizeF viewSize = maxWindowSize + fitOverscanSize;
const QSizeF viewSize = (limitToMin ? minWindowSize : maxWindowSize) + fitOverscanSize;
const qreal fitRatio = qMin(viewSize.width() / imageSize.width(), viewSize.height() / imageSize.height());
targetSize = (imageSize * fitRatio).toSize() - fitOverscanSize;
}

targetSize = targetSize.expandedTo(minWindowSize).boundedTo(maxWindowSize);
if (enforceMinSizeBothDimensions)
targetSize = targetSize.expandedTo(minWindowSize);

// Match center after new geometry
// This is smoother than a single geometry set for some reason
Expand Down
6 changes: 5 additions & 1 deletion src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ void QVGraphicsView::zoomToFit()

void QVGraphicsView::originalSize()
{
zoomAbsolute(1.0);
const bool originalSizeAsToggle = true;
if (originalSizeAsToggle && zoomLevel == 1.0)
zoomToFit();
else
zoomAbsolute(1.0);
}

void QVGraphicsView::centerImage()
Expand Down
2 changes: 1 addition & 1 deletion src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ private slots:
bool isScalingEnabled;
bool isScalingTwoEnabled;
bool isPastActualSizeEnabled;
int fitOverscan;
bool isScrollZoomsEnabled;
bool isLoopFoldersEnabled;
bool isCursorZoomEnabled;
bool isOneToOnePixelSizingEnabled;
int cropMode;
qreal zoomMultiplier;

int fitOverscan;
qreal zoomLevel;
qreal appliedDpiAdjustment;
qreal appliedExpensiveScaleZoomLevel;
Expand Down

0 comments on commit 6aacb3c

Please sign in to comment.