Add view rotation.
This commit is contained in:
parent
fe76bebf75
commit
5dd64252ee
@ -658,20 +658,26 @@ void Tools::zoom(float factor)
|
||||
|
||||
void Tools::rotate90()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
ImageViewer* iv = getViewer();
|
||||
if (!iv)
|
||||
return;
|
||||
iv->rotate(90);
|
||||
}
|
||||
|
||||
void Tools::rotate180()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
ImageViewer* iv = getViewer();
|
||||
if (!iv)
|
||||
return;
|
||||
iv->rotate(180);
|
||||
}
|
||||
|
||||
void Tools::rotate270()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
// TODO
|
||||
ImageViewer* iv = getViewer();
|
||||
if (!iv)
|
||||
return;
|
||||
iv->rotate(270);
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <QResizeEvent>
|
||||
#include <QFileInfo>
|
||||
#include <iostream>
|
||||
|
||||
ImageViewer::ImageViewer(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
@ -17,6 +18,7 @@ ImageViewer::ImageViewer(QWidget* parent) :
|
||||
ui->dial->setVisible(false);
|
||||
histogramView = 0;
|
||||
resetZoom();
|
||||
resetRotate();
|
||||
locked = false;
|
||||
}
|
||||
|
||||
@ -46,6 +48,24 @@ void ImageViewer::resetZoom()
|
||||
_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
|
||||
* Clears the history of the IV
|
||||
@ -63,6 +83,7 @@ bool ImageViewer::loadImage(QString path)
|
||||
|
||||
history.clear();
|
||||
resetZoom();
|
||||
resetRotate();
|
||||
updateImage(image);
|
||||
updateTitle();
|
||||
|
||||
@ -95,6 +116,7 @@ void ImageViewer::updateImage()
|
||||
emit imageChanged(image);
|
||||
emit imageUpdated();
|
||||
setZoom(getZoom()); // best solution ever
|
||||
setRotate(getRotate());
|
||||
}
|
||||
else
|
||||
qWarning("No image on the history list");
|
||||
@ -327,6 +349,36 @@ void ImageViewer::zoom(double factor)
|
||||
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()
|
||||
{
|
||||
locked = true;
|
||||
|
@ -31,6 +31,12 @@ public:
|
||||
void resetZoom();
|
||||
void zoom(double);
|
||||
|
||||
int getRotate();
|
||||
void setRotate(int);
|
||||
void resetRotate();
|
||||
void rotate(int);
|
||||
|
||||
|
||||
PNM* getImage();
|
||||
HistogramViewer* getHistogramWindow();
|
||||
bool loadImage(QString);
|
||||
@ -65,6 +71,7 @@ private:
|
||||
Ui::ImageViewer* ui;
|
||||
HistogramViewer* histogramView;
|
||||
float _zoomRatio;
|
||||
int _rotateDegree;
|
||||
QString _filename;
|
||||
QString _path;
|
||||
QList<PNM*> history;
|
||||
|
Loading…
Reference in New Issue
Block a user