8 InfoItem::InfoItem(QGraphicsItem
*parent
) : QGraphicsItem(parent
)
10 _font
.setPixelSize(FONT_SIZE
);
11 _font
.setFamily(FONT_FAMILY
);
14 void InfoItem::updateBoundingRect()
16 QFontMetrics
fm(_font
);
19 for (QList
<KV
<QString
, QString
> >::const_iterator i
= _list
.constBegin();
20 i
!= _list
.constEnd(); i
++) {
21 width
+= fm
.horizontalAdvance(i
->key() + ": " + i
->value());
22 if (i
!= _list
.constEnd() - 1)
26 _boundingRect
= QRectF(0, 0, width
, _list
.isEmpty() ? 0 : fm
.height());
29 void InfoItem::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
34 QFontMetrics
fm(_font
);
37 painter
->setFont(_font
);
38 painter
->setRenderHint(QPainter::Antialiasing
, false);
40 for (QList
<KV
<QString
, QString
> >::const_iterator i
= _list
.constBegin();
41 i
!= _list
.constEnd(); i
++) {
42 QString
text(i
->key() + ": " + i
->value());
43 painter
->drawText(width
, fm
.height() - fm
.descent(), text
);
44 width
+= fm
.horizontalAdvance(text
);
45 if (i
!= _list
.constEnd() - 1) {
48 painter
->setPen(Qt::gray
);
49 painter
->drawLine(width
- PADDING
/2, fm
.descent(),
50 width
- PADDING
/2, fm
.height() - fm
.descent());
55 //painter->setPen(Qt::red);
56 //painter->drawRect(boundingRect());
59 int InfoItem::indexOf(const QString
&key
) const
61 for (int i
= 0; i
< _list
.size(); i
++)
62 if (_list
.at(i
).key() == key
)
68 void InfoItem::insert(const QString
&key
, const QString
&value
)
72 prepareGeometryChange();
74 if ((i
= indexOf(key
)) < 0)
75 _list
.append(KV
<QString
, QString
>(key
, value
));
77 _list
[i
] = KV
<QString
, QString
>(key
, value
);
83 void InfoItem::clear()
85 prepareGeometryChange();