3 #include <QGraphicsSceneMouseEvent>
7 #include "pathtickitem.h"
10 static QFont
defaultFont()
13 font
.setPixelSize(10);
14 font
.setFamily(FONT_FAMILY
);
20 QFont
PathTickItem::_font
= defaultFont();
22 PathTickItem::PathTickItem(const QRectF
&tickRect
, int value
,
23 QGraphicsItem
*parent
) : GraphicsItem(parent
), _tickRect(tickRect
),
24 _text(QString::number(value
))
26 _tickRect
.moveCenter(QPointF(0, -_tickRect
.height()/2.0 - 3));
28 setCursor(Qt::ArrowCursor
);
29 setAcceptHoverEvents(true);
32 QRectF
PathTickItem::boundingRect() const
34 return _tickRect
.adjusted(0, 0, 0, 3);
37 void PathTickItem::paint(QPainter
*painter
,
38 const QStyleOptionGraphicsItem
*option
, QWidget
*widget
)
43 QPointF arrow
[3] = {QPointF(0, 0), QPointF(3, -3), QPointF(-3, -3)};
45 painter
->setFont(_font
);
46 painter
->setRenderHint(QPainter::Antialiasing
, false);
48 painter
->setPen(Qt::white
);
49 painter
->setBrush(_brush
);
50 painter
->drawPolygon(arrow
, 3);
51 painter
->drawRoundedRect(_tickRect
, 1.5, 1.5);
52 painter
->drawText(_tickRect
, Qt::AlignCenter
, _text
);
55 painter->setBrush(Qt::NoBrush);
56 painter->setPen(Qt::red);
57 painter->drawRect(boundingRect());
61 void PathTickItem::setPos(const QPointF
&pos
)
63 /* For propper rounded rect rendering, the item must be positioned in the
65 QPoint
p(pos
.toPoint());
66 QGraphicsItem::setPos(QPointF(p
.x() - 0.5, p
.y() - 0.5));
69 QRect
PathTickItem::tickRect(int value
)
71 QFontMetrics
fm(_font
);
72 return fm
.boundingRect(QRect(), Qt::AlignCenter
,
73 QString::number(qMax(value
, 10))).adjusted(-2, 0, 2, 0);
76 void PathTickItem::mousePressEvent(QGraphicsSceneMouseEvent
*event
)
78 const PathItem
*pi
= static_cast<PathItem
*>(parentItem());
79 Popup::show(event
->screenPos(), pi
->info(), event
->widget());
80 QGraphicsItem::mousePressEvent(event
);