From 6a9e5e80d054db6179e077f8ebe5d2a91368c8a0 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 19 Mar 2021 23:11:06 +0800 Subject: [PATCH] feat: basic image flip support --- app/actionmanager.cpp | 2 ++ app/actionmanager.h | 1 + app/graphicsview.cpp | 11 +++++++++++ app/graphicsview.h | 1 + app/mainwindow.cpp | 9 +++++++++ app/mainwindow.h | 1 + 6 files changed, 25 insertions(+) diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index c0d2546..c87523d 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -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)); diff --git a/app/actionmanager.h b/app/actionmanager.h index e8fe8e7..cb31694 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -18,6 +18,7 @@ public: public: QAction *actionZoomIn; QAction *actionZoomOut; + QAction *actionHorizontalFlip; QAction *actionCopyPixmap; QAction *actionCopyFilePath; QAction *actionPaste; diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index ef363a4..d2a3346 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -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); diff --git a/app/graphicsview.h b/app/graphicsview.h index 79deb2f..708245e 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -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); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 242adf3..ed413a8 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -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(); diff --git a/app/mainwindow.h b/app/mainwindow.h index d12c6ed..0eb2a8d 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -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();