forked from KamelMoohamed/CMP2241_F21_Team01_IRO_Painting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure.cpp
92 lines (78 loc) · 1.99 KB
/
figure.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 "figure.h"
#include <QPainter>
// Initializing the shapes counters to 1
int Figure::rCount = 1;
int Figure::cCount = 1;
int Figure::lCount = 1;
int Figure::tCount = 1;
/*
* Figure Constructor that initialize the Start and End points.
*/
Figure::Figure(QPointF point, QObject *parent) :
QObject(parent), QGraphicsItem()
{
this->setStartPoint(mapFromScene(point));
this->setEndPoint(mapFromScene(point));
setFlag(QGraphicsItem::ItemIsSelectable);
connect(this, &Figure::pointChanged, this, &Figure::updateCircle);
}
Figure::~Figure()
{
}
QRectF Figure::boundingRect() const
{
return QRectF((endPoint().x() > startPoint().x() ? startPoint().x() : endPoint().x()) - 5,
(endPoint().y() > startPoint().y() ? startPoint().y() : endPoint().y()) - 5,
qAbs(endPoint().x() - startPoint().x()) + 10,
qAbs(endPoint().y() - startPoint().y()) + 10);
}
void Figure::updateCircle()
{
this->update((endPoint().x() > startPoint().x() ? startPoint().x() : endPoint().x()) - 5,
(endPoint().y() > startPoint().y() ? startPoint().y() : endPoint().y()) - 5,
qAbs(endPoint().x() - startPoint().x()) + 10,
qAbs(endPoint().y() - startPoint().y()) + 10);
}
/*
* -------------------------------------------
* Setters and Getters
* -------------------------------------------
*/
/*
* start point setter
*/
void Figure::setStartPoint(const QPointF point)
{
m_startPoint = mapFromScene(point);
emit pointChanged();
}
/*
* end point setter
*/
void Figure::setEndPoint(const QPointF point, bool test)
{
if(test){
m_endPoint = mapFromScene(point);
emit pointChanged();}
else{
m_endPoint = point;
emit pointChanged();
}
}
/*
* start point getter
*/
QPointF Figure::startPoint() const
{
return m_startPoint;
}
/*
* end point getter
*/
QPointF Figure::endPoint() const
{
return m_endPoint;
}
void Figure :: countZero(){
lCount= rCount=cCount=tCount=1;
}