Skip to content

Commit 7b2ce7e

Browse files
committed
rotate functionality updated.
1 parent 022cc2f commit 7b2ce7e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

relightlab/imageframe.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ ImageFrame::ImageFrame(QWidget *parent): QFrame(parent) {
6767
connect(image_view, SIGNAL(skipChanged(int,bool)), image_grid, SLOT(setSkipped(int,bool)));
6868
connect(image_view, SIGNAL(skipChanged(int,bool)), image_list, SLOT(setSkipped(int,bool)));
6969

70+
connect(qRelightApp->action("rotate_left"), SIGNAL(triggered(bool)), this, SLOT(rotateLeft()));
71+
connect(qRelightApp->action("rotate_right"), SIGNAL(triggered(bool)), this, SLOT(rotateRight()));
72+
7073
connect(qRelightApp->action("zoom_fit"), SIGNAL(triggered(bool)), image_view, SLOT(fit()));
7174
connect(qRelightApp->action("zoom_one"), SIGNAL(triggered(bool)), image_view, SLOT(one()));
7275
connect(qRelightApp->action("zoom_in"), SIGNAL(triggered(bool)), image_view, SLOT(zoomIn()));
@@ -110,6 +113,40 @@ int ImageFrame::currentImage() {
110113
return image_list->currentRow();
111114
}
112115

116+
void ImageFrame::rotateLeft() {
117+
QList<QListWidgetItem*> selectedItems = image_list->selectedItems();
118+
for(QListWidgetItem *item: selectedItems) {
119+
int id = item->data(Qt::UserRole).toInt();
120+
rotateImage(id, false);
121+
}
122+
showImage(image_list->currentRow());
123+
}
124+
125+
void ImageFrame::rotateRight() {
126+
QList<QListWidgetItem*> selectedItems = image_list->selectedItems();
127+
for(QListWidgetItem *item: selectedItems) {
128+
int id = item->data(Qt::UserRole).toInt();
129+
rotateImage(id, true);
130+
}
131+
showImage(image_list->currentRow());
132+
}
133+
134+
void ImageFrame::rotateImage(int id, bool clockwise) {
135+
QTransform rotate;
136+
rotate.rotate(clockwise ? 90 : -90);
137+
138+
Project &project = qRelightApp->project();
139+
140+
assert(id >= 0 && id < project.images.size());
141+
142+
Image &image = project.images[id];
143+
QImage source(image.filename);
144+
QImage rotated = source.transformed(rotate);
145+
rotated.save(image.filename, "jpg", 100);
146+
//thumbs needs to be rotated!!!
147+
qRelightApp->loadThumbnails();
148+
}
149+
113150
void ImageFrame::showImage(int id) {
114151

115152
Project &project = qRelightApp->project();

relightlab/imageframe.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ class ImageFrame: public QFrame {
3535
void init();
3636
int currentImage();
3737
void showImage(int id); //new project loaded.
38+
void rotateImage(int id, bool clockwise);
3839

3940
public slots:
41+
void rotateLeft();
42+
void rotateRight();
4043
void previousImage();
4144
void nextImage();
4245
void showImageItem(QListWidgetItem *item);

relightlab/imageview.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void ImageView::showImage(int id) {
3131
QMessageBox::critical(this, "Houston we have a problem!", "Could not load image " + filename);
3232
return;
3333
}
34+
if(imagePixmap) {
35+
delete imagePixmap;
36+
}
3437
imagePixmap = new QGraphicsPixmapItem(QPixmap::fromImage(img));
3538
imagePixmap->setZValue(-1);
3639
scene.addItem(imagePixmap);

relightlab/relightapp.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ void RelightApp::loadThumbnails() {
330330
img.fill(Qt::black);
331331
}
332332
m_thumbnails[i] = img.scaledToHeight(256);
333+
emit updateThumbnail(0);
333334
} else {
334335
QImage img(m_thumbnails[0].size().scaled(256, 256, Qt::KeepAspectRatio), QImage::Format_ARGB32);
335336
img.fill(Qt::black);

0 commit comments

Comments
 (0)