feat: add fit-in-view action
This commit is contained in:
parent
3e51cd5603
commit
635199b85b
|
@ -24,6 +24,7 @@ void ActionManager::setupAction(MainWindow *mainWindow)
|
||||||
CREATE_NEW_ACTION(mainWindow, actionZoomIn);
|
CREATE_NEW_ACTION(mainWindow, actionZoomIn);
|
||||||
CREATE_NEW_ACTION(mainWindow, actionZoomOut);
|
CREATE_NEW_ACTION(mainWindow, actionZoomOut);
|
||||||
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
|
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
|
||||||
|
CREATE_NEW_ACTION(mainWindow, actionFitInView);
|
||||||
CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
|
CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
|
||||||
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap);
|
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap);
|
||||||
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
|
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
|
||||||
|
@ -48,6 +49,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
|
||||||
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
|
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
|
||||||
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
|
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
|
||||||
actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", 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?
|
actionFitByWidth->setText("Fit by width"); // TODO: what should it called?
|
||||||
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
|
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
|
||||||
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
|
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
QAction *actionZoomIn;
|
QAction *actionZoomIn;
|
||||||
QAction *actionZoomOut;
|
QAction *actionZoomOut;
|
||||||
QAction *actionHorizontalFlip;
|
QAction *actionHorizontalFlip;
|
||||||
|
QAction *actionFitInView;
|
||||||
QAction *actionFitByWidth;
|
QAction *actionFitByWidth;
|
||||||
QAction *actionCopyPixmap;
|
QAction *actionCopyPixmap;
|
||||||
QAction *actionCopyFilePath;
|
QAction *actionCopyFilePath;
|
||||||
|
|
|
@ -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)
|
inline double zeroOrOne(double number)
|
||||||
{
|
{
|
||||||
return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1);
|
return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1);
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
|
void fitByOrientation(Qt::Orientation ori = Qt::Horizontal, bool scaleDownOnly = false);
|
||||||
|
|
||||||
void checkAndDoFitInView(bool markItOnAnyway = true);
|
void checkAndDoFitInView(bool markItOnAnyway = true);
|
||||||
|
void setEnableAutoFitInView(bool enable = true);
|
||||||
|
|
||||||
static QTransform resetScale(const QTransform & orig);
|
static QTransform resetScale(const QTransform & orig);
|
||||||
|
|
||||||
|
|
|
@ -421,6 +421,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
menu->addAction(m_am->actionHorizontalFlip);
|
menu->addAction(m_am->actionHorizontalFlip);
|
||||||
|
menu->addAction(m_am->actionFitInView);
|
||||||
menu->addAction(m_am->actionFitByWidth);
|
menu->addAction(m_am->actionFitByWidth);
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
@ -562,6 +563,14 @@ void MainWindow::on_actionHorizontalFlip_triggered()
|
||||||
m_graphicsView->flipView();
|
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()
|
void MainWindow::on_actionFitByWidth_triggered()
|
||||||
{
|
{
|
||||||
m_graphicsView->fitByOrientation();
|
m_graphicsView->fitByOrientation();
|
||||||
|
|
|
@ -66,6 +66,7 @@ private slots:
|
||||||
void on_actionZoomIn_triggered();
|
void on_actionZoomIn_triggered();
|
||||||
void on_actionZoomOut_triggered();
|
void on_actionZoomOut_triggered();
|
||||||
void on_actionHorizontalFlip_triggered();
|
void on_actionHorizontalFlip_triggered();
|
||||||
|
void on_actionFitInView_triggered();
|
||||||
void on_actionFitByWidth_triggered();
|
void on_actionFitByWidth_triggered();
|
||||||
void on_actionCopyPixmap_triggered();
|
void on_actionCopyPixmap_triggered();
|
||||||
void on_actionCopyFilePath_triggered();
|
void on_actionCopyFilePath_triggered();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user