-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaintscene.cpp
70 lines (58 loc) · 1.77 KB
/
paintscene.cpp
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
#include "paintscene.h"
paintScene::paintScene(QObject *parent) : QGraphicsScene(parent)
{
color=Qt::black;
line_width=1.0;
line_type=Qt::SolidLine;
empty=true;
}
paintScene::~paintScene()
{
}
void paintScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button()==Qt::LeftButton){
addEllipse(event->scenePos().x()-line_width/2, event->scenePos().y()-line_width/2,
line_width, line_width, QPen(Qt::NoPen), QBrush(color));
previousPoint = event->scenePos();
if(empty) empty=false;
}
else if(event->button()==Qt::RightButton){
addEllipse(event->scenePos().x()-line_width/2, event->scenePos().y()-line_width/2,
line_width, line_width, QPen(Qt::NoPen), QBrush(Qt::white));
previousPoint = event->scenePos();
}
}
void paintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if(event->buttons() & Qt::LeftButton){
addLine(previousPoint.x(), previousPoint.y(), event->scenePos().x(),
event->scenePos().y(), QPen(color, line_width, line_type, Qt::RoundCap));
previousPoint = event->scenePos();
if(empty) empty=false;
}
else if(event->buttons() & Qt::RightButton){
addLine(previousPoint.x(), previousPoint.y(), event->scenePos().x(),
event->scenePos().y(), QPen(Qt::white, line_width, Qt::SolidLine, Qt::RoundCap));
previousPoint = event->scenePos();
}
}
void paintScene::set_color(QColor color)
{
this->color=color;
}
void paintScene::set_width(qreal line_width)
{
this->line_width=line_width;
}
void paintScene::set_line_type(Qt::PenStyle line_type)
{
this->line_type=line_type;
}
bool paintScene::isEmpty(){
return empty;
}
void paintScene::set_empty()
{
empty=true;
}