diff --git a/src/Graphics/GraphicsPoint.cpp b/src/Graphics/GraphicsPoint.cpp index 17bfe6bb..cd1a0a5d 100644 --- a/src/Graphics/GraphicsPoint.cpp +++ b/src/Graphics/GraphicsPoint.cpp @@ -149,6 +149,8 @@ void GraphicsPoint::createPointEllipse (unsigned int radius) m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH)); m_shadowZeroWidthEllipse->setEnabled (true); + + m_graphicsItemEllipse->setShadow (m_shadowZeroWidthEllipse); } void GraphicsPoint::createPointPolygon (const QPolygonF &polygon) @@ -183,6 +185,8 @@ void GraphicsPoint::createPointPolygon (const QPolygonF &polygon) m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH)); m_shadowZeroWidthPolygon->setEnabled (true); + + m_graphicsItemPolygon->setShadow (m_shadowZeroWidthPolygon); } QVariant GraphicsPoint::data (int key) const diff --git a/src/Graphics/GraphicsPointEllipse.cpp b/src/Graphics/GraphicsPointEllipse.cpp index a7c71b96..5692713e 100644 --- a/src/Graphics/GraphicsPointEllipse.cpp +++ b/src/Graphics/GraphicsPointEllipse.cpp @@ -15,7 +15,8 @@ GraphicsPointEllipse::GraphicsPointEllipse(GraphicsPoint &graphicsPoint, const QRect &rect) : QGraphicsEllipseItem (rect), - m_graphicsPoint (graphicsPoint) + m_graphicsPoint (graphicsPoint), + m_shadow (0) { LOG4CPP_INFO_S ((*mainCat)) << "GraphicsPointEllipse::GraphicsPointEllipse"; } @@ -39,7 +40,7 @@ QVariant GraphicsPointEllipse::itemChange(GraphicsItemChange change, void GraphicsPointEllipse::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { // Highlighted - setOpacity(m_graphicsPoint.highlightOpacity ()); + setOpacityForSubtree (m_graphicsPoint.highlightOpacity()); emit signalPointHoverEnter (data (DATA_KEY_IDENTIFIER).toString ()); @@ -49,16 +50,33 @@ void GraphicsPointEllipse::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void GraphicsPointEllipse::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { // Unhighlighted - setOpacity(MAX_OPACITY); + setOpacityForSubtree (MAX_OPACITY); emit signalPointHoverLeave (data (DATA_KEY_IDENTIFIER).toString ()); QGraphicsEllipseItem::hoverLeaveEvent (event); } +void GraphicsPointEllipse::setOpacityForSubtree (double opacity) +{ + // Set this item + setOpacity (opacity); + + if (m_shadow != 0) { + + // Set the child item. Opacity < MAX_OPACITY is too dark so child is set to totally transparent + m_shadow->setOpacity (opacity < MAX_OPACITY ? 0.0 : opacity); + } +} + void GraphicsPointEllipse::setRadius(int radius) { // Resize assuming symmetry about the origin, and an aspect ratio of 1:1 (so x and y scales are the same) double scale = (2 * radius) / boundingRect().width(); setScale (scale); } + +void GraphicsPointEllipse::setShadow (GraphicsPointEllipse *shadow) +{ + m_shadow = shadow; +} diff --git a/src/Graphics/GraphicsPointEllipse.h b/src/Graphics/GraphicsPointEllipse.h index 21b8babc..0a57812e 100644 --- a/src/Graphics/GraphicsPointEllipse.h +++ b/src/Graphics/GraphicsPointEllipse.h @@ -35,6 +35,9 @@ class GraphicsPointEllipse : public QObject, public QGraphicsEllipseItem /// Update the radius void setRadius(int radius); + /// Bind this graphics item to its shadow + void setShadow (GraphicsPointEllipse *shadow); + signals: /// Signal for geometry window to highlight the current point upon hover enter @@ -46,8 +49,12 @@ class GraphicsPointEllipse : public QObject, public QGraphicsEllipseItem private: GraphicsPointEllipse(); + void setOpacityForSubtree (double opacity); + // Reference to the GraphicsPoint that this class belongs to GraphicsPoint &m_graphicsPoint; + + GraphicsPointEllipse *m_shadow; }; #endif // GRAPHICS_POINT_ELLIPSE_H diff --git a/src/Graphics/GraphicsPointPolygon.cpp b/src/Graphics/GraphicsPointPolygon.cpp index 8a298d83..71f4437f 100644 --- a/src/Graphics/GraphicsPointPolygon.cpp +++ b/src/Graphics/GraphicsPointPolygon.cpp @@ -14,7 +14,8 @@ GraphicsPointPolygon::GraphicsPointPolygon(GraphicsPoint &graphicsPoint, const QPolygonF &polygon) : QGraphicsPolygonItem (polygon), - m_graphicsPoint (graphicsPoint) + m_graphicsPoint (graphicsPoint), + m_shadow (0) { LOG4CPP_INFO_S ((*mainCat)) << "GraphicsPointPolygon::GraphicsPointPolygon"; } @@ -38,7 +39,7 @@ QVariant GraphicsPointPolygon::itemChange(GraphicsItemChange change, void GraphicsPointPolygon::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { // Highlighted - setOpacity(m_graphicsPoint.highlightOpacity ()); + setOpacityForSubtree (m_graphicsPoint.highlightOpacity ()); emit signalPointHoverEnter (data (DATA_KEY_IDENTIFIER).toString ()); @@ -48,16 +49,33 @@ void GraphicsPointPolygon::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void GraphicsPointPolygon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { // Unhighlighted - setOpacity(MAX_OPACITY); + setOpacityForSubtree (MAX_OPACITY); emit signalPointHoverLeave (data (DATA_KEY_IDENTIFIER).toString ()); QGraphicsPolygonItem::hoverLeaveEvent (event); } +void GraphicsPointPolygon::setOpacityForSubtree (double opacity) +{ + // Set this item + setOpacity (opacity); + + if (m_shadow != 0) { + + // Set the child item. Opacity < MAX_OPACITY is too dark so child is set to totally transparent + m_shadow->setOpacity (opacity < MAX_OPACITY ? 0.0 : opacity); + } +} + void GraphicsPointPolygon::setRadius(int radius) { // Resize assuming symmetry about the origin, and an aspect ratio of 1:1 (so x and y scales are the same) double scale = (2 * radius) / boundingRect().width(); setScale (scale); } + +void GraphicsPointPolygon::setShadow (GraphicsPointPolygon *shadow) +{ + m_shadow = shadow; +} diff --git a/src/Graphics/GraphicsPointPolygon.h b/src/Graphics/GraphicsPointPolygon.h index d8f16622..a37869cc 100644 --- a/src/Graphics/GraphicsPointPolygon.h +++ b/src/Graphics/GraphicsPointPolygon.h @@ -35,6 +35,9 @@ class GraphicsPointPolygon : public QObject, public QGraphicsPolygonItem /// Update the radius void setRadius(int radius); + /// Bind this graphics item to its shadow + void setShadow (GraphicsPointPolygon *shadow); + signals: /// Signal for geometry window to highlight the current point upon hover enter @@ -46,8 +49,12 @@ class GraphicsPointPolygon : public QObject, public QGraphicsPolygonItem private: GraphicsPointPolygon(); + void setOpacityForSubtree (double opacity); + // Reference to the GraphicsPoint that this class belongs to GraphicsPoint &m_graphicsPoint; + + GraphicsPointPolygon *m_shadow; }; #endif // GRAPHICS_POINT_POLYGON_H