Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotReady: add custom image rotation #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QImageWriter>
#include <QClipboard>
#include <QPainter>
#include <QInputDialog>
#include <QPrintDialog>
#include <QPrinter>
#include <QWheelEvent>
Expand Down Expand Up @@ -645,46 +646,45 @@ QGraphicsItem* MainWindow::getGraphicsItem() {
}

void MainWindow::on_actionRotateClockwise_triggered() {
QGraphicsItem *graphItem = getGraphicsItem();
bool isGifOrSvg (graphItem->isWidget() // we have gif animation
|| dynamic_cast<QGraphicsSvgItem*>(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<QGraphicsSvgItem*>(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);
}

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);
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
83 changes: 38 additions & 45 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
</property>
<property name="windowIcon">
<iconset theme="lximage-qt">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -101,6 +109,7 @@
</property>
<addaction name="actionRotateClockwise"/>
<addaction name="actionRotateCounterclockwise"/>
<addaction name="actionRotateCustom"/>
<addaction name="actionFlipHorizontal"/>
<addaction name="actionFlipVertical"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -152,8 +161,7 @@
<action name="actionAbout">
<property name="icon">
<iconset theme="help-about">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;About</string>
Expand All @@ -162,8 +170,7 @@
<action name="actionOpenFile">
<property name="icon">
<iconset theme="document-open">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Open File</string>
Expand All @@ -175,8 +182,7 @@
<action name="actionSave">
<property name="icon">
<iconset theme="document-save">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Save</string>
Expand All @@ -188,8 +194,7 @@
<action name="actionSaveAs">
<property name="icon">
<iconset theme="document-save-as">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Save &amp;As</string>
Expand All @@ -201,8 +206,7 @@
<action name="actionClose">
<property name="icon">
<iconset theme="application-exit">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Close</string>
Expand All @@ -214,8 +218,7 @@
<action name="actionZoomIn">
<property name="icon">
<iconset theme="zoom-in">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Zoom &amp;In</string>
Expand All @@ -227,8 +230,7 @@
<action name="actionZoomOut">
<property name="icon">
<iconset theme="zoom-out">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Zoom &amp;Out</string>
Expand All @@ -240,8 +242,7 @@
<action name="actionCopy">
<property name="icon">
<iconset theme="edit-copy">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Copy to Clipboard</string>
Expand All @@ -250,8 +251,7 @@
<action name="actionNext">
<property name="icon">
<iconset theme="go-next">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Next File</string>
Expand All @@ -266,8 +266,7 @@
<action name="actionPrevious">
<property name="icon">
<iconset theme="go-previous">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Previous File</string>
Expand All @@ -282,8 +281,7 @@
<action name="actionOriginalSize">
<property name="icon">
<iconset theme="zoom-original">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Original Size</string>
Expand All @@ -295,8 +293,7 @@
<action name="actionZoomFit">
<property name="icon">
<iconset theme="zoom-fit-best">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Fit</string>
Expand All @@ -305,8 +302,7 @@
<action name="actionRotateClockwise">
<property name="icon">
<iconset theme="object-rotate-right">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Rotate Clockwise</string>
Expand All @@ -315,8 +311,7 @@
<action name="actionRotateCounterclockwise">
<property name="icon">
<iconset theme="object-rotate-left">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Rotate &amp;Counterclockwise</string>
Expand All @@ -338,8 +333,7 @@
<action name="actionFirst">
<property name="icon">
<iconset theme="go-first">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>First File</string>
Expand All @@ -351,8 +345,7 @@
<action name="actionLast">
<property name="icon">
<iconset theme="go-last">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Last File</string>
Expand All @@ -364,8 +357,7 @@
<action name="actionNewWindow">
<property name="icon">
<iconset theme="document-new">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;New Window</string>
Expand All @@ -382,8 +374,7 @@
<action name="actionScreenshot">
<property name="icon">
<iconset theme="camera-photo">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Capture Screenshot</string>
Expand All @@ -408,8 +399,7 @@
<action name="actionPaste">
<property name="icon">
<iconset theme="edit-paste">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Paste from Clipboard</string>
Expand All @@ -421,8 +411,7 @@
</property>
<property name="icon">
<iconset theme="media-playback-start">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Slide Show</string>
Expand All @@ -431,8 +420,7 @@
<action name="actionDelete">
<property name="icon">
<iconset theme="edit-delete">
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Delete</string>
Expand All @@ -454,6 +442,11 @@
<string>File Properties</string>
</property>
</action>
<action name="actionRotateCustom">
<property name="text">
<string>Rotate Custom</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down