Use the canonical file name also for the "already open" check
[GPXSee.git] / src / GUI / infoitem.cpp
blob4f7bb0eb3e1dd33e9a8b678ed6863f86688d4509
1 #include <QFont>
2 #include <QPainter>
3 #include "font.h"
4 #include "infoitem.h"
6 #define PADDING 10
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);
17 qreal width = 0;
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)
23 width += PADDING;
26 _boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height());
29 void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
30 QWidget *widget)
32 Q_UNUSED(option);
33 Q_UNUSED(widget);
34 QFontMetrics fm(_font);
35 int width = 0;
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) {
46 width += PADDING;
47 painter->save();
48 painter->setPen(Qt::gray);
49 painter->drawLine(width - PADDING/2, fm.descent(),
50 width - PADDING/2, fm.height() - fm.descent());
51 painter->restore();
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)
63 return i;
65 return -1;
68 void InfoItem::insert(const QString &key, const QString &value)
70 int i;
72 prepareGeometryChange();
74 if ((i = indexOf(key)) < 0)
75 _list.append(KV<QString, QString>(key, value));
76 else
77 _list[i] = KV<QString, QString>(key, value);
79 updateBoundingRect();
80 update();
83 void InfoItem::clear()
85 prepareGeometryChange();
86 _list.clear();
87 updateBoundingRect();