-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawingarea.cpp
More file actions
87 lines (68 loc) · 1.94 KB
/
drawingarea.cpp
File metadata and controls
87 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
85
86
#include "drawingarea.h"
#include "sharedPins.h"
DrawingArea::DrawingArea(QWidget *parent) : QWidget(parent)
{
//creating an empty image, making it white
image = QImage(600,400,QImage::Format_RGB32);
image.fill(qRgb(255,255,255));
}
void DrawingArea::mousePressEvent(QMouseEvent *event)
{
//saving position of the click to drawingArea class attribute
if (event->button() & Qt::LeftButton)
startPoint = event->pos();
//making sure correct data is getting serialized
serialize(startPoint.rx(),sCoordinateX);
serialize(startPoint.ry(),sCoordinateY);
//setting data attribute of the thread as starting point coordinates
sThread.setData(sCoordinateX,sCoordinateY);
sThread.start();
//singalling that it is the starting point data that is being sent
sharedPins[20]=1;
}
void DrawingArea::mouseReleaseEvent(QMouseEvent *event)
{
//saving position of the click to drawingArea class attribute
if (event->button() & Qt::LeftButton)
endPoint = event->pos();
//drawing the line between start and endpoint
drawLineTo();
serialize(endPoint.rx(),eCoordinateX);
serialize(endPoint.ry(),eCoordinateY);
sThread.setData(eCoordinateX,eCoordinateY);
sThread.start();
//singalling that it is the ending point data that is being sent
sharedPins[20]=0;
}
void DrawingArea::drawLineTo()
{
QPainter painter(&image);
painter.drawLine(startPoint, endPoint);
update();
}
void DrawingArea::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
rect = event->rect();
painter.drawImage(rect, image, rect);
}
void DrawingArea::clearScreen()
{
image.fill(qRgb(255,255,255));
update();
}
void DrawingArea::serialize(int point, bool *data)
{
for(int i=9;i>=0;i--)
{
if(point%2 == 0)
data[i] = 0;
else
data[i] = 1;
point /= 2;
}
}
void DrawingArea::handleClearButton()
{
sharedPins[10] = 1;
}