Skip to content

Commit

Permalink
Add "Fill Window" zoom mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Oct 7, 2023
1 parent 5f6dc8c commit bb5fbe2
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 137 deletions.
18 changes: 13 additions & 5 deletions src/actionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ QMenu *ActionManager::buildViewMenu(bool addIcon, QWidget *parent)
addCloneOfAction(viewMenu, "zoomout");
addCloneOfAction(viewMenu, "originalsize");
addCloneOfAction(viewMenu, "zoomtofit");
addCloneOfAction(viewMenu, "navigationresetszoom");
addCloneOfAction(viewMenu, "fillwindow");
addCloneOfAction(viewMenu, "navresetszoom");
viewMenu->addSeparator();
addCloneOfAction(viewMenu, "rotateright");
addCloneOfAction(viewMenu, "rotateleft");
Expand Down Expand Up @@ -634,9 +635,11 @@ void ActionManager::actionTriggered(QAction *triggeredAction, MainWindow *releva
} else if (key == "originalsize") {
relevantWindow->originalSize();
} else if (key == "zoomtofit") {
relevantWindow->setZoomToFitEnabled(triggeredAction->isChecked());
} else if (key == "navigationresetszoom") {
relevantWindow->setNavigationResetsZoomEnabled(triggeredAction->isChecked());
relevantWindow->setZoomToFit(triggeredAction->isChecked());
} else if (key == "fillwindow") {
relevantWindow->setFillWindow(triggeredAction->isChecked());
} else if (key == "navresetszoom") {
relevantWindow->setNavigationResetsZoom(triggeredAction->isChecked());
} else if (key == "rotateright") {
relevantWindow->rotateRight();
} else if (key == "rotateleft") {
Expand Down Expand Up @@ -765,10 +768,15 @@ void ActionManager::initializeActionLibrary()
zoomToFitAction->setCheckable(true);
actionLibrary.insert("zoomtofit", zoomToFitAction);

auto *fillWindowAction = new QAction(QIcon::fromTheme("zoom-fit-best"), tr("Fill &Window"));
fillWindowAction->setData({"disable"});
fillWindowAction->setCheckable(true);
actionLibrary.insert("fillwindow", fillWindowAction);

auto *navigationResetsZoomAction = new QAction(tr("&Navigation Resets Zoom"));
navigationResetsZoomAction->setData({"disable"});
navigationResetsZoomAction->setCheckable(true);
actionLibrary.insert("navigationresetszoom", navigationResetsZoomAction);
actionLibrary.insert("navresetszoom", navigationResetsZoomAction);

auto *rotateRightAction = new QAction(QIcon::fromTheme("object-rotate-right"), tr("Rotate &Right"));
rotateRightAction->setData({"disable"});
Expand Down
55 changes: 28 additions & 27 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ MainWindow::MainWindow(QWidget *parent, const QJsonObject &windowSessionState) :
// Connect graphicsview signals
connect(graphicsView, &QVGraphicsView::fileChanged, this, &MainWindow::fileChanged);
connect(graphicsView, &QVGraphicsView::zoomLevelChanged, this, &MainWindow::zoomLevelChanged);
connect(graphicsView, &QVGraphicsView::zoomToFitChanged, this, &MainWindow::syncZoomToFitChecked);
connect(graphicsView, &QVGraphicsView::navigationResetsZoomChanged, this, &MainWindow::syncNavigationResetsZoomChecked);
connect(graphicsView, &QVGraphicsView::calculatedZoomModeChanged, this, &MainWindow::syncCalculatedZoomMode);
connect(graphicsView, &QVGraphicsView::navigationResetsZoomChanged, this, &MainWindow::syncNavigationResetsZoom);
connect(graphicsView, &QVGraphicsView::cancelSlideshow, this, &MainWindow::cancelSlideshow);

// Initialize escape shortcut
Expand Down Expand Up @@ -113,9 +113,6 @@ MainWindow::MainWindow(QWidget *parent, const QJsonObject &windowSessionState) :
connect(menuBar(), &QMenuBar::triggered, this, [this](QAction *triggeredAction){
ActionManager::actionTriggered(triggeredAction, this);
});
// Initialize checkable actions
syncZoomToFitChecked();
syncNavigationResetsZoomChecked();

// Add all actions to this window so keyboard shortcuts are always triggered
// using virtual menu to hold them so i can connect to the triggered signal
Expand Down Expand Up @@ -211,6 +208,9 @@ void MainWindow::showEvent(QShowEvent *event)
ui->fullscreenLabel->setMinimumHeight(menuBar()->sizeHint().height());
}

syncCalculatedZoomMode();
syncNavigationResetsZoom();

if (!sessionStateToLoad.isEmpty())
{
loadSessionState(sessionStateToLoad, false);
Expand Down Expand Up @@ -408,19 +408,20 @@ void MainWindow::zoomLevelChanged()
buildWindowTitle();
}

void MainWindow::syncZoomToFitChecked()
void MainWindow::syncCalculatedZoomMode()
{
const auto actions = qvApp->getActionManager().getAllClonesOfAction("zoomtofit", this);
const bool value = graphicsView->getZoomToFitEnabled();
for (const auto &action : actions)
action->setChecked(value);
const bool isZoomToFit = graphicsView->getCalculatedZoomMode() == Qv::CalculatedZoomMode::ZoomToFit;
const bool isFillWindow = graphicsView->getCalculatedZoomMode() == Qv::CalculatedZoomMode::FillWindow;
for (const auto &action : qvApp->getActionManager().getAllClonesOfAction("zoomtofit", this))
action->setChecked(isZoomToFit);
for (const auto &action : qvApp->getActionManager().getAllClonesOfAction("fillwindow", this))
action->setChecked(isFillWindow);
}

void MainWindow::syncNavigationResetsZoomChecked()
void MainWindow::syncNavigationResetsZoom()
{
const auto actions = qvApp->getActionManager().getAllClonesOfAction("navigationresetszoom", this);
const bool value = graphicsView->getNavigationResetsZoomEnabled();
for (const auto &action : actions)
const bool value = graphicsView->getNavigationResetsZoom();
for (const auto &action : qvApp->getActionManager().getAllClonesOfAction("navresetszoom", this))
action->setChecked(value);
}

Expand Down Expand Up @@ -1166,14 +1167,19 @@ void MainWindow::zoomOut()
graphicsView->zoomOut();
}

void MainWindow::setZoomToFitEnabled(bool value)
void MainWindow::setZoomToFit(const bool value)
{
graphicsView->setCalculatedZoomMode(value ? std::make_optional(Qv::CalculatedZoomMode::ZoomToFit) : std::nullopt);
}

void MainWindow::setFillWindow(const bool value)
{
graphicsView->setZoomToFitEnabled(value);
graphicsView->setCalculatedZoomMode(value ? std::make_optional(Qv::CalculatedZoomMode::FillWindow) : std::nullopt);
}

void MainWindow::setNavigationResetsZoomEnabled(bool value)
void MainWindow::setNavigationResetsZoom(const bool value)
{
graphicsView->setNavigationResetsZoomEnabled(value);
graphicsView->setNavigationResetsZoom(value);
}

void MainWindow::originalSize()
Expand All @@ -1184,25 +1190,25 @@ void MainWindow::originalSize()
void MainWindow::rotateRight()
{
graphicsView->rotateImage(90);
graphicsView->zoomToFit();
graphicsView->fitOrConstrainImage();
}

void MainWindow::rotateLeft()
{
graphicsView->rotateImage(-90);
graphicsView->zoomToFit();
graphicsView->fitOrConstrainImage();
}

void MainWindow::mirror()
{
graphicsView->mirrorImage();
graphicsView->zoomToFit();
graphicsView->fitOrConstrainImage();
}

void MainWindow::flip()
{
graphicsView->flipImage();
graphicsView->zoomToFit();
graphicsView->fitOrConstrainImage();
}

void MainWindow::firstFile()
Expand Down Expand Up @@ -1249,12 +1255,7 @@ void MainWindow::saveFrameAs()
saveDialog->setAcceptMode(QFileDialog::AcceptSave);
saveDialog->open();
connect(saveDialog, &QFileDialog::fileSelected, this, [=](const QString &fileName){
graphicsView->originalSize();
for(int i=0; i < graphicsView->getLoadedMovie().frameCount(); i++)
nextFrame();

graphicsView->getLoadedMovie().currentPixmap().save(fileName, nullptr, 100);
graphicsView->zoomToFit();
});
}

Expand Down
10 changes: 6 additions & 4 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class MainWindow : public QMainWindow

void zoomOut();

void setZoomToFitEnabled(bool value);
void setZoomToFit(const bool value);

void setNavigationResetsZoomEnabled(bool value);
void setFillWindow(const bool value);

void setNavigationResetsZoom(const bool value);

void originalSize();

Expand Down Expand Up @@ -150,9 +152,9 @@ public slots:

void zoomLevelChanged();

void syncZoomToFitChecked();
void syncCalculatedZoomMode();

void syncNavigationResetsZoomChecked();
void syncNavigationResetsZoom();

void disableActions();

Expand Down
Loading

0 comments on commit bb5fbe2

Please sign in to comment.