-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStelAppGraphicsItem.cpp
68 lines (54 loc) · 1.4 KB
/
StelAppGraphicsItem.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
#include "StelAppGraphicsItem.h"
StelAppGraphicsItem::StelAppGraphicsItem()
{
tail << QPointF(1, 1);
tail << QPointF(10, 10);
tail << QPointF(20, 20);
}
QRectF StelAppGraphicsItem::boundingRect() const
{
qreal minX = 100000;
qreal minY = 100000;
qreal maxX = 0;
qreal maxY = 0;
foreach (QPointF p, tail) {
maxX = p.x() > maxX ? p.x() :maxX;
maxY = p.y() > maxY ? p.y() :maxY;
minX = p.x() < minX ? p.x() :minX;
minY = p.y() < minY ? p.y() :minY;
}
QPointF tl = mapFromScene(QPointF(minX, minY));
QPointF br = mapFromScene(QPointF(maxX, maxY));
QRectF bound = QRectF(tl.x(),
tl.y(),
br.x()-tl.x() +1,
br.y()-tl.y() +1);
return bound;
}
QPainterPath StelAppGraphicsItem::shape() const
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
foreach(QPointF p, tail)
{
QPointF itemp = mapFromScene(p);
path.addEllipse(itemp, 1, 1);
}
return path;
}
void StelAppGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->save();
painter->fillPath(shape(), Qt::yellow);
painter->restore();
}
void StelAppGraphicsItem::advance(int step)
{
if(!step)
return;
// Update
int i = 0;
foreach (QPointF p, tail) {
tail[i++] = p + QPointF(3, 3);
}
}