-
Notifications
You must be signed in to change notification settings - Fork 0
/
PendulumGraphicsItem.cpp
105 lines (88 loc) · 2.28 KB
/
PendulumGraphicsItem.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
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "PendulumGraphicsItem.h"
#include <QPainter>
PendulumGraphicsItem::PendulumGraphicsItem( QGraphicsItem *parent)
:
QGraphicsItem(parent)
{
}
PendulumGraphicsItem::PendulumGraphicsItem(QPointF centerOfBall, double radius, QGraphicsItem *parent)
:
centerOfBall(centerOfBall),
radius(radius),
colorOfBall(ColorOfBall::Yellow),
QGraphicsItem(parent)
{
this->setSize();
}
PendulumGraphicsItem::PendulumGraphicsItem(QPointF centerOfBall, double radius,
ColorOfBall colorOfBall, QGraphicsItem *parent)
:
centerOfBall(centerOfBall),
radius(radius),
colorOfBall(colorOfBall),
QGraphicsItem(parent)
{
this->setSize();
}
void PendulumGraphicsItem::setCenterOfBall(QPointF centerOfBall)
{
this->centerOfBall = centerOfBall;
}
void PendulumGraphicsItem::setRadius(double radius)
{
this->radius = radius;
}
QPointF PendulumGraphicsItem::getCenterOfBall() const
{
return this->centerOfBall;
}
double PendulumGraphicsItem::getRadius() const
{
return this->radius;
}
QSizeF PendulumGraphicsItem::getSize() const
{
return this->pendulumGraphicsItemSize;
}
int PendulumGraphicsItem::getIndex() const
{
return this->index;
}
void PendulumGraphicsItem::setColor(ColorOfBall colorBall)
{
this->colorOfBall = colorBall;
}
void PendulumGraphicsItem::setSize()
{
this->pendulumGraphicsItemSize = QSize(radius,radius);
}
void PendulumGraphicsItem::setIndex(int index)
{
this->index = index;
}
QRectF PendulumGraphicsItem::boundingRect() const
{
return QRectF(centerOfBall.x()-radius,centerOfBall.y()-radius,
centerOfBall.x()+radius,centerOfBall.y()+radius);
}
void PendulumGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
(void) option;
(void) widget;
switch (colorOfBall) {
case ColorOfBall::Blue :
painter->setBrush(Qt::yellow);
break;
case ColorOfBall::Green :
painter->setBrush(Qt::green);
break;
case ColorOfBall::Red :
painter->setBrush(Qt::red);
break;
case ColorOfBall::Yellow :
painter->setBrush(Qt::yellow);
break;
}
painter->setPen(Qt::black);
painter->drawEllipse(centerOfBall,radius,radius);
}