From f149ef311d71b7abc01ab26ff4cf27195e387e57 2012-11-13 09:11:57 From: Marek Rosa Date: 2012-11-13 09:11:57 Subject: [PATCH] Added hovered support to scatter series --- diff --git a/src/scatterchart/scatterchartitem.cpp b/src/scatterchart/scatterchartitem.cpp index cedbd74..8e8e2c1 100644 --- a/src/scatterchart/scatterchartitem.cpp +++ b/src/scatterchart/scatterchartitem.cpp @@ -96,6 +96,11 @@ void ScatterChartItem::markerSelected(QGraphicsItem *marker) emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); } +void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state) +{ + emit XYChart::hovered(calculateDomainPoint(m_markerMap[marker]), state); +} + void ScatterChartItem::updateGeometry() { diff --git a/src/scatterchart/scatterchartitem_p.h b/src/scatterchart/scatterchartitem_p.h index f127dee..c64322d 100644 --- a/src/scatterchart/scatterchartitem_p.h +++ b/src/scatterchart/scatterchartitem_p.h @@ -55,6 +55,7 @@ public: void setBrush(const QBrush &brush); void markerSelected(QGraphicsItem *item); + void markerHovered(QGraphicsItem *item, bool state); public Q_SLOTS: void handleUpdated(); @@ -84,6 +85,7 @@ public: : QGraphicsEllipseItem(x, y, w, h, parent), m_parent(parent) { + setAcceptHoverEvents(true); } protected: @@ -92,6 +94,16 @@ protected: m_parent->markerSelected(this); QGraphicsEllipseItem::mousePressEvent(event); } + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) + { + m_parent->markerHovered(this, true); + QGraphicsEllipseItem::hoverEnterEvent(event); + } + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) + { + m_parent->markerHovered(this, false); + QGraphicsEllipseItem::hoverLeaveEvent(event); + } private: ScatterChartItem *m_parent; @@ -105,6 +117,7 @@ public: : QGraphicsRectItem(x, y, w, h, parent), m_parent(parent) { + setAcceptHoverEvents(true); } protected: @@ -113,6 +126,16 @@ protected: m_parent->markerSelected(this); QGraphicsRectItem::mousePressEvent(event); } + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) + { + m_parent->markerHovered(this, true); + QGraphicsRectItem::hoverEnterEvent(event); + } + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) + { + m_parent->markerHovered(this, false); + QGraphicsRectItem::hoverLeaveEvent(event); + } private: ScatterChartItem *m_parent;