forked from magnocube/POV-Globe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customrect.cpp
92 lines (60 loc) · 2.09 KB
/
customrect.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "customrect.h"
CustomRect::CustomRect()
{
x_location =0;
y_location =0;
width =50;
height =50;
color = Qt::green;
rotation =0;
lineColor = Qt::black;
lineThickness =1;
setFlag(ItemIsSelectable);
setFlag(ItemIsMovable);
}
QRectF CustomRect::boundingRect() const
{
return QRectF(x_location,y_location,width,height);
}
void CustomRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->rotate(rotation);
QRectF rec = boundingRect();
// QBrush brush(color);
// QPen pen(lineColor);
// pen.setWidth(lineThickness);
// painter->setPen(pen);
// painter->setBrush(brush);
// painter->drawRect(rec);
painter->setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.addRoundedRect(rec, borderRadius, borderRadius);
QPen pen(lineColor, lineThickness);
painter->setPen(pen);
painter->fillPath(path, color);
painter->drawPath(path);
}
void CustomRect::resize(int w, int h)
{
width = w;
height = h;
}
void CustomRect::newProperties(int width, int height, int lineThichness, int rotation, QColor backColor, QColor lineColor, int borderRadius)
{
qDebug() << width << " " << height << " " << lineThichness << " " << rotation << " " << backColor.name() << " " << lineColor.name() << " " << borderRadius;
this->width = width;
this->height = height;
this->lineThickness = lineThichness;
this->rotation = rotation;
this->color = backColor;
this->lineColor = lineColor;
this->borderRadius = borderRadius;
emit updateGraphics();
}
void CustomRect::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e)
{
CustomRect_Editor * myEditor = new CustomRect_Editor(width,height,color,lineColor,lineThickness,rotation,borderRadius); //dont forget to delete this pointer from the heap when the wondow closes
connect(myEditor,SIGNAL(propertyChanged(int,int,int,int,QColor,QColor,int)),this,SLOT(newProperties(int,int,int,int,QColor,QColor,int)));
myEditor->show();
//Todo,,, find a solution to removing the windows
}