feat: basic image flip support

This commit is contained in:
Gary Wang 2021-03-19 23:11:06 +08:00
parent deed477d49
commit 6a9e5e80d0
6 changed files with 25 additions and 0 deletions

View File

@ -23,6 +23,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, actionCopyPixmap);
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
CREATE_NEW_ACTION(mainWindow, actionPaste);
@ -45,6 +46,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", "Horizontal flip", nullptr));
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr));

View File

@ -18,6 +18,7 @@ public:
public:
QAction *actionZoomIn;
QAction *actionZoomOut;
QAction *actionHorizontalFlip;
QAction *actionCopyPixmap;
QAction *actionCopyFilePath;
QAction *actionPaste;

View File

@ -134,6 +134,17 @@ void GraphicsView::zoomView(qreal scaleFactor)
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
}
void GraphicsView::flipView(bool horizontal)
{
if (horizontal) {
scale(-1, 1);
} else {
scale(1, -1);
}
// I guess we don't need to check if we need to trigger navigator view here
// since fliping doesn't affact the image rectangle size.
}
void GraphicsView::resetScale()
{
resetWithScaleAndRotate(1, m_rotateAngle);

View File

@ -26,6 +26,7 @@ public:
void resetTransform();
void zoomView(qreal scaleFactor);
void flipView(bool horizontal = true);
void resetScale();
void rotateView(qreal rotateAngel);
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);

View File

@ -420,6 +420,10 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
menu->addAction(paste);
}
menu->addSeparator();
menu->addAction(m_am->actionHorizontalFlip);
menu->addSeparator();
menu->addAction(stayOnTopMode);
menu->addAction(protectedMode);
@ -554,6 +558,11 @@ void MainWindow::on_actionZoomOut_triggered()
m_graphicsView->zoomView(0.8);
}
void MainWindow::on_actionHorizontalFlip_triggered()
{
m_graphicsView->flipView();
}
void MainWindow::on_actionCopyPixmap_triggered()
{
QClipboard *cb = QApplication::clipboard();

View File

@ -65,6 +65,7 @@ protected:
private slots:
void on_actionZoomIn_triggered();
void on_actionZoomOut_triggered();
void on_actionHorizontalFlip_triggered();
void on_actionCopyPixmap_triggered();
void on_actionCopyFilePath_triggered();
void on_actionPaste_triggered();