1
0

Add view rotation.

This commit is contained in:
Jarosław Wieczorek 2021-04-08 08:28:03 +02:00
parent fe76bebf75
commit 5dd64252ee
3 changed files with 71 additions and 6 deletions

View File

@ -658,20 +658,26 @@ void Tools::zoom(float factor)
void Tools::rotate90() void Tools::rotate90()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; ImageViewer* iv = getViewer();
// TODO if (!iv)
return;
iv->rotate(90);
} }
void Tools::rotate180() void Tools::rotate180()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; ImageViewer* iv = getViewer();
// TODO if (!iv)
return;
iv->rotate(180);
} }
void Tools::rotate270() void Tools::rotate270()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; ImageViewer* iv = getViewer();
// TODO if (!iv)
return;
iv->rotate(270);
} }

View File

@ -8,6 +8,7 @@
#include <QResizeEvent> #include <QResizeEvent>
#include <QFileInfo> #include <QFileInfo>
#include <iostream>
ImageViewer::ImageViewer(QWidget* parent) : ImageViewer::ImageViewer(QWidget* parent) :
QWidget(parent), QWidget(parent),
@ -17,6 +18,7 @@ ImageViewer::ImageViewer(QWidget* parent) :
ui->dial->setVisible(false); ui->dial->setVisible(false);
histogramView = 0; histogramView = 0;
resetZoom(); resetZoom();
resetRotate();
locked = false; locked = false;
} }
@ -46,6 +48,24 @@ void ImageViewer::resetZoom()
_zoomRatio = 1.0f; _zoomRatio = 1.0f;
} }
int ImageViewer::getRotate()
{
return int(_rotateDegree);
}
void ImageViewer::setRotate(int factor)
{
resetRotate();
rotate(factor);
}
void ImageViewer::resetRotate()
{
_rotateDegree = 0.0;
}
/** /**
* loads an image from given path and shows it in the viewer * loads an image from given path and shows it in the viewer
* Clears the history of the IV * Clears the history of the IV
@ -63,6 +83,7 @@ bool ImageViewer::loadImage(QString path)
history.clear(); history.clear();
resetZoom(); resetZoom();
resetRotate();
updateImage(image); updateImage(image);
updateTitle(); updateTitle();
@ -95,6 +116,7 @@ void ImageViewer::updateImage()
emit imageChanged(image); emit imageChanged(image);
emit imageUpdated(); emit imageUpdated();
setZoom(getZoom()); // best solution ever setZoom(getZoom()); // best solution ever
setRotate(getRotate());
} }
else else
qWarning("No image on the history list"); qWarning("No image on the history list");
@ -327,6 +349,36 @@ void ImageViewer::zoom(double factor)
updateTitle(); updateTitle();
} }
void ImageViewer::rotate(int degree)
{
QImage rotatedImage = getImage()->copy();
QPoint center = rotatedImage.rect().center();
QTransform *rotate_matrix = new QTransform();
_rotateDegree = getRotate() + degree;
if (_rotateDegree % 360 == 0){
_rotateDegree = 0;
}
else{
_rotateDegree = int(_rotateDegree % 360);
}
rotate_matrix->translate(center.x(), center.y());
rotate_matrix->rotate(_rotateDegree);
rotatedImage = rotatedImage.transformed(*rotate_matrix, Qt::FastTransformation);
delete rotate_matrix;
ui->imageLabel->move(0,0);
ui->imageLabel->resize(rotatedImage.size());
ui->imageLabel->setPixmap(QPixmap::fromImage(rotatedImage));
resize(rotatedImage.size());
updateTitle();
}
void ImageViewer::transformationStarted() void ImageViewer::transformationStarted()
{ {
locked = true; locked = true;

View File

@ -31,6 +31,12 @@ public:
void resetZoom(); void resetZoom();
void zoom(double); void zoom(double);
int getRotate();
void setRotate(int);
void resetRotate();
void rotate(int);
PNM* getImage(); PNM* getImage();
HistogramViewer* getHistogramWindow(); HistogramViewer* getHistogramWindow();
bool loadImage(QString); bool loadImage(QString);
@ -65,6 +71,7 @@ private:
Ui::ImageViewer* ui; Ui::ImageViewer* ui;
HistogramViewer* histogramView; HistogramViewer* histogramView;
float _zoomRatio; float _zoomRatio;
int _rotateDegree;
QString _filename; QString _filename;
QString _path; QString _path;
QList<PNM*> history; QList<PNM*> history;