-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybubble.cpp
151 lines (120 loc) · 3.04 KB
/
mybubble.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "mybubble.h"
MyBubble::MyBubble(qreal d,int dur):QGraphicsObject(),
diameter(d),
velocity(0,0)
{
setPos(QPoint(qrand()%400,qrand()%400));
anim=new QPropertyAnimation(this,"pos");
anim->setEasingCurve(QEasingCurve::Linear);
anim->setDuration(dur);
position=pos();
}
MyBubble::MyBubble(qreal d, qreal x, qreal y,int dur):QGraphicsObject(),
diameter(d),
velocity(0,0)
{
setPos(QPointF(x,y));
anim=new QPropertyAnimation(this,"pos");
anim->setEasingCurve(QEasingCurve::Linear);
anim->setDuration(dur);
position=pos();
}
MyBubble::MyBubble(qreal d, QPointF v, QPointF p,int dur):QGraphicsObject(),
diameter(d),
velocity(v)
{
setPos(p);
anim=new QPropertyAnimation(this,"pos");
anim->setEasingCurve(QEasingCurve::Linear);
anim->setDuration(dur);
position=pos();
}
MyBubble::MyBubble(const MyBubble &bubble):QGraphicsObject(),
diameter(bubble.diameter),
velocity(0,0)
{
setPos(bubble.pos());
position=pos();
anim=new QPropertyAnimation(this,"pos");
anim->setEasingCurve(QEasingCurve::Linear);
anim->setDuration(bubble.anim->duration());
}
MyBubble::~MyBubble()
{
}
QRectF MyBubble::boundingRect() const
{
return QRectF(-diameter/2,-diameter/2,diameter,diameter);
}
void MyBubble::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
//painter->setRenderHint(QPainter::Antialiasing);
// if (collidingItems().isEmpty())
// {
// painter->setPen(Qt::blue);
// }
// else
// {
// painter->setPen(Qt::red);
// }
painter->drawEllipse(boundingRect());
// painter->setPen(Qt::green);
// painter->drawRect(boundingRect());
}
QPainterPath MyBubble::shape() const
{
QPainterPath path;
path.addEllipse(boundingRect());
return path;
}
void MyBubble::advance(int phase)
{
if (phase)
{
//setPos(position);
anim->start();
}
else
{
if (anim->state() == QPropertyAnimation::Running)
{
anim->setCurrentTime(anim->totalDuration());
}
if (anim->state() ==QPropertyAnimation::Stopped)
{
anim->setEndValue(position);
}
}
}
QPointF MyBubble::getV()
{
return velocity;
}
void MyBubble::setV(const QPointF &value)
{
velocity=value;
}
qreal MyBubble::getDiameter()
{
return diameter;
}
void MyBubble::setDiameter(const qreal &value)
{
diameter = value;
}
QPointF MyBubble::getPosition() const
{
return position;
}
void MyBubble::setPosition(const QPointF &value)
{
position = value;
}
int MyBubble::getFrameDuration() const
{
return anim->duration();
}
void MyBubble::setFrameDuration(int value)
{
anim->setDuration(value);
}