-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimageview.cpp
More file actions
executable file
·84 lines (68 loc) · 1.94 KB
/
imageview.cpp
File metadata and controls
executable file
·84 lines (68 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "imageview.h"
ImageView::ImageView(QWidget *parent) :
QGraphicsView(parent)
{
// Initialize our scene items
scene = new QGraphicsScene();
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
origin = new QPoint;
// Default initializer
cropping = false;
// Create the messagee dialog
}
void ImageView::mousePressEvent(QMouseEvent *e)
{
if(cropping)
{
rubberBand->close();
*origin = e->pos();
if(!rubberBand)
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
rubberBand->setGeometry(QRect(*origin, QSize()));
rubberBand->show();
}
}
void ImageView::mouseMoveEvent(QMouseEvent *e)
{
if(cropping)
rubberBand->setGeometry(QRect(*origin, e->pos()).normalized());
}
void ImageView::mouseReleaseEvent(QMouseEvent *e)
{
// If the user selected yes, then crop the image
if(cropping)
{
// Prompt the user of the permanent change they're about to make
QMessageBox confirm;
confirm.setInformativeText("You are about to crop this image, are you sure you wish to continue?");
confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
confirm.setDefaultButton(QMessageBox::Yes);
// Capture the users request
int res = confirm.exec();
if(res == QMessageBox::Yes)
{
rubberBand->close();
QImage copy = image;
QImage crop;
//int x = rubberBand->x();
//int y = rubberBand->y();
int w = rubberBand->width();
int h = rubberBand->height();
crop = copy.copy(0, 0, w, h);
cropping = false;
emit croppedImage(crop);
}
}
}
void ImageView::setCropImage(QImage img)
{
image = img;
}
void ImageView::setCropping(bool isCropping)
{
cropping = isCropping;
}
QGraphicsScene *ImageView::getScene()
{
return this->scene;
}