From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/charts/ChartMarker.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/charts/ChartMarker.cpp (limited to 'src/charts/ChartMarker.cpp') diff --git a/src/charts/ChartMarker.cpp b/src/charts/ChartMarker.cpp new file mode 100644 index 0000000..7fdd8cd --- /dev/null +++ b/src/charts/ChartMarker.cpp @@ -0,0 +1,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); +} -- cgit