-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotgraphicsitem.cpp
58 lines (46 loc) · 1.39 KB
/
spotgraphicsitem.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
#include "spotgraphicsitem.h"
#include "spot.h"
#include <QGraphicsEllipseItem>
#include <QGraphicsTextItem>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QDebug>
QPen SpotGraphicsItem::s_emptyPen;
SpotGraphicsItem::SpotGraphicsItem(Spot * spot, QGraphicsItem *parent) :
QGraphicsItem(parent)
{
_spot = spot;
setFlag(QGraphicsItem::ItemIsSelectable);
_text = QString("%1,%2,%3\n%4\n%5").arg(_spot->blockNumber()).arg(_spot->column()).arg(_spot->row()).arg(_spot->id()).arg(_spot->name());
setToolTip(_text);
}
QRectF SpotGraphicsItem::boundingRect () const
{
return QRectF(0,0,_spot->diameter(),_spot->diameter());
}
void SpotGraphicsItem::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
{
qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
if(_spot->isEmpty())
{
painter->setPen(s_emptyPen);
}
if (isSelected())
painter->setPen(QColor("blue"));
painter->drawEllipse(0,0,_spot->diameter(),_spot->diameter());
if( lod >= 0.2 )
painter->drawText(0,0,_spot->diameter(),_spot->diameter(),Qt::AlignCenter,_text);
return;
}
void SpotGraphicsItem::setEmptyPen(QVector<qreal> dashPattern)
{
s_emptyPen.setDashPattern(dashPattern);
}
int SpotGraphicsItem::type() const
{
return Type;
}
Spot * SpotGraphicsItem::spot() const
{
return _spot;
}