Commits

Dave Druelinger committed 13e3acf

added image rotation

  • Participants
  • Parent commits 06d0962

Comments (0)

Files changed (3)

File mainwindow.cpp

 
 	imageLoaded = false;
 	scaleFactor = 1;
+	imageRotation = 0;
 	zoomTimer = new QTimer(this);
 
 	gifSelected = false;
 		firstFile();
 	else if (event->key() == Qt::Key_BraceRight)
 		finalFile();
+	else if (event->key() == Qt::Key_R)
+		rotateRight();
+	else if (event->key() == Qt::Key_L)
+		rotateLeft();
 
 	QMainWindow::keyPressEvent(event);
 }
 	}
 }
 
+void MainWindow::rotateRight()
+{
+	if (imageLoaded && ! gifSelected)
+	{
+		imageRotation += 90;
+		if (imageRotation >= 360)
+			imageRotation = 0;
+		openFile();
+	}
+}
+
+void MainWindow::rotateLeft()
+{
+	if (imageLoaded && ! gifSelected)
+	{
+		imageRotation -= 90;
+		if (imageRotation < 0)
+			imageRotation = 270;
+		openFile();
+	}
+}
+
 void MainWindow::openByFileDialog()
 {
 	QString tempFile;
 			return;
 		}
 		pixmappy = QPixmap::fromImage(image);
+		if (imageRotation != 0)
+			pixmappy = pixmappy.transformed(QTransform().rotate(imageRotation));
 		imageLabel->setMovie(NULL);
 		imageLabel->setPixmap(pixmappy);
 	}
 	connect(sortReversedAct, SIGNAL(triggered()), this, SLOT(sortReversed()));
 	sortReversedAct->setCheckable(true);
 
+	rotateRightAct = new QAction(tr("Rotate Right  ( R )"), this);
+	connect(rotateRightAct, SIGNAL(triggered()), this, SLOT(rotateRight()));
+
+	rotateLeftAct = new QAction(tr("Rotate Left  ( L )"), this);
+	connect(rotateLeftAct, SIGNAL(triggered()), this, SLOT(rotateLeft()));
+
 	aboutAct = new QAction(tr("&About"), this);
 	connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
 }
 	viewMenu->addSeparator();
 	viewMenu->addAction(zoomInAct);
 	viewMenu->addAction(zoomOutAct);
+	viewMenu->addAction(rotateRightAct);
+	viewMenu->addAction(rotateLeftAct);
 	viewMenu->addSeparator();
 	viewMenu->addAction(showAllAct);
 	viewMenu->addAction(normalSizeAct);

File mainwindow.h

 	void sortBySize();
 	void sortByType();
 	void sortReversed();
+	void rotateRight();
+	void rotateLeft();
 	void about();
 
 private:
 	QString currentMode;
 	QSize originalSize;
 	double scaleFactor;
+	int imageRotation;
 
 	QMovie *animGif;
 	QPixmap pixmappy;
 	QAction *sortBySizeAct;
 	QAction *sortByTypeAct;
 	QAction *sortReversedAct;
+	QAction *rotateRightAct;
+	QAction *rotateLeftAct;
 	QAction *aboutAct;
 
 	QMenu *fileMenu;
 //right to left reading?
 //command-del sends image to trash?
 //keyboard command to reveal the item in finder
-//could just use a timer instead of animations for arrow (leave for spacebar)
+//could just use a timer instead of animations for arrows (leave for spacebar)
 //zoom centering fucks up on big pictures (could probably be better anyway)
-//rotation with r and l
 
 //add to iusethis