Вы находитесь на странице: 1из 2

void ImageViewer::rotateRight()

{
QString result = QInputDialog::getText(0, " Rotate right ", "Enter Angle val
ue (in degrees):"); // positive numbers
bool ok; // check if error occurs
angle = result.toInt(&ok); // get the angle
if(result.length() == 0){
return ;
}
// check if the user enter invalid angle then show the error message
if (!ok || angle<0){
QMessageBox Msgbox;
Msgbox.setText("ERROR !! Invalid angle, angle value must be a positive n
umber");
Msgbox.exec();
}
else{
if(stackUndo.size() == 0){
stackUndo.push(StackObj(*globalImage->pixmap(),*imageLabel->pixmap()
,0));
}
QPixmap pixmap(*globalImage->pixmap()); // get the image pixmap
QTransform rotate_disc ;
rotate_disc.translate(pixmap.width()/2.0 , pixmap.height()/2.0); // make
the image rotate from orginal point
old_angle+=angle; // set the new angle
rotate_disc.rotate(old_angle); // rotate the image
rotate_disc.translate(-pixmap.width()/2.0 , -pixmap.height()/2.0);
rotate_disc.scale(1, 1);
fitToWindow();
pixmap = pixmap.transformed(rotate_disc);
imageLabel->setPixmap(pixmap);
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
StackObj o (*globalImage->pixmap(),*imageLabel->pixmap(),old_angle); //
create the stack object with this pixmap and the angle
stackUndo.push(o); // push the current object in undo stack
stackRedo.clear(); // new
redoAct->setEnabled(false); // new
undoAct->setEnabled(true);
}
}
//******************************************************************************
***********************************
/*
* this function rotate left the image by enter the angle and press ok
* the image will rotate to the left side with this angle
* you can enter positive numbers
* negative numbers and char not allowed
*/
void ImageViewer::rotateLeft()
{
QString result = QInputDialog::getText(0, " Rotate left", "Enter Angle value
(in degrees):"); // positive numbers
bool ok; // to check if error occurs
angle = result.toInt(&ok);
if(result.length() == 0){
return ;
}
// check if error happen then return an error message
if (!ok || angle <0){
QMessageBox Msgbox;
Msgbox.setText("ERROR !! Invalid angle, angle value must be a positive numb
er");
Msgbox.exec();
}
else{
if(stackUndo.size() == 0){
stackUndo.push(StackObj(*globalImage->pixmap(),*imageLabel->pixmap()
,0));
}
QPixmap pixmap(*globalImage->pixmap()); // get the pixmap of image
// StackObj o (pixmap,old_angle); // create an object
// stackUndo.push(o); // push this object in the stack
// stackRedo.clear(); // new
// redoAct->setEnabled(false); // new
// undoAct->setEnabled(true);
QTransform rotate_disc ;
rotate_disc.translate(pixmap.width()/2.0 , pixmap.height()/2.0); // retu
rn the image to the orginal position
old_angle-=angle; // get new angle
rotate_disc.rotate(old_angle); // rotate the image
rotate_disc.translate(-pixmap.width()/2.0 , -pixmap.height()/2.0);
rotate_disc.scale(1, 1);
fitToWindow();
pixmap = pixmap.transformed(rotate_disc);
imageLabel->setPixmap(pixmap);
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
StackObj o (*globalImage->pixmap(),*imageLabel->pixmap(),old_angle); //
create the stack object with this pixmap and the angle
stackUndo.push(o); // push the current object in undo stack
stackRedo.clear(); // new
redoAct->setEnabled(false); // new
undoAct->setEnabled(true);
}
}

Вам также может понравиться