Skip to content

Commit

Permalink
Shadow points change opacity to show highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
markummitchell-tu committed Jul 19, 2016
1 parent 469eaab commit 45081f6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Graphics/GraphicsPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions src/Graphics/GraphicsPointEllipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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 ());

Expand All @@ -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;
}
7 changes: 7 additions & 0 deletions src/Graphics/GraphicsPointEllipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 21 additions & 3 deletions src/Graphics/GraphicsPointPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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 ());

Expand All @@ -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;
}
7 changes: 7 additions & 0 deletions src/Graphics/GraphicsPointPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 45081f6

Please sign in to comment.