diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1bf1cc09..4ce7932b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -645,37 +646,32 @@ QGraphicsItem* MainWindow::getGraphicsItem() { } void MainWindow::on_actionRotateClockwise_triggered() { - QGraphicsItem *graphItem = getGraphicsItem(); - bool isGifOrSvg (graphItem->isWidget() // we have gif animation - || dynamic_cast(graphItem)); // an SVG image; - if(!image_.isNull()) { - QTransform transform; - transform.rotate(90.0); - image_ = image_.transformed(transform, Qt::SmoothTransformation); - /* when this is GIF or SVG, we need to rotate its corresponding QImage - without showing it to have the right measure for auto-zooming */ - ui.view->setImage(image_, isGifOrSvg ? false : true); - setModified(true); - } + rotateImage(90); +} - if(isGifOrSvg) { - QTransform transform; - transform.translate(graphItem->sceneBoundingRect().height(), 0); - transform.rotate(90); - // we need to apply transformations in the reverse order - QTransform prevTrans = graphItem->transform(); - graphItem->setTransform(transform, false); - graphItem->setTransform(prevTrans, true); +void MainWindow::on_actionRotateCounterclockwise_triggered() { + rotateImage(-90); +} + +void MainWindow::on_actionRotateCustom_triggered() { + bool rotateImageConfirm; + + int customRotation = QInputDialog::getInt(this, tr("Custom rotation"), + tr("Rotate in degrees"), 0, -360, 360, 1, &rotateImageConfirm); + + if (rotateImageConfirm && customRotation) { + rotateImage(customRotation); } } -void MainWindow::on_actionRotateCounterclockwise_triggered() { +void MainWindow::rotateImage(int rotationInDegrees) { QGraphicsItem *graphItem = getGraphicsItem(); bool isGifOrSvg (graphItem->isWidget() || dynamic_cast(graphItem)); + if(!image_.isNull()) { QTransform transform; - transform.rotate(-90.0); + transform.rotate(rotationInDegrees); image_ = image_.transformed(transform, Qt::SmoothTransformation); ui.view->setImage(image_, isGifOrSvg ? false : true); setModified(true); @@ -683,8 +679,12 @@ void MainWindow::on_actionRotateCounterclockwise_triggered() { if(isGifOrSvg) { QTransform transform; - transform.translate(0, graphItem->sceneBoundingRect().width()); - transform.rotate(-90); + + // FIXME: Better center point calculation on custom rotation + transform.translate(graphItem->sceneBoundingRect().width() / 2, graphItem->sceneBoundingRect().height() / 2); + transform.rotate(rotationInDegrees); + transform.translate(-(graphItem->sceneBoundingRect().width() / 2), -(graphItem->sceneBoundingRect().height() / 2)); + QTransform prevTrans = graphItem->transform(); graphItem->setTransform(transform, false); graphItem->setTransform(prevTrans, true); diff --git a/src/mainwindow.h b/src/mainwindow.h index 0139484e..f7fec9fe 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -97,6 +97,7 @@ private Q_SLOTS: void on_actionRotateClockwise_triggered(); void on_actionRotateCounterclockwise_triggered(); + void on_actionRotateCustom_triggered(); void on_actionFlipVertical_triggered(); void on_actionFlipHorizontal_triggered(); void on_actionCopy_triggered(); @@ -125,6 +126,7 @@ private Q_SLOTS: void onFolderLoaded(FmFolder* folder); void updateUI(); void setModified(bool modified); + void rotateImage(int rotationInDegrees); QModelIndex indexFromPath(FmPath* filePath); QGraphicsItem* getGraphicsItem(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index ad78addb..53db2d34 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -15,15 +15,23 @@ - - + .. 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -101,6 +109,7 @@ + @@ -152,8 +161,7 @@ - - + .. &About @@ -162,8 +170,7 @@ - - + .. &Open File @@ -175,8 +182,7 @@ - - + .. &Save @@ -188,8 +194,7 @@ - - + .. Save &As @@ -201,8 +206,7 @@ - - + .. &Close @@ -214,8 +218,7 @@ - - + .. Zoom &In @@ -227,8 +230,7 @@ - - + .. Zoom &Out @@ -240,8 +242,7 @@ - - + .. &Copy to Clipboard @@ -250,8 +251,7 @@ - - + .. Next File @@ -266,8 +266,7 @@ - - + .. Previous File @@ -282,8 +281,7 @@ - - + .. Original Size @@ -295,8 +293,7 @@ - - + .. &Fit @@ -305,8 +302,7 @@ - - + .. &Rotate Clockwise @@ -315,8 +311,7 @@ - - + .. Rotate &Counterclockwise @@ -338,8 +333,7 @@ - - + .. First File @@ -351,8 +345,7 @@ - - + .. Last File @@ -364,8 +357,7 @@ - - + .. &New Window @@ -382,8 +374,7 @@ - - + .. Capture Screenshot @@ -408,8 +399,7 @@ - - + .. &Paste from Clipboard @@ -421,8 +411,7 @@ - - + .. &Slide Show @@ -431,8 +420,7 @@ - - + .. &Delete @@ -454,6 +442,11 @@ File Properties + + + Rotate Custom + +