blob: 7fdd8cd9103729a616ced7d5698404c831368836 (
plain)
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
|
#include "ChartMarker.h"
#include "ChartToolTip.h"
const QPointF ChartMarker::ToolTipOffset(45, -35);
const QColor ChartMarker::Color(Qt::blue);
ChartMarker::ChartMarker(const QPointF& center, const QString& toolTipText):
radius(Radius), toolTip(NULL), toolTipText(toolTipText)
{
setPos(center);
setRect(QRectF(-HoverRadius, -HoverRadius,
2 * HoverRadius, 2 * HoverRadius));
setAcceptHoverEvents(true);
}
ChartMarker::~ChartMarker()
{
delete toolTip;
}
void ChartMarker::hoverEnterEvent(QGraphicsSceneHoverEvent*)
{
radius = HighlightedRadius;
update();
if(!toolTip)
createToolTip();
toolTip->show();
}
void ChartMarker::createToolTip()
{
toolTip = new ChartToolTip(mapToScene(ToolTipOffset), toolTipText);
scene()->addItem(toolTip);
toolTip->adjustPos();
}
void ChartMarker::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
{
radius = Radius;
update();
toolTip->hide();
}
void ChartMarker::paint(QPainter* painter, const QStyleOptionGraphicsItem*,
QWidget*)
{
painter->setPen(Color);
painter->setBrush(Color);
painter->drawEllipse(QPointF(), radius, radius);
}
|