diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index c876a61..57bc00d 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -24,6 +24,7 @@ void ActionManager::setupAction(MainWindow *mainWindow) CREATE_NEW_ACTION(mainWindow, actionZoomIn); CREATE_NEW_ACTION(mainWindow, actionZoomOut); CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip); + CREATE_NEW_ACTION(mainWindow, actionFitInView); CREATE_NEW_ACTION(mainWindow, actionFitByWidth); CREATE_NEW_ACTION(mainWindow, actionCopyPixmap); CREATE_NEW_ACTION(mainWindow, actionCopyFilePath); @@ -48,6 +49,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow) actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr)); actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr)); actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr)); + actionFitInView->setText("Fit in view"); // TODO: what should it called? actionFitByWidth->setText("Fit by width"); // TODO: what should it called? actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr)); actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr)); diff --git a/app/actionmanager.h b/app/actionmanager.h index 50e7978..4494b27 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -19,6 +19,7 @@ public: QAction *actionZoomIn; QAction *actionZoomOut; QAction *actionHorizontalFlip; + QAction *actionFitInView; QAction *actionFitByWidth; QAction *actionCopyPixmap; QAction *actionCopyFilePath; diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 3bce171..440f54c 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -208,6 +208,12 @@ void GraphicsView::checkAndDoFitInView(bool markItOnAnyway) } } +// Automately do fit in view when viewport(window) smaller than image original size. +void GraphicsView::setEnableAutoFitInView(bool enable) +{ + m_enableFitInView = enable; +} + inline double zeroOrOne(double number) { return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1); diff --git a/app/graphicsview.h b/app/graphicsview.h index b741c4f..d27212c 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -33,6 +33,7 @@ public: void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false); void checkAndDoFitInView(bool markItOnAnyway = true); + void setEnableAutoFitInView(bool enable = true); static QTransform resetScale(const QTransform & orig); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 009b76b..7c5ba34 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -421,6 +421,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) menu->addSeparator(); menu->addAction(m_am->actionHorizontalFlip); + menu->addAction(m_am->actionFitInView); menu->addAction(m_am->actionFitByWidth); menu->addSeparator(); @@ -562,6 +563,14 @@ void MainWindow::on_actionHorizontalFlip_triggered() m_graphicsView->flipView(); } +void MainWindow::on_actionFitInView_triggered() +{ + // TODO: maybe do it if window is smaller than original image size? + m_graphicsView->setEnableAutoFitInView(false); + + m_graphicsView->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); +} + void MainWindow::on_actionFitByWidth_triggered() { m_graphicsView->fitByOrientation(); diff --git a/app/mainwindow.h b/app/mainwindow.h index 4ab6c65..50959c8 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -66,6 +66,7 @@ private slots: void on_actionZoomIn_triggered(); void on_actionZoomOut_triggered(); void on_actionHorizontalFlip_triggered(); + void on_actionFitInView_triggered(); void on_actionFitByWidth_triggered(); void on_actionCopyPixmap_triggered(); void on_actionCopyFilePath_triggered();