forked from KamelMoohamed/CMP2241_F21_Team01_IRO_Painting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.cpp
62 lines (45 loc) · 1.59 KB
/
rectangle.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
#include "rectangle.h"
#include <QPainter>
#include <QUndoCommand>
#include "commands.h"
Rectangle::Rectangle(QPointF point,QColor color,int LineWeight, QColor fillColor, QObject *parent) :
Figure(point,parent)
{
/*
* Setting the color and Line weight and then make the name
* Accoding to a counter to the class shapes (rCount)
*/
Q_UNUSED(point)
shapeColor=color;
this->LineWeight=LineWeight;
this->name=QString("Rectangle %1").arg(rCount);
this->fillColor = fillColor;
rCount++;
}
Rectangle::~Rectangle()
{
}
void Rectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(shapeColor, LineWeight));
if(fillColor != Qt::white){
painter->setBrush(Qt::SolidPattern);
painter->setBrush(fillColor);
}
else{
painter->setBrush(Qt::NoBrush);
}
shapeTypeName = "Rectangle";
QRectF rect(endPoint().x() > startPoint().x() ? startPoint().x() : endPoint().x(),
endPoint().y() > startPoint().y() ? startPoint().y() : endPoint().y(),
qAbs(endPoint().x() - startPoint().x()),
qAbs(endPoint().y() - startPoint().y()));
QLineF line1(rect.bottomLeft().x(),rect.bottomLeft().y(),rect.bottomRight().x(),rect.bottomRight().y());
this->sideLen1= line1.length();
QLineF line2(rect.bottomLeft().x(),rect.bottomLeft().y(),rect.topLeft().x(),rect.topLeft().y());
this->sideLen2= line2.length();
this-> perimeter=(sideLen1+sideLen2)*2;
painter->drawRect(rect);
Q_UNUSED(option)
Q_UNUSED(widget)
}