Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. void MainWindow::mousePressEvent(QMouseEvent *e)
  2. {
  3. if (e->button()==Qt::LeftButton)
  4.  
  5. {
  6. selectionStarted=true;
  7. selectionRect.setTopLeft(e->pos());
  8. selectionRect.setBottomRight(e->pos());
  9. rb->setGeometry(selectionRect);
  10. rb->show();
  11. }
  12. }
  13. void MainWindow::mouseMoveEvent(QMouseEvent *e)
  14. {
  15.  
  16. if (selectionStarted)
  17. {
  18. selectionRect.setBottomRight(e->pos());
  19. rb->setGeometry(selectionRect);
  20. rb->show();
  21. repaint();
  22. }
  23. }
  24. void MainWindow::mouseReleaseEvent(QMouseEvent *e)
  25. {
  26. selectionStarted=false;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. void MainWindow::on_pushButton_8_clicked()
  34. {
  35. if(selectionRect.width() > 5 && selectionRect.height() > 5 && !rb->isHidden()){
  36. QPoint start = ui->edit_label->mapFromGlobal(selectionRect.topLeft());
  37. int h = (ui->edit_label->rect().height() - ui->edit_label->pixmap()->rect().height())/2 - 23, w = (ui->edit_label->rect().width() - ui->edit_label->pixmap()->rect().width())/2;
  38. ui->edit_label->setPixmap(ui->edit_label->pixmap()->copy(start.x() - w, start.y() - h, selectionRect.width(),selectionRect.height()));
  39. ui->edit_label->show();
  40. fileName = "C:/Users/Youssef Yossry/Desktop/3rd Year-First Term/HCI/PRO/workspace/current";
  41. angle=0;
  42. QFile file(fileName);
  43. file.open(QIODevice::WriteOnly);
  44. ui->edit_label->pixmap()->save(&file, "PNG");
  45. add_to_undo(*ui->edit_label->pixmap(), angle);
  46. redo.clear();
  47. redoAngle.clear();
  48. rb->hide();
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement